r2925 - spinner: code cleanup - removed ui method and passing a ui hash instead; removed init cal...
Author: pazu2k@gmail.com
Date: Thu Jul 16 00:03:15 2009
New Revision: 2925
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
spinner: code cleanup - removed ui method and passing a ui hash instead;
removed init callback; added a widget property representing the spinner
container; removed return this from enable/disable/value methods.
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 00:03:15 2009
@@ -29,8 +29,6 @@
}
return isNaN(val) ? null : val;
}
-
- self._trigger('init', null, self.ui(null));
// initialize variables
// _curDelay can't be initialized as part of the prototype because all
widgets would share the same object
@@ -69,7 +67,7 @@
? options.readOnly
: self.element.attr('readonly');
- // check for precision in steppinng and set _precision as internal
+ // check for precision in stepping and set _precision as internal
self._precision = parseInt(options.precision, 10);
if (options.step.toString().indexOf('.') != -1 && self._precision === 0)
{
var s = options.step.toString();
@@ -79,10 +77,10 @@
self._setValue( isNaN(self._getValue()) ? options.value :
self._getValue() );
// draw widget
- var widget = self._draw();
+ self.widget = self._draw();
// add behaviours
- widget
+ self.widget
.hover(function() {
if (!options.readOnly && !self.disabled) {
$(this).addClass(hover);
@@ -99,7 +97,7 @@
}
});
- self.buttons = widget.find('.ui-spinner-button')
+ self.buttons = self.widget.find('.ui-spinner-button')
.bind('mousedown', function(event) {
if (!self.counter) {
self.counter = 1;
@@ -109,7 +107,7 @@
if (!self.disabled) {
$(this).addClass(active);
if (!options.readOnly) {
- widget.addClass(active);
+ self.widget.addClass(active);
}
}
})
@@ -153,14 +151,14 @@
})
.bind('keyup'+namespace, function(event) {
self.counter = 0;
- self._trigger('change', event, self.ui());
+ self._trigger('change', event, { value: self._getValue() });
})
.bind('focus'+namespace, function() {
if (options.readOnly) {
self.element.blur();
return false;
}
- widget.addClass(active);
+ self.widget.addClass(active);
self.focused = true;
if (!self.hovered && typeof options.hide != 'boolean'
&& !self.disabled) {
self._delay(self._show, 100, 'hide', options.hide);
@@ -168,7 +166,7 @@
})
.bind('blur'+namespace, function(event) {
if (!self.hovered) {
- widget.removeClass(active);
+ self.widget.removeClass(active);
}
self.focused = false;
if (!self.hovered && typeof options.hide != 'boolean') {
@@ -185,9 +183,6 @@
if (self.element.attr("disabled")) {
self.disable();
}
-
- // TODO: decide whether this is the best way to extend init
- //self._extend('initComplete');
},
_draw: function() {
@@ -250,7 +245,8 @@
if (this.disabled) {
return;
}
- this._trigger('start', event, this.ui());
+
+ this._trigger('start', event, { value: this._getValue() });
var value = this._getValue();
@@ -263,8 +259,8 @@
this.counter++;
}
- this._trigger('spin', event, this.ui());
- this._trigger('stop', event, this.ui());
+ this._trigger('spin', event, { value: this.value() });
+ this._trigger('stop', event, { value: this.value() });
},
_down: function(step, event) {
this._spin('down', step, event);
@@ -293,7 +289,7 @@
this.timer = 0;
}
this.element[0].focus();
- this._trigger('change', event, this.ui());
+ this._trigger('change', event, { value: this.value() });
},
_keydown: function(event) {
var o = this.options,
@@ -337,7 +333,7 @@
window.clearTimeout(self.timeout);
self.timeout = 0;
}
- self.timeout = window.setTimeout(function(){self._trigger('change',
event, self.ui());}, 400);
+ self.timeout = window.setTimeout(function(){self._trigger('change',
event, { value: self.value() });}, 400);
event.preventDefault();
},
_parseValue: function(val, radix, groupSeparator, radixPoint) {
@@ -369,7 +365,7 @@
$.ui.spinner.format.currency(newVal, this.options.currency,
this.options.groupSeparator, this.options.radixPoint) :
$.ui.spinner.format.number(newVal, this._precision,
this.options.radix, this.options.groupSeparator, this.options.radixPoint,
this.options.padLength)
);
- this.element.parents('.' + this.widgetBaseClass
+ ':first').attr('aria-valuenow', this._getValue());
+ this.element.parents('.' + this.widgetBaseClass
+ ':first').attr('aria-valuenow', this.value());
},
// delays a function call, allowing only one at a time of the same type
@@ -441,28 +437,21 @@
$.widget.prototype._setData.call(this, key, value);
},
- ui: function(event) {
- return {
- options: this.options,
- element: this.element,
- value: this._getValue()
- };
- },
destroy: function() {
if ($.fn.mousewheel) {
this.element.unmousewheel();
}
+
this.element
.removeClass('ui-spinner-box')
.removeAttr('disabled')
.removeAttr('autocomplete')
.removeData('spinner')
- .unbind(namespace)
- .siblings()
- .remove()
- .end()
- .parent()
- .replaceWith(this.element);
+ .unbind(namespace);
+
+ if (this.widget) {
+ this.widget.replaceWith(this.element);
+ }
},
enable: function() {
this.element
@@ -472,7 +461,6 @@
.parent()
.removeClass('ui-state-disabled');
this.disabled = false;
- return this;
},
disable: function() {
this.element
@@ -482,7 +470,6 @@
.parent()
.addClass('ui-state-disabled');
this.disabled = true;
- return this;
},
value: function(newVal) {
if (!arguments.length) {
@@ -490,7 +477,6 @@
}
this._setValue(newVal);
- return this;
},
stepUp: function(steps) {
this._up((steps || 1) * this.options.step, null);