r2572 - Corrected value getter/setter implementation. Changed mousewheel implementation so that ...
Author: btburnett3
Date: Thu May 14 21:34:04 2009
New Revision: 2572
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
Corrected value getter/setter implementation. Changed mousewheel
implementation so that event can be bound/unbound during _setData.
Modified: branches/dev/spinner/ui/ui.spinner.js
==============================================================================
--- branches/dev/spinner/ui/ui.spinner.js (original)
+++ branches/dev/spinner/ui/ui.spinner.js Thu May 14 21:34:04 2009
@@ -196,9 +196,7 @@
});
if ($.fn.mousewheel) {
- this.element.mousewheel(function(event, delta) {
- self._mousewheel(event, delta);
- });
+ this.element.mousewheel(self._mousewheel);
}
},
@@ -285,18 +283,18 @@
(/[0-9\-\.]/).test(String.fromCharCode(event.keyCode))) ? true : false;
},
_mousewheel: function(event, delta) {
- var self = this;
+ // this = element, not widget, in event call
+ // we must use a function that is a member of the widget for
binding/unbinding the event on option changes
+ var self = $.data(this, 'spinner');
- if (self.options.mouseWheel) {
- delta = ($.browser.opera ? -delta / Math.abs(delta) : delta);
- (delta > 0 ? self._up(event) : self._down(event));
- if (self.timeout) {
- window.clearTimeout(self.timeout);
- self.timeout = 0;
- }
- self.timeout = window.setTimeout(function(){self._trigger('change',
event);}, 400);
- event.preventDefault();
+ delta = ($.browser.opera ? -delta / Math.abs(delta) : delta);
+ (delta > 0 ? self._up(event) : self._down(event));
+ if (self.timeout) {
+ window.clearTimeout(self.timeout);
+ self.timeout = 0;
}
+ self.timeout = window.setTimeout(function(){self._trigger('change',
event);}, 400);
+ event.preventDefault();
},
_getValue: function() {
var val = this.element.val().replace(this.options.point, '.');
@@ -351,6 +349,12 @@
this.element.append('<'+ wrapper +' class="ui-spinner-dyn">'+ html
+ '</'+ wrapper +'>');
}
},
+ _setData: function(key, value) {
+ if ((key == 'mouseWheel') && (value != this.options.mouseWheel) &&
$.fn.mousewheel)
+ this.element[value ? 'mousewheel' : 'unmousewheel'](this._mousewheel);
+
+ $.widget.prototype._setData.call(this, key, value);
+ },
plugins: {},
ui: function(event) {
@@ -410,15 +414,16 @@
this.disabled = true;
},
value: function(newVal) {
- if (arguments.length)
- this._setValue(newVal);
- return this._getValue();
+ if (!arguments.length)
+ return this._getValue();
+
+ this._setValue(newVal);
+ return this;
}
});
$.extend($.ui.spinner, {
version: "@VERSION",
- getter: 'value',
defaults: {
decimals: 0,
stepping: 1,