r2929 - spinner: tidied up callback triggering
Author: pazu2k@gmail.com
Date: Thu Jul 16 01:59:28 2009
New Revision: 2929
Modified:
branches/dev/spinner/tests/visual/spinner/spinner.html
branches/dev/spinner/ui/ui.spinner.js
Log:
spinner: tidied up callback triggering
Modified: branches/dev/spinner/tests/visual/spinner/spinner.html
==============================================================================
--- branches/dev/spinner/tests/visual/spinner/spinner.html (original)
+++ branches/dev/spinner/tests/visual/spinner/spinner.html Thu Jul 16
01:59:28 2009
@@ -19,18 +19,22 @@
start: function(event, ui) {
console.log('start');
console.log(ui);
+ console.log(event.originalEvent);
},
spin: function(event, ui) {
console.log('spin');
console.log(ui);
+ console.log(event.originalEvent);
},
stop: function(event, ui) {
console.log('stop');
console.log(ui);
+ console.log(event.originalEvent);
},
change: function(event, ui) {
console.log('change');
console.log(ui);
+ console.log(event.originalEvent);
}
});
// hook via bind
Modified: branches/dev/spinner/ui/ui.spinner.js
==============================================================================
--- branches/dev/spinner/ui/ui.spinner.js (original)
+++ branches/dev/spinner/ui/ui.spinner.js Thu Jul 16 01:59:28 2009
@@ -156,9 +156,7 @@
self.buttons = widget.find('.ui-spinner-button')
.bind('mousedown', function(event) {
- if (!self.counter) {
- self.counter = 1;
- }
+ self._start(event);
self._mousedown(100, $(this).hasClass('ui-spinner-up') ? 1 : -1,
event);
if (!self.disabled) {
@@ -172,16 +170,20 @@
if (self.counter == 1) {
self._spin(($(this).hasClass('ui-spinner-up') ? 1 : -1) *
options.step, event);
}
- self._mouseup(event);
+ self._stop(event);
$(this).removeClass(active);
})
+ .bind('click', function(event) {
+ self._change(event);
+ })
// mousedown/mouseup capture first click, now handle second click
.bind('dblclick', function(event) {
if ($.browser.msie) {
$(this).removeClass(active);
self._spin(($(this).hasClass('ui-spinner-up') ? 1 : -1) *
options.step, event);
- self._mouseup(event);
+ self._stop(event);
+ self._change(event);
}
})
.hover(function() {
@@ -191,20 +193,20 @@
}, function(event) {
$(this).removeClass(active + ' ' + hover);
if (self.timer) {
- self._mouseup(event);
+ self._stop(event);
}
});
self.element
.bind('keydown'+namespace, function(event) {
- if (!self.counter) {
- self.counter = 1;
- }
+ self._start(event);
+ })
+ .bind('keypress'+namespace, function(event) {
return self._keydown.call(self, event);
})
.bind('keyup'+namespace, function(event) {
- self.counter = 0;
- self._trigger('change', event, { value: self._getValue() });
+ self._stop(event);
+ self._change(event);
})
.bind('focus'+namespace, function() {
if (options.readOnly) {
@@ -242,13 +244,17 @@
this._setValue(this._getValue());
this._constrain();
},
+ _start: function(event) {
+ if (!this.counter) {
+ this.counter = 1;
+ }
+ this._trigger('start', event, { value: this.value() });
+ },
_spin: function(step, event) {
if (this.disabled) {
return;
}
-
- this._trigger('start', event, { value: this.value() });
-
+
var value = this._getValue();
if (isNaN(value)) {
@@ -261,8 +267,19 @@
}
this._trigger('spin', event, { value: this.value() });
+ },
+ _stop: function(event) {
+ this.counter = 0;
+ if (this.timer) {
+ window.clearInterval(this.timer);
+ this.timer = 0;
+ }
+ this.element[0].focus();
this._trigger('stop', event, { value: this.value() });
},
+ _change: function(event) {
+ this._trigger('change', event, { value: this.value() });
+ },
_mousedown: function(i, d, event) {
var self = this;
i = i || 100;
@@ -277,15 +294,6 @@
}
}, i);
},
- _mouseup: function(event) {
- this.counter = 0;
- if (this.timer) {
- window.clearInterval(this.timer);
- this.timer = 0;
- }
- this.element[0].focus();
- this._trigger('change', event, { value: this.value() });
- },
_keydown: function(event) {
var o = this.options,
jump = o.page * o.step;
@@ -328,7 +336,7 @@
window.clearTimeout(self.timeout);
self.timeout = 0;
}
- self.timeout = window.setTimeout(function(){self._trigger('change',
event, { value: self.value() });}, 400);
+ self.timeout = window.setTimeout(function(){self._change(event);}, 400);
event.preventDefault();
},
_parseValue: function(val, radix, groupSeparator, radixPoint) {