Skip to content

Commit 8c5a6f7

Browse files
committed
Spinner: Use a polynomial instead of hard-coded blocks for incremental stepping.
1 parent 2a8a77a commit 8c5a6f7

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

ui/jquery.ui.spinner.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,7 @@ $.widget( "ui.spinner", {
239239
this.counter = 1;
240240
}
241241

242-
// TODO refactor, maybe figure out some non-linear math
243-
// x*x*x/50000 - x*x/500 + 17*x/200 + 1
244-
var newVal = this.value() + step * (this.options.incremental &&
245-
this.counter > 20
246-
? this.counter > 100
247-
? this.counter > 200
248-
? 100
249-
: 10
250-
: 2
251-
: 1);
242+
var newVal = this.value() + step * this._increment( this.counter );
252243

253244
// clamp the new value
254245
newVal = this._trimValue( newVal );
@@ -259,6 +250,12 @@ $.widget( "ui.spinner", {
259250
}
260251
},
261252

253+
_increment: function( i ) {
254+
return this.options.incremental ?
255+
Math.floor( i*i*i/50000 - i*i/500 + 17*i/200 + 1 ) :
256+
1;
257+
},
258+
262259
_trimValue: function( value ) {
263260
var options = this.options;
264261

0 commit comments

Comments
 (0)