r2674 - Spinner: added options var to _init.
Author: scott.gonzalez
Date: Sun Jun 7 17:41:59 2009
New Revision: 2674
Modified:
branches/dev/spinner/ui/ui.spinner.js
Log:
Spinner: added options var to _init.
Modified: branches/dev/spinner/ui/ui.spinner.js
==============================================================================
--- branches/dev/spinner/ui/ui.spinner.js (original)
+++ branches/dev/spinner/ui/ui.spinner.js Sun Jun 7 17:41:59 2009
@@ -20,6 +20,7 @@
$.widget('ui.spinner', {
_init: function() {
var self = this,
+ options = self.options,
validChars;
function parse(val, ifNull) {
@@ -27,7 +28,7 @@
val = ifNull;
}
if (typeof val == 'string') {
- val = self._parseValue(val, self.options.radix,
self.options.groupSeparator, self.options.radixPoint);
+ val = self._parseValue(val, options.radix, options.groupSeparator,
options.radixPoint);
}
return isNaN(val) ? null : val;
}
@@ -41,43 +42,43 @@
self.hovered = false;
// perform data bind on generic objects
- if (self.options.items != null && typeof self.options.items[0]
== 'object' && !self.element.is('input')) {
- var data = this.options.items;
+ if (options.items != null && typeof options.items[0] == 'object'
&& !self.element.is('input')) {
+ var data = options.items;
for (var i=0; i<data.length; i++) {
self._addItem(data[i]);
}
}
// Create list of valid characters used to build regexs
- validChars = '\\-\\' + self.options.radixPoint;
- if (self.options.groupSeparator) {
- validChars += '\\' + self.options.groupSeparator;
+ validChars = '\\-\\' + options.radixPoint;
+ if (options.groupSeparator) {
+ validChars += '\\' + options.groupSeparator;
}
- if (self.options.radix < 10) {
- validChars += '0-' + self.options.radix;
+ if (options.radix < 10) {
+ validChars += '0-' + options.radix;
} else {
validChars += '0-9';
- if (self.options.radix > 10) {
- validChars += 'a-' + String.fromCharCode('a'.charCodeAt(0) +
self.options.radix - 11);
+ if (options.radix > 10) {
+ validChars += 'a-' + String.fromCharCode('a'.charCodeAt(0) +
options.radix - 11);
}
}
self.validChars = validChars;
// Parse min, max, step, and page for strings based on radix, apply
HTML5 attributes if they are null
- self.options.max = parse(self.options.max, self.element.attr('max') ||
Number.MAX_VALUE);
- self.options.min = parse(self.options.min, self.element.attr('min') ||
-Number.MAX_VALUE);
- self.options.page = parse(self.options.page);
- self.options.readOnly = parse(self.options.readOnly,
self.element.attr('readonly'));
- self.options.step = parse(self.options.step, self.element.attr('step')) |
| 1;
+ options.max = parse(options.max, self.element.attr('max') ||
Number.MAX_VALUE);
+ options.min = parse(options.min, self.element.attr('min') ||
-Number.MAX_VALUE);
+ options.page = parse(options.page);
+ options.readOnly = parse(options.readOnly,
self.element.attr('readonly'));
+ options.step = parse(options.step, self.element.attr('step')) || 1;
// check for precision in steppinng and set _precision as internal
- self._precision = parseInt(self.options.precision, 10);
- if (self.options.step.toString().indexOf('.') != -1 && self._precision
=== 0) {
- var s = self.options.step.toString();
+ self._precision = parseInt(options.precision, 10);
+ if (options.step.toString().indexOf('.') != -1 && self._precision === 0)
{
+ var s = options.step.toString();
self._precision = s.slice(s.indexOf('.')+1, s.length).length;
}
- self._setValue( isNaN(self._getValue()) ? self.options.value :
self._getValue() );
+ self._setValue( isNaN(self._getValue()) ? options.value :
self._getValue() );
// draw widget
var widget = self._draw();
@@ -95,7 +96,7 @@
.bind('mouseup', function(event) {
$(this).removeClass(active);
if (self.counter == 1) {
- self._up(self.options.step, event);
+ self._up(options.step, event);
}
self._mouseup(event);
})
@@ -103,7 +104,7 @@
.bind('dblclick', function(event) {
if ($.browser.msie) {
$(this).removeClass(active);
- self._up(self.options.step, event);
+ self._up(options.step, event);
self._mouseup(event);
}
})
@@ -119,7 +120,7 @@
.bind('mouseup', function(event) {
$(this).removeClass(active);
if (self.counter == 1) {
- self._down(self.options.step, event);
+ self._down(options.step, event);
}
self._mouseup(event);
})
@@ -127,20 +128,20 @@
.bind('dblclick', function(event) {
if ($.browser.msie) {
$(this).removeClass(active);
- self._down(self.options.step, event);
+ self._down(options.step, event);
self._mouseup(event);
}
})
.end()
.hover(function() {
self.hovered = true;
- if (typeof self.options.hide != 'boolean' && !self.focused
&& !self.disabled) {
- self._delay(self._show, 100, 'hide', self.options.hide);
+ if (typeof options.hide != 'boolean' && !self.focused
&& !self.disabled) {
+ self._delay(self._show, 100, 'hide', options.hide);
}
}, function() {
self.hovered = false;
- if (typeof self.options.hide != 'boolean' && !self.focused) {
- self._delay(self._hide, 100, 'hide', self.options.hide);
+ if (typeof options.hide != 'boolean' && !self.focused) {
+ self._delay(self._hide, 100, 'hide', options.hide);
}
});
@@ -153,7 +154,7 @@
self._mouseup(event);
}
});
- if (self.options.hide) {
+ if (options.hide) {
self._hide();
}
@@ -163,7 +164,7 @@
if (self._items > 1) {
var margins = self.element.outerHeight(true) -
self.element.outerHeight();
var height = self.element.outerHeight()/self._items + margins*2;
- //var height = self.options.height;
+ //var height = options.height;
self.element
.addClass('ui-spinner-list')
.height(height)
@@ -175,9 +176,9 @@
.parent()
.height(height)
.end();
- self.options.step = 1;
- self.options.min = 0;
- self.options.max = self._items-1;
+ options.step = 1;
+ options.min = 0;
+ options.max = self._items-1;
}
self.element
@@ -192,25 +193,25 @@
self._trigger('change', event, self.ui());
})
.bind('focus'+namespace, function() {
- if (self.options.readOnly) {
+ if (options.readOnly) {
self.element.blur();
return false;
}
self.focused = true;
- if (!self.hovered && typeof self.options.hide != 'boolean'
&& !self.disabled) {
- self._delay(self._show, 100, 'hide', self.options.hide);
+ if (!self.hovered && typeof options.hide != 'boolean'
&& !self.disabled) {
+ self._delay(self._show, 100, 'hide', options.hide);
}
})
.bind('blur'+namespace, function(event) {
self.focused = false;
- if (!self.hovered && typeof self.options.hide != 'boolean') {
- self._delay(self._hide, 100, 'hide', self.options.hide);
+ if (!self.hovered && typeof options.hide != 'boolean') {
+ self._delay(self._hide, 100, 'hide', options.hide);
}
self._cleanUp();
});
- if ($.fn.mousewheel && self.options.mouseWheel) {
+ if ($.fn.mousewheel && options.mouseWheel) {
self.element.mousewheel(self._mousewheel);
}