CTextBox: Methods to get and set clientside height.
This commit is contained in:
@@ -166,6 +166,45 @@ namespace VAR.Focus.Web.Controls
|
|||||||
return _allowEmpty || (string.IsNullOrEmpty(_txtContent.Text) == false);
|
return _allowEmpty || (string.IsNullOrEmpty(_txtContent.Text) == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int? GetClientsideHeight()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_hidSize.Value))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
JsonParser jsonParser = new JsonParser();
|
||||||
|
Dictionary<string, object> sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary<string, object>;
|
||||||
|
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<string, object> sizeObj = null;
|
||||||
|
if (string.IsNullOrEmpty(_hidSize.Value) == false)
|
||||||
|
{
|
||||||
|
JsonParser jsonParser = new JsonParser();
|
||||||
|
sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary<string, object>;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sizeObj = new Dictionary<string, object> {
|
||||||
|
{ "height", height },
|
||||||
|
{ "width", null },
|
||||||
|
{ "scrollTop", null },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
JsonWriter jsonWriter = new JsonWriter();
|
||||||
|
_hidSize.Value = jsonWriter.Write(sizeObj);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Public methods
|
#endregion Public methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
var CTextBox_SetText = function (id, text) {
|
var CTextBox_SetText = function (id, text) {
|
||||||
var element = document.getElementById(id);
|
var element = document.getElementById(id);
|
||||||
element.value = text;
|
element.value = text;
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// CTextBox_Multiline_KeyDown
|
// CTextBox_Multiline_KeyDown
|
||||||
//
|
//
|
||||||
var CTextBox_Multiline_KeyDown = function (e) {
|
var CTextBox_Multiline_KeyDown = function (e) {
|
||||||
if (e.keyCode == 9 || e.which == 9) {
|
if (e.keyCode === 9 || e.which === 9) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var s = this.selectionStart;
|
var s = this.selectionStart;
|
||||||
this.value = this.value.substring(0, this.selectionStart) + "\t" + this.value.substring(this.selectionEnd);
|
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 CTextBox_Multiline_SaveSizeData = function (textArea) {
|
||||||
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
|
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
|
||||||
hidSizeData.value = JSON.stringify(textArea.cfg.size);
|
hidSizeData.value = JSON.stringify(textArea.cfg.size);
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// CTextBox_Multiline_RestoreSizeData
|
// CTextBox_Multiline_RestoreSizeData
|
||||||
@@ -34,13 +34,19 @@ var CTextBox_Multiline_RestoreSizeData = function (textArea) {
|
|||||||
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
|
var hidSizeData = document.getElementById(textArea.cfg.hidSize);
|
||||||
|
|
||||||
if (hidSizeData.value !== "") {
|
if (hidSizeData.value !== "") {
|
||||||
textArea.cfg.size = JSON.parse(hidSizeData.value);;
|
textArea.cfg.size = JSON.parse(hidSizeData.value);
|
||||||
textArea.style.width = textArea.cfg.size.width + "px";
|
if (textArea.cfg.size.width !== null) {
|
||||||
textArea.style.height = textArea.cfg.size.height + "px";
|
textArea.style.width = textArea.cfg.size.width + "px";
|
||||||
textArea.scrollTop = textArea.cfg.size.scrollTop;
|
}
|
||||||
|
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
|
// CTextBox_Multiline_MouseUp
|
||||||
@@ -48,20 +54,20 @@ var CTextBox_Multiline_RestoreSizeData = function (textArea) {
|
|||||||
var CTextBox_Multiline_MouseUp = function (e) {
|
var CTextBox_Multiline_MouseUp = function (e) {
|
||||||
var textArea = e.target;
|
var textArea = e.target;
|
||||||
var newSize = { height: textArea.offsetHeight, width: textArea.offsetWidth, scrollTop: textArea.scrollTop };
|
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;
|
textArea.cfg.size = newSize;
|
||||||
CTextBox_Multiline_SaveSizeData(textArea);
|
CTextBox_Multiline_SaveSizeData(textArea);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// CTextBox_Multiline_Scrolled
|
// CTextBox_Multiline_Scrolled
|
||||||
//
|
//
|
||||||
var CTextBox_Multiline_Scrolled = function (e) {
|
var CTextBox_Multiline_Scrolled = function (e) {
|
||||||
var textArea = e.target;
|
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_SaveSizeData(textArea);
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// CTextBox_Multiline_Init
|
// CTextBox_Multiline_Init
|
||||||
@@ -76,4 +82,4 @@ var CTextBox_Multiline_Init = function (cfg) {
|
|||||||
textArea.onmouseup = CTextBox_Multiline_MouseUp;
|
textArea.onmouseup = CTextBox_Multiline_MouseUp;
|
||||||
textArea.onscroll = CTextBox_Multiline_Scrolled;
|
textArea.onscroll = CTextBox_Multiline_Scrolled;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user