]> source.dussan.org Git - jquery-ui.git/commitdiff
Spinner: Use a polynomial instead of hard-coded blocks for incremental stepping.
authorScott González <scott.gonzalez@gmail.com>
Sun, 7 Aug 2011 23:21:23 +0000 (19:21 -0400)
committerScott González <scott.gonzalez@gmail.com>
Sun, 7 Aug 2011 23:21:23 +0000 (19:21 -0400)
ui/jquery.ui.spinner.js

index b36bdd9fded7f1161e3e5aa430715d99dd36d731..fecaa9b05e270f429ec854980eb638fea58ece98 100644 (file)
@@ -239,16 +239,7 @@ $.widget( "ui.spinner", {
                        this.counter = 1;
                }
 
-               // TODO refactor, maybe figure out some non-linear math
-               // x*x*x/50000 - x*x/500 + 17*x/200 + 1
-               var newVal = this.value() + step * (this.options.incremental &&
-                       this.counter > 20
-                               ? this.counter > 100
-                                       ? this.counter > 200
-                                               ? 100
-                                               : 10
-                                       : 2
-                               : 1);
+               var newVal = this.value() + step * this._increment( this.counter );
 
                // clamp the new value 
                newVal = this._trimValue( newVal );
@@ -259,6 +250,12 @@ $.widget( "ui.spinner", {
                }
        },
 
+       _increment: function( i ) {
+               return this.options.incremental ?
+                       Math.floor( i*i*i/50000 - i*i/500 + 17*i/200 + 1 ) :
+                       1;
+       },
+
        _trimValue: function( value ) {
                var options = this.options;