r2942 - spinner: added _validChars method

r2942 - spinner: added _validChars method


Author: pazu2k@gmail.com
Date: Sun Jul 19 07:33:18 2009
New Revision: 2942
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
spinner: added _validChars method
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 07:33:18 2009
@@ -20,30 +20,12 @@
$.widget('ui.spinner', {
    _init: function() {
        var self = this,
-            options = self.options,
-            validChars;
+            options = self.options;
        
        // initialize variables
        // _curDelay can't be initialized as part of the prototype because all
widgets would share the same object
        self.currentDelay = {};
-        self.focused = false;
-        self.hovered = false;
        
-        // Create list of valid characters used to build regexs
-        validChars = '\\-\\' + options.radixPoint;
-        if (options.groupSeparator) {
-            validChars += '\\' + options.groupSeparator;
-        }
-        if (options.radix < 10) {
-            validChars += '0-' + options.radix;
-        } else {
-            validChars += '0-9';
-            if (options.radix > 10) {
-                validChars += 'a-' + String.fromCharCode('a'.charCodeAt(0) +
options.radix - 11);
-            }
-        }
-        self.validChars = validChars;
-
        // parse min, max, step, and page based on radix
        // 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},
@@ -86,7 +68,16 @@
            self.disable();
        }
    },
-    
+    _validChars: function() {
+        var radix = parseInt(this.options.radix);
+        return '\\-\\' + this.options.radixPoint + (this.options.groupSeparator
+            ? '\\' + this.options.groupSeparator
+            :'') + (radix < 10
+                ? '0-' + radix
+                : '0-9' + (radix > 10
+                    ? 'a-' + String.fromCharCode('a'.charCodeAt(0) + radix - 11)
+                    :''));
+    },
    _draw: function() {
        var self = this,
            options = self.options,
@@ -316,7 +307,7 @@
            event.keyCode == KEYS.LEFT || event.keyCode == KEYS.RIGHT ||
event.keyCode == KEYS.PERIOD ||
            event.keyCode == KEYS.NUMPAD_DECIMAL || event.keyCode ==
KEYS.NUMPAD_SUBTRACT ||
            (event.keyCode >= 96 && event.keyCode <= 105) || // add support for
numeric keypad 0-9
-            (new RegExp('[' + this.validChars
+ ']', 'i').test(String.fromCharCode(event.keyCode)))) ? true : false;
+            (new RegExp('[' + this._validChars()
+ ']', 'i').test(String.fromCharCode(event.keyCode)))) ? true : false;
    },
    _mousewheel: function(event, delta) {
        // this = element, not widget, in event call
@@ -339,7 +330,7 @@
                val = val.replace(this.options.groupSeparator, '');
            }
    
-            val = val.replace(new RegExp('[^' + this.validChars
+ ']', 'gi'), '').split(this.options.radixPoint);
+            val = val.replace(new RegExp('[^' + this._validChars()
+ ']', 'gi'), '').split(this.options.radixPoint);
            
            result = parseInt(val[0], this.options.radix);
            if (val.length > 1) {