CTextBox: Methods to get and set clientside height.

This commit is contained in:
2018-03-18 10:23:20 +01:00
parent af0345ebff
commit 4cf0c70150
2 changed files with 59 additions and 14 deletions

View File

@@ -5,13 +5,13 @@
var CTextBox_SetText = function (id, text) {
var element = document.getElementById(id);
element.value = text;
}
};
////////////////////////
// CTextBox_Multiline_KeyDown
//
var CTextBox_Multiline_KeyDown = function (e) {
if (e.keyCode == 9 || e.which == 9) {
if (e.keyCode === 9 || e.which === 9) {
e.preventDefault();
var s = this.selectionStart;
this.value = this.value.substring(0, this.selectionStart) + "\t" + this.value.substring(this.selectionEnd);
@@ -25,7 +25,7 @@ var CTextBox_Multiline_KeyDown = function (e) {
var CTextBox_Multiline_SaveSizeData = function (textArea) {
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
hidSizeData.value = JSON.stringify(textArea.cfg.size);
}
};
////////////////////////
// CTextBox_Multiline_RestoreSizeData
@@ -34,13 +34,19 @@ var CTextBox_Multiline_RestoreSizeData = function (textArea) {
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
if (hidSizeData.value !== "") {
textArea.cfg.size = JSON.parse(hidSizeData.value);;
textArea.style.width = textArea.cfg.size.width + "px";
textArea.style.height = textArea.cfg.size.height + "px";
textArea.scrollTop = textArea.cfg.size.scrollTop;
textArea.cfg.size = JSON.parse(hidSizeData.value);
if (textArea.cfg.size.width !== null) {
textArea.style.width = textArea.cfg.size.width + "px";
}
if (textArea.cfg.size.height !== null) {
textArea.style.height = textArea.cfg.size.height + "px";
}
if (textArea.cfg.size.scrollTop !== null) {
textArea.scrollTop = textArea.cfg.size.scrollTop;
}
}
textArea.cfg.size = { height: textArea.offsetHeight, scrollTop: textArea.scrollTop };
}
textArea.cfg.size = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
};
////////////////////////
// CTextBox_Multiline_MouseUp
@@ -48,20 +54,20 @@ var CTextBox_Multiline_RestoreSizeData = function (textArea) {
var CTextBox_Multiline_MouseUp = function (e) {
var textArea = e.target;
var newSize = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
if (textArea.cfg.size.height != newSize.height) {
if (textArea.cfg.size.height !== newSize.height) {
textArea.cfg.size = newSize;
CTextBox_Multiline_SaveSizeData(textArea);
}
}
};
////////////////////////
// CTextBox_Multiline_Scrolled
//
var CTextBox_Multiline_Scrolled = function (e) {
var textArea = e.target;
textArea.cfg.size = { height: textArea.offsetHeight, scrollTop: textArea.scrollTop };
textArea.cfg.size = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
CTextBox_Multiline_SaveSizeData(textArea);
}
};
////////////////////////
// CTextBox_Multiline_Init
@@ -76,4 +82,4 @@ var CTextBox_Multiline_Init = function (cfg) {
textArea.onmouseup = CTextBox_Multiline_MouseUp;
textArea.onscroll = CTextBox_Multiline_Scrolled;
}
}
};