var hover = 'ui-state-hover',\r
active = 'ui-state-active',\r
namespace = '.spinner',\r
- uiSpinnerClasses = 'ui-spinner ui-state-default ui-widget ui-widget-content ui-corner-all ';\r
+ pageModifier = 10;\r
\r
$.widget('ui.spinner', {\r
options: {\r
dir: 'ltr',\r
incremental: true,\r
- max: null,\r
- min: null,\r
- mouseWheel: true,\r
+ max: Number.MAX_VALUE,\r
+ min: -Number.MAX_VALUE,\r
numberformat: "n",\r
- page: 5,\r
- step: null,\r
+ step: 1,\r
value: null\r
},\r
\r
})\r
.bind('mouseup', function(event) {\r
if (self.counter == 1) {\r
- self._spin(($(this).hasClass('ui-spinner-up') ? 1 : -1) * self._step(), event);\r
+ self._spin(($(this).hasClass('ui-spinner-up') ? 1 : -1) * self.options.step, event);\r
}\r
if (self.spinning) {\r
self._stop(event);\r
self.uiSpinner = uiSpinner;\r
},\r
_uiSpinnerHtml: function() {\r
- return '<div role="spinbutton" class="ui-spinner-' + this.options.dir + '"></div>';\r
+ return '<div role="spinbutton" class="ui-spinner ui-state-default ui-widget ui-widget-content ui-corner-all ui-spinner-' + this.options.dir + '"></div>';\r
},\r
_buttonHtml: function() {\r
return '<a class="ui-spinner-button ui-spinner-up ui-corner-t' + this.options.dir.substr(-1,1) + \r
self._repeat(self.options.incremental && self.counter > 20 ? 20 : i, steps, event);\r
}, i);\r
\r
- self._spin(steps*self._step(), event);\r
+ self._spin(steps*self.options.step, event);\r
},\r
_keydown: function(event) {\r
var o = this.options,\r
\r
switch (event.keyCode) {\r
case KEYS.UP:\r
- this._repeat(null, event.shiftKey ? o.page : 1, event);\r
+ this._repeat(null, 1, event);\r
return false;\r
case KEYS.DOWN:\r
- this._repeat(null, event.shiftKey ? -o.page : -1, event);\r
+ this._repeat(null, -1, event);\r
return false;\r
case KEYS.PAGE_UP:\r
- this._repeat(null, o.page, event);\r
+ this._repeat(null, pageModifier, event);\r
return false;\r
case KEYS.PAGE_DOWN:\r
- this._repeat(null, -o.page, event);\r
- return false;\r
- \r
- case KEYS.HOME:\r
- case KEYS.END:\r
- if (event.shiftKey) {\r
- return true;\r
- }\r
- this.value(this['_' + (event.keyCode == KEYS.HOME ? 'min' : 'max')]());\r
+ this._repeat(null, -pageModifier, event);\r
return false;\r
\r
case KEYS.ENTER:\r
return true;\r
},\r
_mousewheel: function() {\r
+ if (!$.fn.mousewheel)\r
+ return;\r
var self = this;\r
- if ($.fn.mousewheel && self.options.mouseWheel) {\r
- this.element.mousewheel(function(event, delta) {\r
- delta = ($.browser.opera ? -delta / Math.abs(delta) : delta);\r
- if (!self._start(event)) {\r
- return false;\r
- }\r
- self._spin((delta > 0 ? 1 : -1) * self._step(), event); \r
- if (self.timeout) {\r
- window.clearTimeout(self.timeout);\r
+ this.element.mousewheel(function(event, delta) {\r
+ delta = ($.browser.opera ? -delta / Math.abs(delta) : delta);\r
+ if (!self._start(event)) {\r
+ return false;\r
+ }\r
+ self._spin((delta > 0 ? 1 : -1) * self.options.step, event);\r
+ if (self.timeout) {\r
+ window.clearTimeout(self.timeout);\r
+ }\r
+ self.timeout = window.setTimeout(function() {\r
+ if (self.spinning) {\r
+ self._stop(event);\r
+ self._change(event);\r
}\r
- self.timeout = window.setTimeout(function() {\r
- if (self.spinning) {\r
- self._stop(event);\r
- self._change(event); \r
- }\r
- }, 400);\r
- event.preventDefault(); \r
- }); \r
- }\r
+ }, 400);\r
+ event.preventDefault();\r
+ });\r
},\r
value: function(newVal) {\r
if (!arguments.length) {\r
_setOption: function(key, value) {\r
if (key == 'value') {\r
value = this._parse(value);\r
- if (value < this._min()) {\r
- value = this._min();\r
+ if (value < this.options.min) {\r
+ value = this.options.min;\r
}\r
- if (value > this._max()) {\r
- value = this._max();\r
+ if (value > this.options.max) {\r
+ value = this.options.max;\r
}\r
} \r
$.Widget.prototype._setOption.call( this, key, value );\r
},\r
_aria: function() {\r
this.uiSpinner\r
- .attr('aria-valuemin', this._min())\r
- .attr('aria-valuemax', this._max())\r
+ .attr('aria-valuemin', this.options.min)\r
+ .attr('aria-valuemax', this.options.max)\r
.attr('aria-valuenow', this.value());\r
},\r
\r
_format: function(num) {\r
this.element.val( window.Globalization ? Globalization.format(num, this.options.numberformat) : num );\r
},\r
- _getOption: function(key, defaultValue) {\r
- return this._parse(this.options[key] !== null\r
- ? this.options[key]\r
- : this.element.attr(key)\r
- ? this.element.attr(key)\r
- : defaultValue);\r
- },\r
- _step: function(newVal) {\r
- if (!arguments.length) {\r
- return this._getOption('step', 1);\r
- }\r
- this._setOption('step', newVal);\r
- },\r
- _min: function(newVal) {\r
- if (!arguments.length) {\r
- return this._getOption('min', -Number.MAX_VALUE);\r
- }\r
- this._setOption('min', newVal);\r
- },\r
- _max: function(newVal) {\r
- if (!arguments.length) {\r
- return this._getOption('max', Number.MAX_VALUE);\r
- }\r
- this._setOption('max', newVal);\r
- },\r
\r
destroy: function() {\r
if ($.fn.mousewheel) {\r
this.options.disabled = true;\r
},\r
stepUp: function(steps) {\r
- this._spin((steps || 1) * this._step(), null);\r
+ this._spin((steps || 1) * this.options.step, null);\r
return this;\r
},\r
stepDown: function(steps) {\r
- this._spin((steps || 1) * -this._step(), null); \r
+ this._spin((steps || 1) * -this.options.step, null); \r
return this;\r
},\r
pageUp: function(pages) {\r