r2943 - spinner: null checks in _contrain to !== and refactored _keydown to switch statement.
Author: pazu2k@gmail.com
Date: Sun Jul 19 08:24:39 2009
New Revision: 2943
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
spinner: null checks in _contrain to !== and refactored _keydown to switch
statement.
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 08:24:39 2009
@@ -217,10 +217,10 @@
self.widget = widget;
},
_constrain: function() {
- if (this.options.min != null && this._getValue() < this.options.min) {
+ if (this.options.min !== null && this._getValue() < this.options.min) {
this._setValue(this.options.min);
}
- if (this.options.max != null && this._getValue() > this.options.max) {
+ if (this.options.max !== null && this._getValue() > this.options.max) {
this._setValue(this.options.max);
}
},
@@ -283,31 +283,31 @@
jump = o.page * o.step;
KEYS = $.ui.keyCode;
- if (event.keyCode == KEYS.UP) {
- this._spin(event.shiftKey ? jump : o.step, event);
- }
- if (event.keyCode == KEYS.DOWN) {
- this._spin(event.shiftKey ? -jump : -o.step, event);
- }
- if (event.keyCode == KEYS.PAGE_UP) {
- this._spin(jump, event);
+ switch (event.keyCode) {
+ case KEYS.UP: this._spin(event.shiftKey ? jump : o.step, event);
break;
+ case KEYS.DOWN: this._spin(event.shiftKey ? -jump : -o.step, event);
break;
+ case KEYS.PAGE_UP: this._spin(jump, event); break;
+ case KEYS.PAGE_DOWN: this._spin(-jump, event); break;
+ case KEYS.HOME: this._setValue(o.min); break;
+ case KEYS.END: this._setValue(o.max); break;
+
+ case KEYS.TAB:
+ case KEYS.BACKSPACE:
+ case KEYS.LEFT:
+ case KEYS.RIGHT:
+ case KEYS.PERIOD:
+ case KEYS.NUMPAD_DECIMAL:
+ case KEYS.NUMPAD_SUBTRACT:
+ return true;
+
+ default:
+ if ((event.keyCode >= 96 && event.keyCode <= 105) || // numeric keypad
0-9
+ (new RegExp('[' + this._validChars()
+ ']', 'i').test(String.fromCharCode(event.keyCode)))) {
+ return true;
+ };
}
- if (event.keyCode == KEYS.PAGE_DOWN) {
- this._spin(-jump, event);
- }
- if (event.keyCode == KEYS.HOME) {
- //Home key goes to min
- this._setValue(o.min);
- }
- if (event.keyCode == KEYS.END && o.max != null) {
- //End key goes to maximum
- this._setValue(o.max);
- }
- return (event.keyCode == KEYS.TAB || event.keyCode == KEYS.BACKSPACE ||
- 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;
+
+ return false;
},
_mousewheel: function(event, delta) {
// this = element, not widget, in event call
@@ -343,7 +343,6 @@
return isNaN(val) ? null : val;
},
_getValue: function() {
- //return this._parseValue(this.element.val(), this.options.radix,
this.options.groupSeparator, this.options.radixPoint);
return this._parse(this.element.val());
},
_setValue: function(newVal) {