]> source.dussan.org Git - jquery-ui.git/commitdiff
Slider: More codecleanup. Inlining defaults for min/max, removing page (use 10*step...
authorjzaefferer <joern.zaefferer@gmail.com>
Mon, 25 Oct 2010 16:06:26 +0000 (18:06 +0200)
committerjzaefferer <joern.zaefferer@gmail.com>
Mon, 25 Oct 2010 16:06:26 +0000 (18:06 +0200)
ui/jquery.ui.spinner.js

index 70dd7adac8f6e769cef43d439a07b0fc758335b4..022e7f7dae2e9b530cb81e379d839b02255e7a79 100644 (file)
 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
@@ -114,7 +112,7 @@ $.widget('ui.spinner', {
                        })\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
@@ -140,7 +138,7 @@ $.widget('ui.spinner', {
                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
@@ -202,7 +200,7 @@ $.widget('ui.spinner', {
                        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
@@ -210,24 +208,16 @@ $.widget('ui.spinner', {
 \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
@@ -237,26 +227,26 @@ $.widget('ui.spinner', {
                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
@@ -277,11 +267,11 @@ $.widget('ui.spinner', {
        _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
@@ -307,8 +297,8 @@ $.widget('ui.spinner', {
        },\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
@@ -329,31 +319,6 @@ $.widget('ui.spinner', {
        _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
@@ -388,11 +353,11 @@ $.widget('ui.spinner', {
                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