(function ($) { $.jqx.jqxWidget("jqxNumberInput", "", {}); $.extend($.jqx._jqxNumberInput.prototype, { defineInstance: function () { var settings = { // Type: Number // Default: 0 // Gets or sets the input's value. value: null, // Type: Number // Default: 0 // Gets or sets the input's number. decimal: 0, // Type: Number // Default= 0 // Gets or sets the input's minimum value. min: -99999999, // Type: Number // Default: 0 // Gets or sets the input's maximum value. max: 99999999, //Type: Number. //Default: 0. //Sets width of the input in pixels. Only positive values have effect. width: 200, //Type: String, //Default: Invalid value. validationMessage: "Invalid value", //Type: Number. //Default: 0. //Sets height of the input in pixels. height: 25, // Sets the alignment. textAlign: "right", // Type: Bool // Default: false // Sets the readOnly state of the input. readOnly: false, // Type: Char // Default: "_" // Sets the prompt char displayed when an editable char is empty. // Possible Values: "_", "?", "#". promptChar: "_", // Type: Number // Default: 2 // Indicates the number of decimal places to use in numeric values. decimalDigits: 2, // Type= Char // Default: '.' // Gets or sets the char to use as the decimal separator in numeric values. decimalSeparator: ".", // Type= Char // Default: "," // Gets or sets the string that separates groups of digits to the left of the // decimal in numeric values. groupSeparator: ",", // Type: Number // Default: '3' // Gets or sets the number of digits in each group to the left of the decimal in numeric values. groupSize: 3, // Type: String // Default: empty // Gets or sets the string to use as currency or percentage symbol. symbol: '', // Type: Bool // Default: "left" // Gets or sets the position of the symbol in the input. symbolPosition: "left", // Type: Number // Default: 8 // Gets or sets the digits in the input digits: 8, // Type: Bool // Default: false // Gets or sets whether the decimal is negative. negative: false, // Type: Bool // Default: false // Gets or sets the string to use as negative symbol. negativeSymbol: '-', // Type: Bool // Default: false // Gets or sets whether the widget is disabled. disabled: false, // Type: String // Default: advanced // Gets or sets the input mode. When the mode is simple, the text is formatted after editing. When the mode is advanced, the text is formatted while the user is in edit mode. // Available values: [simple, advanced] inputMode: 'advanced', // Type: Boolean // Default: false // shows the spin buttons. spinButtons: false, // Type: Number // Default: 18 // Sets the spin buttons width spinButtonsWidth: 18, // Type: Number // Default: 1 // sets the spin button step. spinButtonsStep: 1, // validates the value to be in the min-max range when the user leaves the input. autoValidate: true, // none, advanced or simple spinMode: 'advanced', enableMouseWheel: true, touchMode: "auto", allowNull: true, placeHolder: "", changeType: null, template: "", rtl: false, // NumberInput events. events: [ 'valueChanged', 'textchanged', 'mousedown', 'mouseup', 'keydown', 'keyup', 'keypress', 'change' ], aria: { "aria-valuenow": { name: "decimal", type: "number" }, "aria-valuemin": { name: "min", type: "number" }, "aria-valuemax": { name: "max", type: "number" }, "aria-disabled": { name: "disabled", type: "boolean" } }, invalidArgumentExceptions: [ 'invalid argument exception' ] }; if (this === $.jqx._jqxNumberInput.prototype) { return settings; } $.extend(true, this, settings); return settings; }, // creates the number input's instance. createInstance: function (args) { var _val = this.host.attr('value'); if (_val != undefined) { this.decimal = _val; } if (this.value != null) this.decimal = this.value; var that = this; that._createFromInput("jqxNumberInput"); this.render(); }, _createFromInput: function (name) { var that = this; if (that.element.nodeName.toLowerCase() == "input") { that.field = that.element; if (that.field.className) { that._className = that.field.className; } var properties = { 'title': that.field.title }; if (that.field.value) { that.decimal = parseFloat(that.field.value); } if (that.field.getAttribute('min')) { var min = (that.field.getAttribute('min')); that.min = parseFloat(min); } if (that.field.getAttribute('step')) { var step = (that.field.getAttribute('step')); that.spinButtonsStep = parseFloat(step); } if (that.field.getAttribute('max')) { var max = (that.field.getAttribute('max')); that.max = parseFloat(max); } if (that.field.id.length) { properties.id = that.field.id.replace(/[^\w]/g, '_') + "_" + name; } else { properties.id = $.jqx.utilities.createId() + "_" + name; } var wrapper = $("
", properties); wrapper[0].style.cssText = that.field.style.cssText; if (!that.width) { that.width = $(that.field).width(); } if (!that.height) { that.height = $(that.field).outerHeight(); } $(that.field).hide().after(wrapper); var data = that.host.data(); that.host = wrapper; that.host.data(data); that.element = wrapper[0]; that.element.id = that.field.id; that.field.id = properties.id; if (that._className) { that.host.addClass(that._className); $(that.field).removeClass(that._className); } if (that.field.tabIndex) { var tabIndex = that.field.tabIndex; that.field.tabIndex = -1; that.element.tabIndex = tabIndex; } } }, _doTouchHandling: function () { var me = this; var savedValue = me.savedValue; if (!me.parsing) me.parsing = true; if (me.parsing) { if (me.numberInput.val() && me.numberInput.val().indexOf('-') == 0) { me.setvalue('negative', true); } else { me.setvalue('negative', false); } var value = me.numberInput.val(); for (var i = 0; i < value.length - 1; i++) { var ch = value.substring(i, i + 1); if (isNaN(parseFloat(ch)) && me.symbol.toString().indexOf(ch) === -1 && ch != "%" && ch != "$" && ch != '.' && ch != ',' && ch != '-') { me.numberInput[0].value = savedValue; me.parsing = false; return; } } me.ValueString = me.GetValueString(me.numberInput.val(), me.decimalSeparator, me.decimalSeparator != ''); //me.ValueString = new Number(me.ValueString).toFixed(me.decimalDigits); me._parseDecimalInSimpleMode(); me.decimal = me.ValueString; var isNegative = me.getvalue('negative'); if (isNegative) { me.decimal = "-" + me.ValueString; } me.parsing = false; } }, render: function () { this.host .attr({ role: "spinbutton" }); this.host.attr('data-role', 'input'); $.jqx.aria(this); $.jqx.aria(this, "aria-multiline", false); var me = this; if (this.officeMode || (this.theme && this.theme.indexOf('office') != -1)) { if (this.spinButtonsWidth == 18) this.spinButtonsWidth = 15; } if ($.jqx.mobile.isTouchDevice() || this.touchMode === true) { this.inputMode = 'textbox'; this.spinMode = 'simple'; } if (this.decimalSeparator == '') this.decimalSeparator = ' '; this.host.addClass(this.toThemeProperty('jqx-input')); this.host.addClass(this.toThemeProperty('jqx-rc-all')); this.host.addClass(this.toThemeProperty('jqx-widget')); this.host.addClass(this.toThemeProperty('jqx-widget-content')); this.host.addClass(this.toThemeProperty('jqx-numberinput')); if (this.spinButtons) { this._spinButtons(); } else { this.numberInput = $("").appendTo(this.host); this.numberInput.addClass(this.toThemeProperty('jqx-input-content')); this.numberInput.addClass(this.toThemeProperty('jqx-widget-content')); } this.numberInput.attr('placeholder', this.placeHolder); var name = this.host.attr('name'); if (name) { this.numberInput.attr('name', name); } if (this.host.attr('tabindex')) { this.numberInput.attr('tabindex', this.host.attr('tabindex')); this.host.removeAttr('tabindex'); } if ($.jqx.mobile.isTouchDevice() || this.touchMode === true || this.inputMode == 'textbox') { var me = this; me.savedValue = ""; this.addHandler(this.numberInput, 'focus', function () { me.savedValue = me.numberInput[0].value; }); this.addHandler(this.numberInput, 'change', function () { me._doTouchHandling(); }); } var vars = $.data(this.host[0], 'jqxNumberInput'); vars.jqxNumberInput = this; var me = this; if (this.host.parents('form').length > 0) { this.addHandler(this.host.parents('form'), 'reset', function () { setTimeout(function () { me.setDecimal(0); }, 10); }); } this.propertyChangeMap['disabled'] = function (instance, key, oldVal, value) { if (value) { instance.numberInput.addClass(self.toThemeProperty('jqx-input-disabled')); instance.numberInput.attr("disabled", true); } else { instance.host.removeClass(self.toThemeProperty('jqx-input-disabled')); instance.numberInput.attr("disabled", false); } if (instance.spinButtons && instance.host.jqxRepeatButton) { instance.upbutton.jqxRepeatButton({ disabled: value }); instance.downbutton.jqxRepeatButton({ disabled: value }); } } if (this.disabled) { this.numberInput.addClass(this.toThemeProperty('jqx-input-disabled')); this.numberInput.attr("disabled", true); this.host.addClass(this.toThemeProperty('jqx-fill-state-disabled')); } this.selectedText = ""; this.decimalSeparatorPosition = -1; var id = this.element.id; var el = this.element; var self = this; this.oldValue = this._value(); this.items = new Array(); var value = this.value; var decimal = this.decimal; this._initializeLiterals(); this._render(); this.setDecimal(decimal); var me = this; setTimeout(function () { // me._render(false); } , 100); this._addHandlers(); $.jqx.utilities.resize(this.host, function () { me._render(); }); }, refresh: function (initialRefresh) { if (!initialRefresh) { this._render(); } }, wheel: function (event, self) { if (!self.enableMouseWheel) { return; } self.changeType = "mouse"; var delta = 0; if (!event) /* For IE. */ event = window.event; if (event.originalEvent && event.originalEvent.wheelDelta) { event.wheelDelta = event.originalEvent.wheelDelta; } if (event.wheelDelta) { /* IE/Opera. */ delta = event.wheelDelta / 120; } else if (event.detail) { /** Mozilla case. */ delta = -event.detail / 3; } if (delta) { var result = self._handleDelta(delta); if (event.preventDefault) event.preventDefault(); if (event.originalEvent != null) { event.originalEvent.mouseHandled = true; } if (event.stopPropagation != undefined) { event.stopPropagation(); } if (result) { result = false; event.returnValue = result; return result; } else { return false; } } if (event.preventDefault) event.preventDefault(); event.returnValue = false; }, _handleDelta: function (delta) { if (delta < 0) { this.spinDown(); } else this.spinUp(); return true; }, _addHandlers: function () { var self = this; this.addHandler(this.numberInput, 'paste', function (e) { var selection = self._selection(); e.preventDefault(); if (e.originalEvent.clipboardData) { content = (e.originalEvent || e).clipboardData.getData('text/plain'); } else if (window.clipboardData) { content = window.clipboardData.getData('Text'); } this.selectedText = content; $.data(document.body, "jqxSelection", this.selectedText); if (self.inputMode != "simple") { self._pasteSelectedText(); } else self.val(content); setTimeout(function () { self._setSelectionStart(selection.start); }); }); this.addHandler(this.numberInput, 'mousedown', function (event) { return self._raiseEvent(2, event) }); this._mousewheelfunc = this._mousewheelfunc || function (event) { if (!self.editcell) { self.wheel(event, self); return false; } }; this.removeHandler(this.host, 'mousewheel', this._mousewheelfunc); this.addHandler(this.host, 'mousewheel', this._mousewheelfunc); var oldval = ""; this.addHandler(this.numberInput, 'focus', function (event) { $.data(self.numberInput, "selectionstart", self._selection().start); self.host.addClass(self.toThemeProperty('jqx-fill-state-focus')); if (self.spincontainer) { self.spincontainer.addClass(self.toThemeProperty('jqx-numberinput-focus')); } oldval = self.numberInput.val(); self._savedValue = self.decimal; }); this.addHandler(this.numberInput, 'blur', function (event) { if (self.inputMode == 'simple') { self._exitSimpleInputMode(event, self, false, oldval); } if (self.autoValidate) { var val = parseFloat(self.decimal); var isNegative = self.getvalue('negative'); if (isNegative && self.decimal > 0) { val = -parseFloat(self.decimal); } if (val > self.max) { self._disableSetSelection = true; self.setDecimal(self.max); self._disableSetSelection = false; } if (val < self.min) { self._disableSetSelection = true; self.setDecimal(self.min); self._disableSetSelection = false; } } self.host.removeClass(self.toThemeProperty('jqx-fill-state-focus')); if (self.spincontainer) { self.spincontainer.removeClass(self.toThemeProperty('jqx-numberinput-focus')); } if (self.numberInput.val() != oldval) { self._raiseEvent(7, event); $.jqx.aria(self, "aria-valuenow", self.decimal); self.element.value = self.decimal; } return true; }); this.addHandler(this.numberInput, 'mouseup', function (event) { return self._raiseEvent(3, event) }); this.addHandler(this.numberInput, 'keydown', function (event) { self.changeType = "keyboard"; return self._raiseEvent(4, event) }); this.addHandler(this.numberInput, 'keyup', function (event) { return self._raiseEvent(5, event) }); this.addHandler(this.numberInput, 'keypress', function (event) { return self._raiseEvent(6, event) }); }, focus: function () { try { this.numberInput.focus(); } catch (error) { } }, _removeHandlers: function () { var self = this; this.removeHandler(this.numberInput, 'mousedown'); var isOperaMini = $.jqx.mobile.isOperaMiniMobileBrowser(); if (isOperaMini) { this.removeHandler($(document), 'click.' + this.element.id, self._exitSimpleInputMode, self); } this.removeHandler(this.numberInput, 'paste'); this.removeHandler(this.numberInput, 'focus'); this.removeHandler(this.numberInput, 'blur'); this.removeHandler(this.numberInput, 'mouseup'); this.removeHandler(this.numberInput, 'keydown'); this.removeHandler(this.numberInput, 'keyup'); this.removeHandler(this.numberInput, 'keypress'); }, //[optimize] _spinButtons: function () { if (this.host.jqxRepeatButton) { if (!this.numberInput) { this.numberInput = $(""); this.numberInput.appendTo(this.host); this.numberInput.addClass(this.toThemeProperty('jqx-input-content')); this.numberInput.addClass(this.toThemeProperty('jqx-widget-content')); } else { this.numberInput.css('float', 'left'); } if (this.spincontainer) { if (this.upbutton) { this.upbutton.jqxRepeatButton('destroy'); } if (this.downbutton) { this.downbutton.jqxRepeatButton('destroy'); } this.spincontainer.remove(); } this.spincontainer = $('
'); if (this.rtl) { this.spincontainer.css('float', 'right'); this.numberInput.css('float', 'right'); this.spincontainer.css('left', '-1px'); } this.host.append(this.spincontainer); this.upbutton = $('
'); this.spincontainer.append(this.upbutton); this.upbutton.jqxRepeatButton({ overrideTheme: true, disabled: this.disabled, roundedCorners: 'top-right' }); this.downbutton = $('
'); this.spincontainer.append(this.downbutton); this.downbutton.jqxRepeatButton({ overrideTheme: true, disabled: this.disabled, roundedCorners: 'bottom-right' }); if (this.template) { this.upbutton.addClass(this.toThemeProperty("jqx-" + this.template)) this.downbutton.addClass(this.toThemeProperty("jqx-" + this.template)) } var me = this; this.downbutton.addClass(this.toThemeProperty('jqx-fill-state-normal jqx-action-button')); this.upbutton.addClass(this.toThemeProperty('jqx-fill-state-normal jqx-action-button')); this.upbutton.addClass(this.toThemeProperty('jqx-rc-tr')); this.downbutton.addClass(this.toThemeProperty('jqx-rc-br')); this.addHandler(this.downbutton, 'mouseup', function (event) { if (!me.disabled) { me.downbutton.removeClass(me.toThemeProperty('jqx-fill-state-pressed')); me._downArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-down-selected')); } }); this.addHandler(this.upbutton, 'mouseup', function (event) { if (!me.disabled) { me.upbutton.removeClass(me.toThemeProperty('jqx-fill-state-pressed')); me._upArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-up-selected')); } }); this.removeHandler($(document), 'mouseup.' + this.element.id); this.addHandler($(document), 'mouseup.' + this.element.id, function (event) { me.upbutton.removeClass(me.toThemeProperty('jqx-fill-state-pressed')); me._upArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-up-selected')); me.downbutton.removeClass(me.toThemeProperty('jqx-fill-state-pressed')); me._downArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-down-selected')); }); this.addHandler(this.downbutton, 'mousedown', function (event) { if (!me.disabled) { if ($.jqx.browser.msie && $.jqx.browser.version < 9) { me._inputSelection = me._selection(); } me.downbutton.addClass(me.toThemeProperty('jqx-fill-state-pressed')); me._downArrow.addClass(me.toThemeProperty('jqx-icon-arrow-down-selected')); event.preventDefault(); event.stopPropagation(); return false; } }); this.addHandler(this.upbutton, 'mousedown', function (event) { if (!me.disabled) { if ($.jqx.browser.msie && $.jqx.browser.version < 9) { me._inputSelection = me._selection(); } me.upbutton.addClass(me.toThemeProperty('jqx-fill-state-pressed')); me._upArrow.addClass(me.toThemeProperty('jqx-icon-arrow-up-selected')); event.preventDefault(); event.stopPropagation(); return false; } }); this.addHandler(this.upbutton, 'mouseenter', function (event) { me.upbutton.addClass(me.toThemeProperty('jqx-fill-state-hover')); me._upArrow.addClass(me.toThemeProperty('jqx-icon-arrow-up-hover')); }); this.addHandler(this.upbutton, 'mouseleave', function (event) { me.upbutton.removeClass(me.toThemeProperty('jqx-fill-state-hover')); me._upArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-up-hover')); }); this.addHandler(this.downbutton, 'mouseenter', function (event) { me.downbutton.addClass(me.toThemeProperty('jqx-fill-state-hover')); me._downArrow.addClass(me.toThemeProperty('jqx-icon-arrow-down-hover')); }); this.addHandler(this.downbutton, 'mouseleave', function (event) { me.downbutton.removeClass(me.toThemeProperty('jqx-fill-state-hover')); me._downArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-down-hover')); }); this.upbutton.css('border-width', '0px'); this.downbutton.css('border-width', '0px'); if (this.disabled) { this.upbutton[0].disabled = true; this.downbutton[0].disabled = true; } else { this.upbutton[0].disabled = false; this.downbutton[0].disabled = false; } this.spincontainer.addClass(this.toThemeProperty('jqx-input')); this.spincontainer.addClass(this.toThemeProperty('jqx-rc-r')); this.spincontainer.css('border-width', '0px'); if (!this.rtl) { this.spincontainer.css('border-left-width', '1px'); } else { this.spincontainer.css('border-right-width', '1px'); } this._upArrow = this.upbutton.find('div'); this._downArrow = this.downbutton.find('div'); this._upArrow.addClass(this.toThemeProperty('jqx-icon-arrow-up')); this._downArrow.addClass(this.toThemeProperty('jqx-icon-arrow-down')); this._upArrow.addClass(this.toThemeProperty('jqx-input-icon')); this._downArrow.addClass(this.toThemeProperty('jqx-input-icon')); var me = this; this._upArrow.hover(function () { if (!me.disabled) { me._upArrow.addClass(me.toThemeProperty('jqx-icon-arrow-up-hover')); } }, function () { me._upArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-up-hover')); }); this._downArrow.hover(function () { if (!me.disabled) { me._downArrow.addClass(me.toThemeProperty('jqx-icon-arrow-down-hover')); } }, function () { me._downArrow.removeClass(me.toThemeProperty('jqx-icon-arrow-down-hover')); }); var isTouchDevice = $.jqx.mobile.isTouchDevice(); var eventname = 'click'; if (isTouchDevice) { eventname = $.jqx.mobile.getTouchEventName('touchstart'); } if (isTouchDevice) { this.addHandler(this.downbutton, 'click', function (event) { me.spinDown(); }); this.addHandler(this.upbutton, 'click', function (event) { me.spinUp(); }); } this.addHandler(this.downbutton, eventname, function (event) { if (!isTouchDevice) { if (me._selection().start == 0) { me._setSelectionStart(me.numberInput.val().length); } if ($.jqx.browser.msie && $.jqx.browser.version < 9) { me._setSelectionStart(me._inputSelection.start); } } else { event.preventDefault(); event.stopPropagation(); } me.spinDown(); return false; }); this.addHandler(this.upbutton, eventname, function (event) { if (!isTouchDevice) { if (me._selection().start == 0) { me._setSelectionStart(me.numberInput.val().length); } if ($.jqx.browser.msie && $.jqx.browser.version < 9) { me._setSelectionStart(me._inputSelection.start); } } else { event.preventDefault(); event.stopPropagation(); } me.spinUp(); return false; }); } else { throw new Error("jqxNumberInput: Missing reference to jqxbuttons.js."); } }, spinDown: function () { var me = this; var oldDecimal = this.decimal; if (me.spinMode == 'none') return; if (this.decimal == null) { this.setDecimal(0); return; } var isNegative = this.getvalue('negative'); var negativeOffset = isNegative ? -1 : 0; if ($.jqx.mobile.isTouchDevice() || this.inputMode == 'textbox') { me._doTouchHandling(); } if (!me.disabled) { var selection = this._selection(); var olddecimal = this.decimal; var decimal = this.getDecimal(); if (decimal < this.min) { decimal = this.min; this.setDecimal(this.min); this._setSelectionStart(selection.start); this.spinDown(); return; } else if (decimal > this.max) { decimal = this.max; this.setDecimal(this.max); this._setSelectionStart(selection.start); this.spinDown(); return; } if (me.spinButtonsStep < 0) me.spinButtonsStep = 1; var dec = parseInt(me.decimal) - me.spinButtonsStep; dec = dec.toString().length; var validvalue = negativeOffset + dec <= me.digits; if (me.spinMode != 'advanced') { if (decimal - me.spinButtonsStep >= me.min && validvalue) { var multiple = 1; for (i = 0; i < me.decimalDigits; i++) { multiple = multiple * 10; } var newvalue = (multiple * decimal) - (multiple * me.spinButtonsStep); newvalue = newvalue / multiple; newvalue = this._parseDecimalValueToEditorValue(newvalue); me.setDecimal(newvalue); } } else { var values = this._getspindecimal(); var separator = this._getSeparatorPosition(); var decimal = parseFloat(values.decimal); if (me.spinButtonsStep < 0) me.spinButtonsStep = 1; var dec = parseInt(decimal) - me.spinButtonsStep; dec = dec.toString().length; var validvalue = negativeOffset + dec <= me.digits; var multiple = 1; var separatorindex = values.decimal.indexOf("."); if (separatorindex != -1) { var divide = values.decimal.length - separatorindex - 1; var multiple = 1; for (var i = 0; i < divide; i++) { multiple = multiple * 10; } decimal -= new Number(me.spinButtonsStep / multiple); decimal = decimal.toFixed(divide); var separatorindex = decimal.toString().indexOf("."); if (separatorindex == -1) { decimal = decimal.toString() + '.'; } var result = decimal.toString() + values.afterdecimal; result = new Number(result); result = result.toFixed(me.decimalDigits); if (result >= me.min) { result = this._parseDecimalValueToEditorValue(result); me.setDecimal(result); } } else { if (decimal - me.spinButtonsStep >= me.min && validvalue) { var newvalue = (multiple * decimal) - (multiple * me.spinButtonsStep); newvalue = newvalue / multiple; var result = newvalue.toString() + values.afterdecimal; if (result >= me.min) { result = this._parseDecimalValueToEditorValue(result); me.setDecimal(result); } } } } if (result == undefined || this.inputMode != 'simple') { this._setSelectionStart(selection.start); me.savedValue = me.numberInput[0].value; if (oldDecimal != this.decimal) { if ($.jqx.mobile.isTouchDevice()) { this._raiseEvent(0, {}); } this._raiseEvent(7, {}); } $.jqx.aria(self, "aria-valuenow", this.decimal); return; } result = this.decimal.toString(); var isNegative = this.getvalue('negative'); if (negativeOffset == 0 && isNegative) { this._setSelectionStart(selection.start + 1); } else { if ((result != undefined && (olddecimal == undefined || olddecimal.toString().length == result.length))) { this._setSelectionStart(selection.start); } else { if (isNegative) { this._setSelectionStart(selection.start + 1); } else { this._setSelectionStart(selection.start - 1); } } } if (oldDecimal != this.decimal) { if ($.jqx.mobile.isTouchDevice()) { this._raiseEvent(0, {}); } this._raiseEvent(7, {}); } $.jqx.aria(self, "aria-valuenow", this.decimal); } }, _getspindecimal: function () { var selection = this._selection(); var decimalString = ""; var separatorPosition = this._getSeparatorPosition(); var visibleItems = this._getVisibleItems(); var prefix = this._getHiddenPrefixCount(); var text = this.numberInput.val(); if (this.numberInput.val().length == selection.start && selection.length == 0) { this._setSelection(selection.start, selection.start + 1); selection = this._selection(); } var issimple = this.inputMode != 'advanced'; for (var i = 0; i < selection.start; i++) { if (issimple) { var literal = text.substring(i, i + 1); var isDigit = (!isNaN(parseInt(literal))); if (isDigit) { decimalString += literal; } if (literal == this.decimalSeparator) { decimalString += literal; } continue; } if (visibleItems[i].canEdit && visibleItems[i].character != this.promptChar) { decimalString += visibleItems[i].character; } else if (!visibleItems[i].canEdit && this.decimalSeparatorPosition != -1 && visibleItems[i] == visibleItems[this.decimalSeparatorPosition - prefix]) { if (decimalString.length == 0) { decimalString = "0"; } decimalString += visibleItems[i].character; } } var afterdecimal = ""; for (var i = selection.start; i < visibleItems.length; i++) { if (issimple) { var literal = text.substring(i, i + 1); var isDigit = (!isNaN(parseInt(literal))); if (isDigit) { afterdecimal += literal; } if (literal == this.decimalSeparator) { afterdecimal += literal; } continue; } if (visibleItems[i].canEdit && visibleItems[i].character != this.promptChar) { afterdecimal += visibleItems[i].character; } else if (!visibleItems[i].canEdit && this.decimalSeparatorPosition != -1 && visibleItems[i] == visibleItems[this.decimalSeparatorPosition - prefix]) { afterdecimal += visibleItems[i].character; } } var isNegative = this.getvalue('negative'); var d = isNegative ? "-" + this._parseDecimalValue(decimalString).toString() : this._parseDecimalValue(decimalString).toString(); return { decimal: d, afterdecimal: this._parseDecimalValue(afterdecimal) }; }, _parseDecimalValue: function (number) { if (this.decimalSeparator != '.') { var start = number.toString().indexOf(this.decimalSeparator); if (start >= 0) { var result = number.toString().substring(0, start) + '.' + number.toString().substring(start + 1); return result; } } return number; }, _parseDecimalValueToEditorValue: function (number) { if (this.decimalSeparator != '.') { var start = number.toString().indexOf("."); if (start >= 0) { var result = number.toString().substring(0, start) + this.decimalSeparator + number.toString().substring(start + 1); return result; } } return number; }, spinUp: function () { var me = this; var oldDecimal = this.decimal; if (me.spinMode == 'none') return; if (this.decimal == null) { this.setDecimal(0); return; } if ($.jqx.mobile.isTouchDevice() || this.inputMode == 'textbox') { me._doTouchHandling(); } var isNegative = this.getvalue('negative'); var negativeOffset = isNegative ? -1 : 0; if (!me.disabled) { var selection = this._selection(); var olddecimal = me.decimal; var decimal = me.getDecimal(); if (decimal < this.min) { decimal = this.min; this.setDecimal(this.min); this._setSelectionStart(selection.start); this.spinUp(); return; } else if (decimal > this.max) { decimal = this.max; this.setDecimal(this.max); this._setSelectionStart(selection.start); this.spinUp(); return; } if (me.spinButtonsStep < 0) me.spinButtonsStep = 1; var dec = parseInt(me.decimal) + me.spinButtonsStep; dec = dec.toString().length; var validvalue = negativeOffset + dec <= me.digits; if (me.spinMode != 'advanced') { if (decimal + me.spinButtonsStep <= me.max && validvalue) { var multiple = 1; for (var i = 0; i < me.decimalDigits; i++) { multiple = multiple * 10; } var newvalue = (multiple * decimal) + (multiple * me.spinButtonsStep); newvalue = newvalue / multiple; newvalue = this._parseDecimalValueToEditorValue(newvalue); me.setDecimal(newvalue); } } else { var values = this._getspindecimal(); var separator = this._getSeparatorPosition(); var decimal = parseFloat(values.decimal); if (me.spinButtonsStep < 0) me.spinButtonsStep = 1; var dec = parseInt(decimal) + me.spinButtonsStep; dec = dec.toString().length; var validvalue = negativeOffset + dec <= me.digits; var multiple = 1; var separatorindex = values.decimal.indexOf("."); if (separatorindex != -1) { var divide = values.decimal.length - separatorindex - 1; var multiple = 1; for (var i = 0; i < divide; i++) { multiple = multiple * 10; } decimal += new Number(me.spinButtonsStep / multiple); decimal = decimal.toFixed(divide); var separatorindex = decimal.toString().indexOf("."); if (separatorindex == -1) { decimal = decimal.toString() + '.'; } var result = decimal.toString() + values.afterdecimal; result = new Number(result); result = result.toFixed(me.decimalDigits); var number = new Number(result).toFixed(me.decimalDigits); if (number <= me.max) { result = this._parseDecimalValueToEditorValue(result); me.setDecimal(result); } else result = undefined; } else { if (decimal + me.spinButtonsStep <= me.max && validvalue) { var newvalue = (multiple * decimal) + (multiple * me.spinButtonsStep); newvalue = newvalue / multiple; var result = newvalue.toString() + values.afterdecimal; var number = new Number(result).toFixed(me.decimalDigits); if (number <= me.max) { result = this._parseDecimalValueToEditorValue(result); if (isNegative && result.indexOf('-') == -1) { if (values.decimal != '-0') { result = '-' + result; } } me.setDecimal(result); } else { result = undefined; } } } } if (result == undefined || this.inputMode != 'simple') { this._setSelectionStart(selection.start); me.savedValue = me.numberInput[0].value; if (oldDecimal != this.decimal) { if ($.jqx.mobile.isTouchDevice()) { this._raiseEvent(0, {}); } this._raiseEvent(7, {}); } $.jqx.aria(self, "aria-valuenow", this.decimal); return; } result = this.decimal.toString(); var isNegative = this.getvalue('negative'); if (negativeOffset == -1 && !isNegative) { this._setSelectionStart(-1 + selection.start); } else { if ((result != undefined && (olddecimal == undefined || olddecimal.toString().length == result.length))) { this._setSelectionStart(selection.start); } else { if (isNegative) { this._setSelectionStart(selection.start); } else { this._setSelectionStart(1 + selection.start); } } } if (oldDecimal != this.decimal) { if ($.jqx.mobile.isTouchDevice()) { this._raiseEvent(0, {}); } this._raiseEvent(7, {}); } $.jqx.aria(self, "aria-valuenow", this.decimal); } }, _exitSimpleInputMode: function (event, self, checkbounds, oldvalue) { if (self == undefined) { self = event.data; } if (self == null) return; if (checkbounds == undefined) { if (event.target != null && self.element != null) { if ((event.target.id != undefined && event.target.id.toString().length > 0 && self.host.find('#' + event.target.id).length > 0) || event.target == self.element) { return; } } var offset = self.host.offset(); var left = offset.left; var top = offset.top; var width = self.host.width(); var height = self.host.height(); var targetOffset = $(event.target).offset(); if (targetOffset.left >= left && targetOffset.left <= left + width) if (targetOffset.top >= top && targetOffset.top <= top + height) { return; } } if ($.jqx.mobile.isOperaMiniBrowser()) { self.numberInput.attr("readonly", true); } if (self.disabled || self.readOnly) return; var enteredMode = $.data(self.numberInput, "simpleInputMode"); if (enteredMode == null) return; $.data(self.numberInput, "simpleInputMode", null); this._parseDecimalInSimpleMode(); return false; }, _getDecimalInSimpleMode: function () { var val = this.decimal; if (this.decimalSeparator != '.') { var indx = val.toString().indexOf(this.decimalSeparator); if (indx > 0) { var prefix = val.toString().substring(0, indx); var val = prefix + "." + val.toString().substring(indx + 1); } } return val; }, _parseDecimalInSimpleMode: function (refreshValue) { var self = this; var isNegative = self.getvalue('negative'); var decimal = this.ValueString; if (decimal == undefined) { decimal = this.GetValueString(this.numberInput.val(), this.decimalSeparator, this.decimalSeparator != ""); } if (this.decimalSeparator != '.') { var indx = decimal.toString().indexOf("."); if (indx > 0) { var prefix = decimal.toString().substring(0, indx); var val = prefix + this.decimalSeparator + decimal.toString().substring(indx + 1); decimal = val; } } var string = isNegative ? "-" : ''; if (this.symbolPosition == 'left') { string += this.symbol; } var leadingDigitsCount = this.digits % this.groupSize; if (leadingDigitsCount == 0) { leadingDigitsCount = this.groupSize; } var decimalString = decimal.toString(); if (decimalString.indexOf('-') >= 0) { decimalString = decimalString.substring(decimalString.indexOf('-') + 1); } string += decimalString; if (this.symbolPosition == 'right') { string += this.symbol; } if (refreshValue != false) { self.numberInput.val(string); } }, //[optimize] _enterSimpleInputMode: function (event, self) { if (self == undefined) { self = event.data; } var selection = this._selection(); if (self == null) return; var isNegative = self.getvalue('negative'); var decimal = self.decimal; if (isNegative) { if (decimal > 0) decimal = -decimal; } self.numberInput.val(decimal); $.data(self.numberInput, "simpleInputMode", true); if ($.jqx.mobile.isOperaMiniBrowser()) { self.numberInput.attr("readonly", false); } this._parseDecimalInSimpleMode(); this._setSelectionStart(selection.start); }, setvalue: function (name, value) { if (this[name] !== undefined) { if (name == 'decimal') { this._setDecimal(value); } else { this[name] = value; this.propertyChangedHandler(this, name, value, value); } } }, getvalue: function (name) { if (name == 'decimal') { if (this.negative != undefined && this.negative == true) { return -Math.abs(this[name]); } } if (name in this) { return this[name] } return null; }, // gets the intput's value. _getString: function () { var s = ""; for (var i = 0; i < this.items.length; i++) { var character = this.items[i].character; s += character; } return s; }, //[optimize] _literal: function (letter, regExpression, editable, separator) { return { character: letter, regex: regExpression, canEdit: editable, isSeparator: separator }; }, //[optimize] _initializeLiterals: function () { if (this.inputMode == 'textbox') return; // add the negative symbol. var index = 0; var negativeSymbolLength = this.negativeSymbol.length; for (var i = 0; i < negativeSymbolLength; i++) { var character = this.negativeSymbol.substring(i, i + 1); var regex = ""; var canEdit = false; var literal = null; if (this.negative) { literal = this._literal(character, regex, canEdit, false); } else { literal = this._literal('', regex, canEdit, false); } this.items[index] = literal; index++; } // add the currency or percentage symbol. var symbolLength = this.symbol.length; if (this.symbolPosition == 'left') { for (i = 0; i < symbolLength; i++) { var character = this.symbol.substring(i, i + 1); var regex = ""; var canEdit = false; var literal = this._literal(character, regex, canEdit, false); this.items[index] = literal; index++; } } var leadingDigitsCount = this.digits % this.groupSize; if (leadingDigitsCount == 0) { leadingDigitsCount = this.groupSize; } // add the digits and group separators. for (var i = 0; i < this.digits; i++) { var character = this.promptChar; var regex = "\\d"; var canEdit = true; var literal = this._literal(character, regex, canEdit, false); this.items[index] = literal; index++; if (i < this.digits - 1 && this.groupSeparator != undefined && this.groupSeparator.length > 0) { leadingDigitsCount--; if (leadingDigitsCount == 0) { leadingDigitsCount = this.groupSize; var separatorLiteral = this._literal(this.groupSeparator, "", false, false); this.items[index] = separatorLiteral; index++; } } else if (i == this.digits - 1) { literal.character = 0; } } this.decimalSeparatorPosition = -1; // add the digits decimal separator and the decimal digits. if (this.decimalDigits != undefined && this.decimalDigits > 0) { var character = this.decimalSeparator; if (character.length == 0) { character = "."; } var literal = this._literal(character, "", false, true); this.items[index] = literal; this.decimalSeparatorPosition = index; index++; for (var i = 0; i < this.decimalDigits; i++) { var decimalCharacter = 0; var regex = "\\d"; var decimalDigit = this._literal(decimalCharacter, regex, true, false); this.items[index] = decimalDigit; index++; } } // add the currency or percentage symbol. if (this.symbolPosition == 'right') { for (var i = 0; i < symbolLength; i++) { var character = this.symbol.substring(i, i + 1); var regex = ""; var canEdit = false; var literal = this._literal(character, regex, canEdit); this.items[index] = literal; index++; } } }, //[optimize] _match: function (character, regex) { var regExpr = new RegExp(regex, "i"); return regExpr.test(character); }, //[optimize] _raiseEvent: function (id, arg) { var evt = this.events[id]; var args = {}; args.owner = this; if (this.host.css('display') == 'none') { return true; } var key = arg.charCode ? arg.charCode : arg.keyCode ? arg.keyCode : 0; var result = true; var isreadOnly = this.readOnly; var me = this; if (id == 3 || id == 2) { if (!this.disabled) { if (this.inputMode != 'simple' && this.inputMode != 'textbox') { this._handleMouse(arg); } else { // this._enterSimpleInputMode(null, me); return true; } } } if (id == 0) { var decimalValue = this.getvalue('decimal'); if ((this.max < decimalValue) || (this.min > decimalValue)) { this.host.addClass(this.toThemeProperty("jqx-input-invalid")); } else { this.host.removeClass(this.toThemeProperty("jqx-input-invalid")); this.host.addClass(this.toThemeProperty("jqx-input")); this.host.addClass(this.toThemeProperty("jqx-rc-all")); } } var event = new $.Event(evt); event.owner = this; args.value = this.getvalue('decimal'); args.text = this.numberInput.val(); event.args = args; if (id == 7) { args.type = this.changeType; this.changeType = null; } if (evt != undefined) { if (id != 4 && id != 5 && id != 6) { result = this.host.trigger(event); } } var me = this; // key down if (this.inputMode == 'textbox') return result; if (this.inputMode != 'simple') { if (id == 4) { if (isreadOnly || this.disabled) { return false; } result = me._handleKeyDown(arg, key); } // key up else if (id == 5) { if (isreadOnly || this.disabled) { result = false; } } else if (id == 6) { if (isreadOnly || this.disabled) { return false; } result = me._handleKeyPress(arg, key); } } else { if (id == 4 || id == 5 || id == 6) { if ($.jqx.mobile.isTouchDevice() || this.touchMode === true) { return true; } if (isreadOnly || this.disabled) { return false; } var letter = String.fromCharCode(key); var digit = parseInt(letter); var allowInput = true; if (!arg.ctrlKey && !arg.shiftKey && !arg.metaKey) { if (key >= 65 && key <= 90) { allowInput = false; } } if (id == 6 && $.jqx.browser.opera != undefined) { if (key == 8) return false; } if (allowInput) { if (id == 4) { allowInput = me._handleSimpleKeyDown(arg, key); } if (key == 189 || key == 45 || key == 109 || key == 173) { var selection = me._selection(); if (id == 4) { var isNegative = me.getvalue('negative'); if (isNegative == false) { me.setvalue('negative', true); } else { me.setvalue('negative', false); } me.decimal = me.ValueString; me._parseDecimalInSimpleMode(); me._setSelectionStart(selection.start); allowInput = false; me._raiseEvent(0, me.value); me._raiseEvent(1, me.numberInput.val()); } } var ctrlKey = args.ctrlKey || args.metaKey; if (!$.jqx.browser.msie) { var e = arg; if ((ctrlKey && key == 99 /* firefox */) || (ctrlKey && key == 67) /* opera */ || (ctrlKey && key == 122 /* firefox */) || (ctrlKey && key == 90) /* opera */ || (ctrlKey && key == 118 /* firefox */) || (ctrlKey && key == 86) /* opera */ || (e.shiftKey && key == 45)) { if ($.jqx.browser.webkit || $.jqx.browser.chrome) { me._handleSimpleKeyDown(arg, key); } if (key == 67) return true; return false; } } if ((ctrlKey && key == 97 /* firefox */) || (ctrlKey && key == 65) /* opera */) { return true; } if (id == 6 && allowInput) { var specialKey = this._isSpecialKey(key); return specialKey; } } return allowInput; } } return result; }, GetSelectionInValue: function (selectionPosition, text, separator, hasSeparator) { var selectionInValue = 0; for (i = 0; i < text.length; i++) { if (i >= selectionPosition) break; var literal = text.substring(i, i + 1); var isDigit = (!isNaN(parseInt(literal))); if (isDigit || (hasSeparator && text.substring(i, i + 1) == separator)) { selectionInValue++; } } return selectionInValue; }, GetSelectionLengthInValue: function (selectionPosition, selectionLength, text, separator) { var selectionInValue = 0; for (i = 0; i < text.length; i++) { if (i >= selectionPosition + selectionLength) break; var literal = text.substring(i, i + 1); var isDigit = (!isNaN(parseInt(literal))); if (selectionLength > 0 && i >= selectionPosition && isDigit || (i >= selectionPosition && text[i].toString() == separator)) { selectionInValue++; } } return selectionInValue; }, GetInsertTypeByPositionInValue: function (positionInValue, separator, text, hasSeparator) { var insertType = "before"; var valueString = this.GetValueString(text, separator, hasSeparator); var digitsToSeparator = this.GetDigitsToSeparator(0, valueString, separator); if (positionInValue > digitsToSeparator) { insertType = 'after'; } return insertType; }, RemoveRange: function (start, length, text, separatorChar, updateText, insert) { var decimalPossibleChars = this.digits; var selectionStart = start; var selectionLength = length; var removedDigits = 0; var value = this.decimal; var selection = this._selection(); // var text = this.numberInput.val(); var separatorChar = this.decimalSeparator; var hasSeparator = separatorChar != ''; if (selectionLength == 0 && this.ValueString.length < this.decimalPossibleChars - 1) return removedDigits; var separatorPosition = this.GetSeparatorPositionInText(separatorChar, text); if (!updateText) { separatorPosition = this.GetSeparatorPositionInText(separatorChar, text); } if (separatorPosition < 0 && !hasSeparator && text.length > 1) { separatorPosition = text.length; } if (separatorPosition == -1) separatorPosition = text.length; var separatorOffset = hasSeparator ? 1 : 0; if (length < 2 && insert == true) { var valueDigits = this.ValueString.length - this.decimalDigits - separatorOffset; if ((valueDigits) == decimalPossibleChars && start + length < separatorPosition) { selectionLength++; } } var newTextString = ""; for (var i = 0; i < text.length; i++) { if (i < selectionStart || i >= selectionStart + selectionLength) { newTextString += text.substring(i, i + 1); continue; } else { var literal = text.substring(i, i + 1); if (literal == separatorChar) { newTextString += separatorChar; continue; } else { var literal = text.substring(i, i + 1); if (this.symbol && this.symbol != "" && this.symbol.indexOf(literal) >= 0) continue; if (i > separatorPosition) { newTextString += "0"; continue; } } } var literal = text.substring(i, i + 1); var isDigit = (!isNaN(parseInt(literal))); if (isDigit) { removedDigits++; } } if (newTextString.length == 0) { newTextString = "0"; } if (updateText) { this.numberInput.val(newTextString); } else { this.ValueString = newTextString; } var ch = newTextString.substring(0, 1); if (ch == separatorChar && isNaN(parseInt(ch))) { var res = '0' + newTextString; newTextString = res; } this.ValueString = this.GetValueString(newTextString, separatorChar, hasSeparator); this.decimal = this.ValueString; this._parseDecimalInSimpleMode(); this._setSelectionStart(selectionStart); return removedDigits; }, InsertDigit: function (digit, position) { if (typeof this.digits != 'number') { this.digits = parseInt(this.digits); } if (typeof this.decimalDigits != 'number') { this.decimalDigits = parseInt(this.decimalDigits); } var decimalPossibleChars = 1 + this.digits; var selection = this._selection(); var isNegative = this.getvalue('negative'); var increased = false; if (selection.start == 0 && this.symbol != '' && this.symbolPosition == 'left') { this._setSelectionStart(selection.start + 1); selection = this._selection(); increased = true; } if ((isNegative && increased) || (isNegative && !increased && selection.start == 0)) { this._setSelectionStart(selection.start + 1); selection = this._selection(); } var selectionChar = this.numberInput.val().substring(selection.start, selection.start + 1); var text = this.numberInput.val(); var separatorChar = this.decimalSeparator; var hasSeparator = separatorChar != '' && this.decimalDigits > 0; if (selectionChar == this.symbol && this.symbolPosition == 'right') { if (this.decimalDigits == 0) { this.ValueString = this.GetValueString(text, separatorChar, hasSeparator); if (this.ValueString.length >= decimalPossibleChars) return; } else { return; } } this.ValueString = this.GetValueString(text, separatorChar, hasSeparator); if (this.ValueString == "") { this.ValueString = new Number(0).toFixed(this.decimalDigits); } var value = this.ValueString; if (this.decimalDigits > 0 && position >= value.length) { position = value.length - 1; } var valueChar = ''; if (position < value.length) { valueChar = value.substring(position, position + 1); } var shouldReplace = false; var decrementedPosition = false; var type = this.GetInsertTypeByPositionInValue(position, separatorChar, text, hasSeparator); if (type == 'after') { shouldReplace = true; } var separatorOffset = hasSeparator ? 1 : 0; if (valueChar != separatorChar && (this.ValueString.length - this.decimalDigits - separatorOffset) >= decimalPossibleChars - 1) { shouldReplace = true; } if (valueChar === "0" && this.ValueString.length === 1 && this.decimalDigits === 0) { shouldReplace = true; } var isdecimal = false; var separatoroffset = hasSeparator ? 1 : 0; if (!shouldReplace && this.ValueString && this.ValueString.length >= this.digits + this.decimalDigits + separatoroffset) { return; } if (shouldReplace && valueChar != separatorChar) { if (isdecimal) position++; var before = value.substring(0, position); if (before.length == value.length) { if (this.ValueString.length >= this.digits + this.decimalDigits + separatoroffset) return; } var current = digit; var after = ""; if (position + 1 < value.length) { after = value.substring(position + 1); } var result = before + current + after; this.ValueString = result; } else { var before = value.substring(0, position); var current = digit; var after = value.substring(position); var result = before + current + after; if (value.substring(0, 1) == '0' && value.substring(1, 2) == separatorChar) { result = current + value.substring(1); if (valueChar == separatorChar) { this._setSelectionStart(selection.start - 1); selection = this._selection(); } } this.ValueString = result; } if (isNegative) { this.decimal = -this.ValueString; } else this.decimal = this.ValueString; this._parseDecimalInSimpleMode(); var start = selection.start; start += 1; this._setSelectionStart(start); this.value = this.decimal; this._raiseEvent(0, this.value); this._raiseEvent(1, this.numberInput.val()); }, GetStringToSeparator: function (text, separator, hasSeparator) { var res = ""; var pointSeparator = separator; var separatorInText = this.GetSeparatorPositionInText(separator, text); var newString = text.subString(0, separatorInText); res = this.GetValueString(newString, separator, hasSeparator); return res; }, GetSeparatorPositionInText: function (separator, text) { var decimalPointPos = -1; for (i = 0; i < text.length; i++) { if (text.substring(i, i + 1) == separator) { decimalPointPos = i; break; } } return decimalPointPos; }, GetValueString: function (text, separator, hasSeparator) { var res = ""; for (var i = 0; i < text.length; i++) { var literal = text.substring(i, i + 1); var isDigit = (!isNaN(parseInt(literal))); if (isDigit) { res += literal; } if (literal == separator) { res += separator; } } return res; }, Backspace: function () { var selection = this._selection(); var initialselection = this._selection(); var text = this.numberInput.val(); if (selection.start == 0 && selection.length == 0) return; this.isBackSpace = true; var literal = text.substring[selection.start, selection.start + 1]; var isDigit = (!isNaN(parseInt(literal))); if (selection.start > 0 && selection.length == 0) { this._setSelectionStart(selection.start - 1); var selection = this._selection(); } this.Delete(); this._setSelectionStart(initialselection.start - 1); this.isBackSpace = false; }, Delete: function (deleteWithoutSelection) { var selection = this._selection(); var text = this.numberInput.val(); if (selection.start === 0 && text.substring(0, 1) == "-") { this.setvalue('negative', false); var selection = this._selection(); var text = this.numberInput.val(); } var selectionStart = selection.start; var selectionLength = selection.length; selectionLength = Math.max(selectionLength, 1); this.ValueString = this.GetValueString(text, this.decimalSeparator, this.decimalSeparator != ''); if (selectionStart > this.ValueString.indexOf(this.decimalSeparator) && this.decimalDigits > 0) { selectionStart++; } var offset = 0; if (this.symbol) { if (this.symbolPosition == "left") { offset--; } if (this.negative) offset--; } this.RemoveRange(selection.start + offset, selectionLength, this.ValueString, ".", false); var literal = this.ValueString.substring(0, 1); var isDigit = (!isNaN(parseInt(literal))); if (!isDigit) { this.ValueString = '0' + this.ValueString; } this.decimal = this.ValueString; this._parseDecimalInSimpleMode(); this._setSelectionStart(selectionStart); this.value = this.decimal; this._raiseEvent(0, this.value); this._raiseEvent(1, this.numberInput.val()); }, insertsimple: function (insertion) { var selection = this._selection(); var text = this.numberInput.val(); if (selection.start == text.length && this.decimal != null && this.decimalDigits > 0) return; var oldValue = this.decimal; var separatorChar = this.decimalSeparator; this.ValueString = this.GetValueString(text, separatorChar, separatorChar != ''); var positionInValue = this.GetSelectionInValue(selection.start, text, separatorChar, separatorChar != ''); var lengthInValue = this.GetSelectionLengthInValue(selection.start, selection.length, text, separatorChar); var digitsToSeparator = this.GetDigitsToSeparator(0, this.ValueString, separatorChar); var decrementPositionInValue = false; if (this.decimalDigits > 0 && positionInValue >= this.ValueString.length) { positionInValue--; } if (this.ValueString == "") { this.ValueString = new Number(0).toFixed(this.decimalDigits); this.ValueString = this.ValueString.replace(".", separatorChar); this.RemoveRange(selection.start, lengthInValue, this.ValueString, separatorChar, false, true); this.InsertDigit(insertion, 0, selection); return; } this.RemoveRange(selection.start, lengthInValue, this.ValueString, separatorChar, false, true); this.InsertDigit(insertion, positionInValue, selection); }, GetDigitsToSeparator: function (digitsToSeparator, valueString, separator) { if (separator == undefined) separator = '.'; if (valueString.indexOf(separator) < 0) { return valueString.length; } for (i = 0; i < valueString.length; i++) { if (valueString.substring(i, i + 1) == separator) { digitsToSeparator = i; break; } } return digitsToSeparator; }, _handleSimpleKeyDown: function (e, key) { var selection = this._selection(); var ctrlKey = e.ctrlKey || e.metaKey; if ((key == 8 || key == 46) && ctrlKey) { this.setDecimal(null); return false; } if (selection.start >= 0 && selection.start < this.items.length) { var letter = String.fromCharCode(key); } if (key === 27) { this.setDecimal(this._savedValue); var position = this.GetSeparatorPositionInText(this.decimalSeparator, this.numberInput.val()); if (position != -1) { this._setSelectionStart(position); } e.preventDefault(); } if (this.rtl && key == 37) { var shift = e.shiftKey; var offset = shift ? 1 : 0; if (shift) { this._setSelection(selection.start + 1 - offset, selection.start + selection.length + 1); } else { this._setSelection(selection.start + 1 - offset, selection.start + 1); } return false; } else if (this.rtl && key == 39) { var shift = e.shiftKey; var offset = shift ? 1 : 0; if (shift) { this._setSelection(selection.start - 1, selection.length + offset + selection.start - 1); } else { this._setSelection(selection.start - 1, selection.start - 1); } return false; } // handle backspace. if (key == 8) { this.Backspace(); return false; } if (key == 190 || key == 110) { var position = this.GetSeparatorPositionInText(this.decimalSeparator, this.numberInput.val()); if (position != -1) { this._setSelectionStart(position + 1); } return false; } if (key == 188) { var value = this.numberInput.val(); for (i = selection.start; i < value.length; i++) { if (value[i] == this.groupSeparator) { this._setSelectionStart(1 + i); break; } } return false; } // allow Ctrl+C (copy) var ctrlKey = e.ctrlKey || e.metaKey; if ((ctrlKey && key == 99 /* firefox */) || (ctrlKey && key == 67) /* opera */) { var selection = this._selection(); var text = ""; var input = this.numberInput.val(); if (selection.start > 0 || selection.length > 0) { for (var i = selection.start; i < selection.end; i++) { text += input.substring(i, i + 1); } } $.data(document.body, "jqxSelection", text); if ($.jqx.browser.msie) { window.clipboardData.setData("Text", text); } else { var me = this; var copyFrom = $('