r2940 - spinner: merged parse and _parseValue methods
Author: pazu2k@gmail.com
Date: Sun Jul 19 05:41:27 2009
New Revision: 2940
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
spinner: merged parse and _parseValue methods
Modified: branches/dev/spinner/ui/ui.spinner.js
==============================================================================
--- branches/dev/spinner/ui/ui.spinner.js (original)
+++ branches/dev/spinner/ui/ui.spinner.js Sun Jul 19 05:41:27 2009
@@ -22,13 +22,6 @@
var self = this,
options = self.options,
validChars;
-
- function parse(val) {
- if (typeof val == 'string') {
- val = self._parseValue(val, options.radix, options.groupSeparator,
options.radixPoint);
- }
- return isNaN(val) ? null : val;
- }
// initialize variables
// _curDelay can't be initialized as part of the prototype because all
widgets would share the same object
@@ -55,14 +48,14 @@
// min, max and step pull from attributes if the option is set to null
$.each({ min: -Number.MAX_VALUE, max: Number.MAX_VALUE, step: 1},
function(option, defaultValue) {
- options[option] = parse(options[option] !== null
+ options[option] = self._parse(options[option] !== null
? options[option]
: self.element.attr(option)
? self.element.attr(option)
: defaultValue);
});
- options.page = parse(options.page || 1);
+ options.page = self._parse(options.page || 1);
options.readOnly = options.readOnly !== null
? options.readOnly
@@ -339,25 +332,28 @@
self.timeout = window.setTimeout(function(){self._change(event);}, 400);
event.preventDefault();
},
- _parseValue: function(val, radix, groupSeparator, radixPoint) {
- // Because groupSeparator is included in the regex, we must replace it
independently
- if (groupSeparator) {
- val = val.replace(groupSeparator, '');
- }
-
- val = val.replace(new RegExp('[^' + this.validChars
+ ']', 'gi'), '').split(radixPoint);
-
- result = parseInt(val[0], radix);
- if (val.length > 1) {
- result += parseInt(val[1], radix) / Math.pow(radix, val[1].length) *
- // must test first character of val[0] for minus sign because -0 is
parsed as 0 in result
- (val[0][0] == '-' ? -1 : 1);
+ _parse: function(val) {
+ if (typeof val == 'string') {
+ // Because groupSeparator is included in the regex, we must replace it
independently
+ if (this.options.groupSeparator) {
+ val = val.replace(this.options.groupSeparator, '');
+ }
+
+ val = val.replace(new RegExp('[^' + this.validChars
+ ']', 'gi'), '').split(this.options.radixPoint);
+
+ result = parseInt(val[0], this.options.radix);
+ if (val.length > 1) {
+ result += parseInt(val[1], this.options.radix) /
Math.pow(this.options.radix, val[1].length) *
+ // must test first character of val[0] for minus sign because -0 is
parsed as 0 in result
+ (val[0][0] == '-' ? -1 : 1);
+ }
+ val = result;
}
-
- return result;
+ return isNaN(val) ? null : val;
},
_getValue: function() {
- return this._parseValue(this.element.val(), this.options.radix,
this.options.groupSeparator, this.options.radixPoint);
+ //return this._parseValue(this.element.val(), this.options.radix,
this.options.groupSeparator, this.options.radixPoint);
+ return this._parse(this.element.val());
},
_setValue: function(newVal) {
if (isNaN(newVal)) {