nscomponentsreact
Version:
React Wrapper Components for NSComponents
923 lines (871 loc) • 29.1 kB
JavaScript
var nsModuleExport = function(root,name,prototype)
{
if(typeof exports === 'object' && typeof module === 'object')
{
module.exports[name] = prototype;
}
else if (typeof define === "function" && define.amd)
{
define(name,[], function () {return prototype;});
}
else if(typeof exports === 'object')
{
exports[name] = prototype;
}
else
{
root[name] = prototype;
}
};var nsIsWeb = function(root)
{
if(typeof exports === 'object' && typeof module === 'object')
{
return false;
}
else if (typeof define === "function" && define.amd)
{
return false;
}
else if(typeof exports === 'object')
{
return false;
}
else
{
return true;
}
};if(!nsIsWeb())
{
var nsutilRef = require('./nsUtil.min.js');
var NSUtil = nsutilRef.NSUtil;
var nscontainerbaseRef = require('./nsContainerBase.min.js');
var nsExtendPrototype = nscontainerbaseRef.nsExtendPrototype;
var NSContainerBase = nscontainerbaseRef.NSContainerBase;
var svgRef = require('./nsSVG.min.js');
var NSSvg = svgRef.NSSvg;
var NSSvgShapes = svgRef.NSSvgShapes;
var plugginsRef = require('./nsPluggins.min.js');
var nsTextEditor = plugginsRef.nsTextEditor;
var nsTextAreaEditor = plugginsRef.nsTextAreaEditor;
var NSCellSelection = plugginsRef.NSCellSelection;
var NSTableCellNavigator = plugginsRef.NSTableCellNavigator;
var dateutilRef = require('./nsDateUtil.min.js');
var NSDateUtil = dateutilRef.NSDateUtil;
}
"use strict";
var NSNumericTextBox = (function()
{
function NSNumericTextBox(setting)
{
this.util = new NSUtil();
this.__setting = setting;
this.__config = null;
this.__id = null;
this.__parentNode = null;
this.__spanContainer = null;
this.__spanTextBoxParent = null;
this.__currentValue = null;
this.__interval = null;
this.__hasClickedSpin = false;
this.__typing = false;
this.__observer = null;
this.__initialize();
};
NSNumericTextBox.prototype.setValue = function(value,fireEvent)
{
fireEvent = this.util.isUndefined(fireEvent) ? true : Boolean.parse(fireEvent);
if(this.util.isUndefinedOrNull(value))
{
var textBox = this.__config.input;
textBox.value = null;
this.__oldValue = this.__currentValue;
this.__currentValue = null;
}
else
{
this.__updateValue(value,false,fireEvent);
this.__setFormattedValue();
}
};
NSNumericTextBox.prototype.getValue = function()
{
return (this.__currentValue || 0);
};
NSNumericTextBox.prototype.getFormattedValue = function()
{
return this.__config.input.value;
};
NSNumericTextBox.prototype.setTheme = function(theme)
{
if(theme)
{
this.util.removeStyleClass(this.__spanContainer, "nsNumericTextBoxContainer" + this.__config.theme);
this.__config.theme = theme;
this.util.addStyleClass(this.__spanContainer, "nsNumericTextBoxContainer" + this.__config.theme);
}
};
NSNumericTextBox.prototype.setDisabled = function(isDisabled)
{
var textBox = this.__config.input;
textBox.disabled = isDisabled;
};
NSNumericTextBox.prototype.setReadonly = function(isReadonly)
{
var textBox = this.__config.input;
textBox.readOnly = isReadonly;
};
NSNumericTextBox.prototype.remove = function()
{
if(this.__spanContainer && this.__spanContainer.parentNode == this.__parentNode)
{
this.__spanTextBoxParent.removeChild(this.__config.input);
this.__parentNode.insertBefore(this.__config.input,this.__spanContainer);
this.__parentNode.removeChild(this.__spanContainer);
}
this.__removeTextBoxEvents();
this.util.removeStyleClass(this.__config.input,"nsNumericTextBox");
if(this.__observer)
{
this.__observer.disconnect();
this.__observer = null;
}
};
NSNumericTextBox.prototype.__initialize = function()
{
if(this.__setting)
{
this.__objType = {"num":{symbol:"",format:"%v"},
"per":{symbol:"%",format:"%v%s"},
"usd":{symbol:"$",format:"%s%v"},
"pound":{symbol:"£",format:"%s%v"},
"euro":{symbol:"\u20AC",format:"%v%s"},//https://www.fileformat.info/info/unicode/char/20ac/index.htm
"yen":{symbol:"\u00A5",format:"%s%v"}//https://www.fileformat.info/info/unicode/char/a5/index.htm
};
this.__config = {
input: this.__setting["input"],
type: this.__setting["type"] || "num",
enableDecimals: this.util.isUndefinedOrNull(this.__setting["enableDecimals"]) ? true : Boolean.parse(this.__setting["enableDecimals"]),
decimals: this.__setting["decimals"] || 2,
grouping: this.__setting["grouping"] || 3,
min: this.__setting["min"],
max: this.__setting["max"],
value: this.__setting["value"],
enableThousand: this.util.isUndefinedOrNull(this.__setting["enableThousand"]) ? true : Boolean.parse(this.__setting["enableThousand"]),
decimalSeparator: this.__setting["decimalSeparator"] || ".",
thousandSeparator: this.__setting["thousandSeparator"] || ",",
enableHover: this.util.isUndefinedOrNull(this.__setting["enableHover"]) ? true : Boolean.parse(this.__setting["enableHover"]),
theme: this.__setting["theme"] || "White",
customClass: this.__setting["customClass"] || {},
enableSpinner: this.util.isUndefinedOrNull(this.__setting["enableSpinner"]) ? true : Boolean.parse(this.__setting["enableSpinner"]),
incrementerProp: this.__setting["incrementerProp"] || {label:"Increase Value",iconHtml:""},
decrementerProp: this.__setting["decrementerProp"] || {label:"Decrease Value",iconHtml:""},
step: this.__setting["step"] || 1,
format: this.__setting["format"],
enableRangeRoundOf: this.util.isUndefinedOrNull(this.__setting["enableRangeRoundOf"]) ? true : Boolean.parse(this.__setting["enableRangeRoundOf"]),
customFormatSpecifier: this.__setting["customFormatSpecifier"] || "#",
};
if(!this.__config.input)
{
this.util.throwNSError("NSNumericTextBox","Input property is not valid");
}
if(!this.__config.enableThousand)
{
this.__config.thousandSeparator = "";
}
if(!this.__config.enableDecimals)
{
this.__config.decimals = 0;
}
this.__createElement();
var value = this.__config.value;
if(!this.util.isUndefinedOrNull(value))
{
this.setValue(value);
}
if(this.__config.type == "custom" && this.util.isUndefinedOrNull(this.__setting["enableRangeRoundOf"]))
{
this.__config.enableRangeRoundOf = false;
}
this.setTheme(this.__config.theme);
this.__setDisabledOrReadonly();
}
};
NSNumericTextBox.prototype.__createElement = function()
{
this.__parentNode = this.__config.input.parentNode;
var id = this.__getID();
this.__spanContainer = this.util.createElement("span", id + "Container", "nsNumericTextBoxContainer");
this.__applyCustomClass(this.__spanContainer,"outerContainer");
this.__spanTextBoxParent = this.util.createElement("span", id + "Parent", "nsNumericTextBoxParent");
this.__applyCustomClass(this.__spanTextBoxParent,"textBoxContainer");
this.__spanContainer.appendChild(this.__spanTextBoxParent);
this.__parentNode.insertBefore(this.__spanContainer,this.__config.input);
this.__spanTextBoxParent.appendChild(this.__config.input);
this.util.addStyleClass(this.__config.input,"nsNumericTextBox");
if(this.__config.enableHover)
{
this.util.addEvent(this.__spanTextBoxParent,"mouseenter",this.__textBoxParentEventHandler.bind(this,true));
this.util.addEvent(this.__spanTextBoxParent,"mouseleave",this.__textBoxParentEventHandler.bind(this,false));
}
this.__addTextBoxEvents();
if(this.__config.enableSpinner)
{
this.util.addStyleClass(this.__spanTextBoxParent,"nsNumericTextBoxParentWithSpinner");
this.__createSpinner(id);
}
};
NSNumericTextBox.prototype.__createSpinner = function(id)
{
var incrementerProp = this.__config.incrementerProp;
var decrementerProp = this.__config.decrementerProp;
this.__spanSpinnerContainer = this.util.createElement("span", id + "SpinnerContainer", "nsNumericTextBoxSpinnerContainer");
this.__applyCustomClass(this.__spanSpinnerContainer,"spinContainer");
var item = this.__createSpecificSpinner("Inc",incrementerProp.label,"spinIncrement");
this.__spanIncSpinContainer = item.parent;
this.__spanIncSpin = item.child;
item = this.__createSpecificSpinner("Dec",decrementerProp.label,"spinDecrement");
this.__spanDecSpinContainer = item.parent;
this.__spanDecSpin = item.child;
this.__spanTextBoxParent.appendChild(this.__spanSpinnerContainer);
this.util.addEvent(this.__spanSpinnerContainer,"mouseleave",this.__spinnerContainerMouseOutHandler.bind(this));
};
NSNumericTextBox.prototype.__createSpecificSpinner = function(func,title,customClass)
{
var spanParent = this.util.createElement("span", null,"nsNumericTextBoxSpinContainer " + "nsNumericTextBox" + func + "SpinnerContainer");
spanParent.setAttribute("unselectable","on");
spanParent.setAttribute("title",title);
spanParent.setAttribute("aria-label",title);
var spanSpin = this.util.createElement("span", null,"nsNumericTextBoxSpinner " + "nsNumericTextBox" + func + "Spinner");
spanSpin.setAttribute("unselectable","on");
this.__applyCustomClass(spanSpin,customClass);
spanParent.appendChild(spanSpin);
this.__spanSpinnerContainer.appendChild(spanParent);
var mouseDownHandler = this.__spinnerMouseDownHandler.bind(this,spanParent,spanSpin,func);
var mouseOutHandler = this.__spinnerMouseOutHandler.bind(this,spanParent,spanSpin,func);
this.util.addEvent(spanParent,"mousedown",mouseDownHandler);
this.util.addEvent(spanParent,"mouseup",mouseOutHandler);
this.util.addEvent(spanParent,"mouseleave",mouseOutHandler);
return {parent: spanParent,child:spanSpin};
};
NSNumericTextBox.prototype.__spinnerMouseDownHandler = function(spinParent,spin,func,event)
{
if(event)
{
event = this.util.getEvent(event);
event.preventDefault();
}
this.__hasClickedSpin = true;
this.__spinHandler(func);
clearTimeout(this.__interval);
this.util.addStyleClass(spinParent,"nsNumericTextBoxSpinnerSelected");
var self = this;
this.__interval = setTimeout(function(){self.__spinnerMouseDownHandler.call(self,spinParent,spin,func,event);}, 200);
};
NSNumericTextBox.prototype.__spinnerMouseOutHandler = function(spinParent,spin,func,event)
{
clearTimeout(this.__interval);
this.__interval = null;
this.util.removeStyleClass(spinParent,"nsNumericTextBoxSpinnerSelected");
if(event)
{
event = this.util.getEvent(event);
event.preventDefault();
}
};
NSNumericTextBox.prototype.__spinnerContainerMouseOutHandler = function(event)
{
this.__hasClickedSpin = false;
var textBox = this.__config.input;
textBox.blur();
this.__blurHandler(null);
};
NSNumericTextBox.prototype.__spinHandler = function(func)
{
if(this.__config.enableSpinner && !this.__isDisabled())
{
var step = Number(this.__config.step);
step = isNaN(step) ? 1 : step;
step = (func == "Inc") ? step : (-1 * step);
this.__spin(step);
}
};
NSNumericTextBox.prototype.__textBoxParentEventHandler = function(isMouseOver,event)
{
isMouseOver ? this.util.addStyleClass(this.__spanTextBoxParent,"nsNumericTextBoxParentHover") : this.util.removeStyleClass(this.__spanTextBoxParent,"nsNumericTextBoxParentHover");
};
NSNumericTextBox.prototype.__keyDownHandler = function(event)
{
event = this.util.getEvent(event);
var inputCode = (event.which) ? event.which : event.keyCode;
var keyCode = this.util.KEYCODE;
switch(inputCode)
{
case keyCode.UP:
this.__spinHandler("Inc");
break;
case keyCode.DOWN:
this.__spinHandler("Dec");
break;
case keyCode.DELETE:
case keyCode.BACKSPACE:
var self = this;
setTimeout(function(){self.__updateValue.call(self,self.__config.input.value,false,true);},500);
break;
case keyCode.ENTER:
this.__updateValue(this.__config.input.value,false,true);
break;
default:
if(inputCode != keyCode.TAB)
{
this.__typing = true;
}
}
};
NSNumericTextBox.prototype.__keyPressHandler = function(event)
{
event = this.util.getEvent(event);
var inputCode = (event.which) ? event.which : event.keyCode;
if (inputCode === 0 || event.metaKey || event.ctrlKey || event.keyCode === 8 || event.keyCode === 13)
{
return;
}
var character = String.fromCharCode(inputCode);
this.__updateValue(character,true,false);
event.preventDefault();
};
NSNumericTextBox.prototype.__focusHandler = function(event)
{
var textBox = this.__config.input;
textBox.value = this.__currentValue;
};
NSNumericTextBox.prototype.__blurHandler = function(event)
{
var value = this.__config.input.value;
if(!(value == "" && this.util.isUndefinedOrNull(this.__currentValue)))
{
this.__setFormattedValue(value);
if(this.__oldValue != this.__currentValue)
{
var item = {oldValue:this.__oldValue,newValue:this.__currentValue};
this.__dispatchEvent(NSNumericTextBox.VALUE_CHANGED,item,item);
this.__oldValue = this.__currentValue;
}
}
};
NSNumericTextBox.prototype.__pasteHandler = function(event)
{
event = this.util.getEvent(event);
var content = "";
if(event.clipboardData)
{
content = event.clipboardData.getData('text/plain');
}
else if(window.clipboardData)
{
content = window.clipboardData.getData('Text');
}
//console.log("Pasted Data :: " + content);
this.__updateValue(content,true,true);
event.stopPropagation();
event.preventDefault();
};
NSNumericTextBox.prototype.__updateValue = function(newContent,isAdd,fireEvent)
{
var textBox = this.__config.input;
var regex = this.__getNumericRegex();
var selection = this.util.caretPosition(textBox);
var selectionStart = selection.start;
var selectionEnd = selection.end;
var value = newContent;
var presentValue = textBox.value;
if(isAdd)
{
value = presentValue.substring(0, selectionStart) + newContent + presentValue.substring(selectionEnd);
}
var isValid = regex.test(value);
if(isValid)
{
value = this.__getRangeValue(value,this.__currentValue);
this.__oldValue = this.__currentValue;
this.__currentValue = value;
textBox.value = value;
if(isAdd)
{
var caretPos = selectionStart + newContent.length;
this.util.caretPosition(textBox,caretPos);
}
if(fireEvent)
{
if(this.__oldValue != value)
{
if(!this.__typing)
{
this.util.triggerEvent(textBox,"change");
}
var item = {oldValue:this.__oldValue,newValue:value};
this.__dispatchEvent(NSNumericTextBox.VALUE_CHANGED,item,item);
this.__oldValue = value;
}
}
}
else
{
console.debug("Invalid Value");
}
this.__typing = false;
return isValid;
};
NSNumericTextBox.prototype.__spin = function(steps)
{
var textBox = this.__config.input;
if(this.__getActiveElement() != textBox)
{
this.__textBoxParentEventHandler(true,null);
this.__focusHandler();
textBox.focus();
}
var currentValue = Number(this.__currentValue);
var presentValue = currentValue;
var decimals = Math.abs(this.__config.decimals);
var newValue = (currentValue + steps).toFixed(decimals);
this.__updateValue(newValue,false,true);
newValue = currentValue;
if(presentValue !== newValue)
{
var item = {oldValue:presentValue,newValue:newValue};
this.__dispatchEvent(NSNumericTextBox.SPIN,item,item);
}
};
NSNumericTextBox.prototype.__addTextBoxEvents = function()
{
var textBox = this.__config.input;
if(!this.__keyDownRef)
{
this.__keyDownRef = this.__keyDownHandler.bind(this);
this.util.addEvent(textBox,"keydown",this.__keyDownRef);
}
if(!this.__keyPressRef)
{
this.__keyPressRef = this.__keyPressHandler.bind(this);
this.util.addEvent(textBox,"keypress",this.__keyPressRef);
}
if(!this.__focusRef)
{
this.__focusRef = this.__focusHandler.bind(this);
this.util.addEvent(textBox,"focus",this.__focusRef);
}
if(!this.__blurRef)
{
this.__blurRef = this.__blurHandler.bind(this);
this.util.addEvent(textBox,"blur",this.__blurRef);
}
if(!this.__pasteRef)
{
this.__pasteRef = this.__pasteHandler.bind(this);
this.util.addEvent(textBox,"paste",this.__pasteRef);
}
};
NSNumericTextBox.prototype.__removeTextBoxEvents = function()
{
var textBox = this.__config.input;
if(this.__keyDownRef)
{
this.util.removeEvent(textBox,"keydown",this.__keyDownRef);
this.__keyDownRef = null;
}
if(this.__keyPressRef)
{
this.util.removeEvent(textBox,"keypress",this.__keyPressRef);
this.__keyPressRef = null;
}
if(this.__focusRef)
{
this.util.removeEvent(textBox,"focus",this.__focusRef);
this.__focusRef = null;
}
if(this.__blurRef)
{
this.util.removeEvent(textBox,"blur",this.__blurRef);
this.__blurRef = null;
}
if(this.__pasteRef)
{
this.util.addEvent(textBox,"paste",this.__pasteRef);
this.__pasteRef = null;
}
};
NSNumericTextBox.prototype.__getNumericRegex = function()
{
var decimals = Math.abs(this.__config.decimals);
var decimalSeparator = this.__config.decimalSeparator;
var decimalRegex = '*';
if (decimalSeparator === ".")
{
decimalSeparator = '\\' + decimalSeparator;
}
if(decimals == 0)
{
return new RegExp("^(-)?(\\d*)$");
}
decimalRegex = '{0,' + decimals + '}';
//return new RegExp("^[0-9]+([" + decimalSeparator + "][0-9]{1," + decimals + "})?$");
return new RegExp('^(-)?(((\\d+(' + decimalSeparator + '\\d' + decimalRegex + ')?)|(' + decimalSeparator + '\\d' + decimalRegex + ')))?$');
};
NSNumericTextBox.prototype.__setFormattedValue = function(value)
{
value = this.util.isUndefinedOrNull(value) ? this.__currentValue : value;
var textBox = this.__config.input;
if(this.util.isUndefinedOrNull(value) || value == "")
{
value = "";
}
else
{
value = this.__getFormattedValue(value);
}
textBox.value = value;
};
NSNumericTextBox.prototype.__getFormattedValue = function(value)
{
var type = this.__config.type;
var retValue = "";
value = this.__getUnFormattedNumber(value);
if(type == "custom")
{
var format = this.__config.format;
if(format)
{
retValue = this.__getCustomFormattedNumber(value.toString(),format);
}
else
{
this.util.throwNSError("NSNumericTextBox","Format is not valid");
}
}
else
{
var formattedValue = this.__getFormattedNumber(value);
var objType = this.__objType[type];
var format = this.__checkFormat(objType.format);
retValue = format.replace('%s', this.__getRenderedChar(objType.symbol)).replace('%v',formattedValue);
}
return retValue;
};
NSNumericTextBox.prototype.__getCustomFormattedNumber = function(value,format)
{
var retValue = format;
var specifier = this.__config.customFormatSpecifier;
for(var count = 0,index = 0;count <= format.length;count++)
{
var cha = format.charAt(count);
if(value.length > index)
{
if(cha == specifier)
{
retValue = this.__replaceCharAt(retValue,count,value[index]);
index++;
}
}
else
{
break;
}
}
retValue = retValue.split(specifier).join("");
var lastIndex = format.lastIndexOf(specifier);
var lastStr = format.substring(lastIndex + 1,format.length);
var index = retValue.length - 1;
while(!this.__isNumeric(retValue.charAt(index)) && index > -1)
{
retValue = retValue.substring(0,index);
index--;
}
return (retValue + lastStr);
};
NSNumericTextBox.prototype.__getFormattedNumber = function(value)
{
var retValue = value;
try
{
var decimals = Math.abs(this.__config.decimals);
var decimalSeparator = this.__config.decimalSeparator;
if(value.toString().indexOf("e") > -1)
{
retValue = this.__round(+value,decimals);
retValue = retValue.replace(".",decimalSeparator);
}
else
{
var thousandSeparator = this.__config.thousandSeparator;
var grouping = Math.abs(this.__config.grouping);
var negativeSign = "";
if(value < 0)
{
negativeSign = "-";
value = (-1 * value);
}
var wholePart = parseInt(value = Math.abs(Number(value) || 0).toFixed(decimals)).toString();
var groupingMod = (wholePart.length > grouping) ? wholePart.length % grouping : 0;
var regex = new RegExp("(\\d{" + grouping + "})(?=\\d)","g");
var firstWholePart = (groupingMod ? wholePart.substr(0, groupingMod) + thousandSeparator : '');
var restWholePart = wholePart.substr(groupingMod).replace(regex, "$1" + thousandSeparator);
var decimalPart = "";
if (decimals > 0)
{
decimalPart = decimalSeparator + Math.abs(value - wholePart).toFixed(decimals).slice(2);
}
retValue = negativeSign + firstWholePart + restWholePart + decimalPart;
}
}
catch(error)
{
}
return retValue;
};
NSNumericTextBox.prototype.__getUnFormattedNumber = function(value)
{
if(typeof value === "number")
{
return value;
}
var decimalSeparator = this.__config.decimalSeparator;
var regex = new RegExp("[^0-9-" + decimalSeparator + "]", ["g"]);
var retValue = parseFloat(
("" + value)
.replace(/\((?=\d+)(.*)\)/, "-$1") // replace bracketed values with negatives
.replace(regex, '') // strip out any cruft
.replace(decimalSeparator, '.') // make sure decimal point is standard
);
return !isNaN(retValue) ? retValue : 0;
};
NSNumericTextBox.prototype.__checkFormat = function(format)
{
var retItem = {};
if(typeof format === "function" )
{
format = format();
}
if(this.util.isString(format) && format.match("%v"))
{
retItem = format;
}
else if(!format || !format.match("%v"))
{
this.util.throwNSError("NSNumericTextBox","Format is not valid");
}
return retItem;
};
NSNumericTextBox.prototype.__getRangeValue = function(value,presentValue)
{
var decimalSeparator = this.__config.decimalSeparator;
value = value.toString();
if(value.indexOf(decimalSeparator) == value.length - 1)
{
return value;
}
var decimalPart = "";
if(value.indexOf(decimalSeparator) > -1 && Number(value).toString().indexOf(decimalSeparator) == -1)
{
decimalPart = decimalSeparator + value.split(decimalSeparator)[1];
}
value = Number(value);
this.__validateMinMax();
var min = this.__config.min;
var max = this.__config.max;
var retValue = null;
if(this.__config.enableRangeRoundOf)
{
retValue = value > max ? max : value < min ? min : (value + decimalPart);
}
else
{
retValue = value > max ? presentValue : value < min ? presentValue : (value + decimalPart);
}
return retValue;
};
NSNumericTextBox.prototype.__validateMinMax = function()
{
var min = this.__config.min;
var max = this.__config.max;
var type = this.__config.type;
if(!this.util.isNumber(min) || isNaN(min))
{
min = -Number.MAX_VALUE;
}
if(!this.util.isNumber(max) || isNaN(max))
{
max = Number.MAX_VALUE;
}
if(type == "custom")
{
var format = this.__config.format;
if(format)
{
var maxValue = "";
var specifier = this.__config.customFormatSpecifier;
var length = (format.match(new RegExp(specifier,"g")||[])).length;
for(var count = 0;count < length;count++)
{
maxValue = maxValue + "9";
}
maxValue = Number(maxValue);
console.log(maxValue);
if(max > maxValue)
{
max = maxValue;
}
if(min < 0)
{
min = 0;
}
}
}
min = (min > max) ? max : min;
this.__config.min = min;
this.__config.max = max;
};
NSNumericTextBox.prototype.__applyCustomClass = function(element,type)
{
if(this.__config.customClass && element && type)
{
var itemProperty = {"outerContainer":{property:"outerContainer",defaultValue:null},
"textBoxContainer":{property:"textBoxContainer",defaultValue:null},
"spinContainer":{property:"spinContainer",defaultValue:null},
"spinIncrement":{property:"spinIncrement",defaultValue:null},
"spinDecrement":{property:"spinDecrement",defaultValue:null},
};
if(itemProperty[type])
{
if(this.__config.customClass[itemProperty[type]["property"]])
{
this.util.addStyleClass(element,this.__config.customClass[itemProperty[type]["property"]]);
}
else if(itemProperty[type]["defaultValue"])
{
this.util.addStyleClass(element,itemProperty[type]["defaultValue"]);
}
}
}
};
NSNumericTextBox.prototype.__getRenderedChar = function(str)
{
/*var div = document.createElement("div");
div.innerHTML = str;
return div.innerHTML;*/
return str;
};
NSNumericTextBox.prototype.__round = function(value,precision,negative)
{
precision = precision || 0;
value = value.toString().split("e");
value = Math.round(+(value[0] + "e" + (value[1] ? +value[1] + precision : precision)));
if (negative)
{
value = -value;
}
value = value.toString().split("e");
value = +(value[0] + "e" + (value[1] ? +value[1] - precision : -precision));
return value.toFixed(Math.min(precision, 20));
};
NSNumericTextBox.prototype.__replaceCharAt = function(str,index,replace)
{
return str.substring(0,index) + replace + str.substring(index + 1);
};
NSNumericTextBox.prototype.__isNumeric = function(str)
{
return /^\d+$/.test(str);
};
NSNumericTextBox.prototype.__dispatchEvent = function(eventType,data,param,bubbles,cancelable)
{
/*if(this.__eventDispatcher)
{
this.__eventDispatcher(eventType,data,param,bubbles,cancelable);
}
else
{*/
this.util.dispatchEvent(this.__config.input,eventType,data,param,bubbles,cancelable);
//}
};
NSNumericTextBox.prototype.__getActiveElement = function()
{
try
{
return document.activeElement;
}
catch (error)
{
return document.documentElement.activeElement;
}
};
NSNumericTextBox.prototype.__setDisabledOrReadonly = function()
{
var textBox = this.__config.input;
var disabled = this.__isDisabled();
if(disabled)
{
this.util.addStyleClass(this.__spanContainer,"nsNumericTextBoxContainerDisabled");
}
else
{
this.util.removeStyleClass(this.__spanContainer,"nsNumericTextBoxContainerDisabled");
}
if(!this.__observer)
{
var self = this;
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
this.__observer = new MutationObserver(function(mutations)
{
mutations.forEach(function(mutation)
{
if(mutation.type == "attributes")
{
var attributeName = mutation.attributeName;
if(attributeName.toLowerCase() == "disabled" || attributeName.toLowerCase() == "readonly")
{
self.__setDisabledOrReadonly();
}
}
});
});
var config = {attributes: true,childList:false,characterData: false};
this.__observer.observe(textBox,config);
}
};
NSNumericTextBox.prototype.__isDisabled = function()
{
var textBox = this.__config.input;
if(textBox.disabled || textBox.readOnly)
{
return true;
}
var fieldSet = this.util.findParent(textBox,"fieldset");
if(fieldSet && fieldSet.disabled)
{
return true;
}
return false;
};
NSNumericTextBox.prototype.__getID = function()
{
if(!this.__id)
{
if(this.__config.input.hasAttribute("id"))
{
this.__id = this.__config.input.getAttribute("id");
}
else if(this.__config.input.hasAttribute("name"))
{
this.__id = this.__config.input.getAttribute("name");
}
else
{
this.__id = "comp" + this.util.getUniqueId();
}
}
return this.__id;
};
NSNumericTextBox.SPIN = "spin";
NSNumericTextBox.VALUE_CHANGED = "valueChanged";
return NSNumericTextBox;
})();
nsModuleExport(this,"NSNumericTextBox",NSNumericTextBox);