r2986 commited - spinner: renamed padLength to padding; removed keypress event in favou...
Revision: 2986
Author: pazu2k@gmail.com
Date: Sun Jul 26 16:59:57 2009
Log: spinner: renamed padLength to padding; removed keypress event in
favour of keydown; renamed _mousedown to _repeat because both mousedown and
keydown events share this function.
http://code.google.com/p/jquery-ui/source/detail?r=2986
Modified:
/branches/dev/spinner/ui/ui.spinner.js
=======================================
--- /branches/dev/spinner/ui/ui.spinner.js Sun Jul 26 14:47:10 2009
+++ /branches/dev/spinner/ui/ui.spinner.js Sun Jul 26 16:59:57 2009
@@ -24,7 +24,7 @@
this._initOptions();
this._value(this._value() || this.options.value);
-
+
this._draw();
this._mousewheel();
@@ -114,8 +114,6 @@
})
.bind('keydown'+namespace, function(event) {
self._start(event);
- })
- .bind('keypress'+namespace, function(event) {
return self._keydown(event);
})
.bind('keyup'+namespace, function(event) {
@@ -150,15 +148,13 @@
// button bindings
this.buttons = widget.find('.ui-spinner-button')
- .bind('mousedown', function(event) {
+ .bind('mousedown', function(event) {
self._start(event);
- self._mousedown(100, $(this).hasClass('ui-spinner-up') ? 1 : -1,
event);
-
- if (!self.options.disabled) {
+ self._repeat(null, $(this).hasClass('ui-spinner-up') ? 1 : -1, event);
+
+ if (!self.options.disabled && !self.options.readOnly) {
$(this).addClass(active);
- if (!options.readOnly) {
- widget.addClass(active);
- }
+ widget.addClass(active);
}
})
.bind('mouseup', function(event) {
@@ -182,7 +178,7 @@
}
})
.hover(function() {
- if (!self.options.disabled) {
+ if (!self.options.disabled && !self.options.readOnly) {
$(this).addClass(hover);
}
}, function(event) {
@@ -220,7 +216,7 @@
this._constrain();
},
_start: function(event) {
- if (!self.spinning) {
+ if (!this.spinning && !this.options.readOnly) {
if (!this.counter) {
this.counter = 1;
}
@@ -231,7 +227,7 @@
}
},
_spin: function(step, event) {
- if (this.options.disabled) {
+ if (this.options.disabled || this.options.readOnly) {
return;
}
if (!this.counter) {
@@ -261,29 +257,32 @@
_change: function(event) {
this._trigger('change', event, { value: this.value() });
},
- _mousedown: function(i, d, event) {
+ _repeat: function(i, steps, event) {
var self = this;
i = i || 100;
if (this.timer) {
window.clearInterval(this.timer);
}
this.timer = window.setInterval(function() {
- self._spin(d*self.options.step, event);
+ self._spin(steps*self.options.step, event);
if (self.options.incremental && self.counter > 20) {
- self._mousedown(20, d, event);
+ self._repeat(20, steps, event);
}
}, i);
+ if (event.originalEvent && event.originalEvent.type === 'keydown') {
+ this._spin(steps*this.options.step, event);
+ }
},
_keydown: function(event) {
var o = this.options,
- jump = o.page * o.step,
KEYS = $.ui.keyCode;
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.UP: this._repeat(null, event.shiftKey ? o.page : 1,
event); break;
+ case KEYS.DOWN: this._repeat(null, event.shiftKey ? -o.page : -1,
event); break;
+ case KEYS.PAGE_UP: this._repeat(null, o.page, event); break;
+ case KEYS.PAGE_DOWN: this._repeat(null, -o.page, event); break;
+
case KEYS.HOME: this._value(o.min); break;
case KEYS.END: this._value(o.max); break;
@@ -297,9 +296,8 @@
return true;
default:
- var code = event.keyCode || event.charCode;
if ((event.keyCode >= 96 && event.keyCode <= 105) || // numeric keypad
0-9
- (new RegExp('[' + this._validChars()
+ ']', 'i').test(String.fromCharCode(code)))) {
+ (new RegExp('[' + this._validChars()
+ ']', 'i').test(String.fromCharCode(event.keyCode)))) {
return true;
};
}
@@ -402,7 +400,7 @@
);
result = num.replace('-','');
- while (options.padLength && (result.length < options.padLength)) {
+ while (options.padding && (result.length < options.padding)) {
result = '0' + result;
}
@@ -499,7 +497,7 @@
max: null,
min: null,
mouseWheel: true,
- padLength: 0,
+ padding: 0,
page: 5,
precision: 0,
radix: 10,