diff --git a/VAR.Focus.Web/Controls/CTextBox.cs b/VAR.Focus.Web/Controls/CTextBox.cs index ddce0d4..8f27e7d 100644 --- a/VAR.Focus.Web/Controls/CTextBox.cs +++ b/VAR.Focus.Web/Controls/CTextBox.cs @@ -166,6 +166,45 @@ namespace VAR.Focus.Web.Controls return _allowEmpty || (string.IsNullOrEmpty(_txtContent.Text) == false); } + public int? GetClientsideHeight() + { + if (string.IsNullOrEmpty(_hidSize.Value)) + { + return null; + } + JsonParser jsonParser = new JsonParser(); + Dictionary sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary; + if (sizeObj == null) { return null; } + + if (sizeObj.ContainsKey("height") == false) { return null; } + return (int)sizeObj["height"]; + } + + public void SetClientsideHeight(int? height) + { + if(height == null) + { + _hidSize.Value = string.Empty; + return; + } + Dictionary sizeObj = null; + if (string.IsNullOrEmpty(_hidSize.Value) == false) + { + JsonParser jsonParser = new JsonParser(); + sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary; + } + else + { + sizeObj = new Dictionary { + { "height", height }, + { "width", null }, + { "scrollTop", null }, + }; + } + JsonWriter jsonWriter = new JsonWriter(); + _hidSize.Value = jsonWriter.Write(sizeObj); + } + #endregion Public methods } } \ No newline at end of file diff --git a/VAR.Focus.Web/Scripts/03. Controls.js b/VAR.Focus.Web/Scripts/03. Controls.js index db3c0a5..4c0ec17 100644 --- a/VAR.Focus.Web/Scripts/03. Controls.js +++ b/VAR.Focus.Web/Scripts/03. Controls.js @@ -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; } -} +};