@@ -27,8 +27,14 @@ $.widget('ui.spinner', {
27
27
} ,
28
28
29
29
_create : function ( ) {
30
- // html5 attributes initalization
31
- // TODO refactor
30
+ this . _draw ( ) ;
31
+ this . _markupOptions ( ) ;
32
+ this . _mousewheel ( ) ;
33
+ this . _aria ( ) ;
34
+ } ,
35
+
36
+ _markupOptions : function ( ) {
37
+ // TODO refactor and read only when the related option is null (set default to null, init Number.MAX_VALUE only when nothing is specified)
32
38
var min = this . element . attr ( "min" ) ;
33
39
if ( typeof min == "string" && min . length > 0 ) {
34
40
this . options . min = this . _parse ( min ) ;
@@ -42,9 +48,6 @@ $.widget('ui.spinner', {
42
48
this . options . step = this . _parse ( step ) ;
43
49
}
44
50
this . value ( this . options . value !== null ? this . options . value : this . element . val ( ) || 0 ) ;
45
- this . _draw ( ) ;
46
- this . _mousewheel ( ) ;
47
- this . _aria ( ) ;
48
51
} ,
49
52
50
53
_draw : function ( ) {
@@ -69,7 +72,7 @@ $.widget('ui.spinner', {
69
72
self . hovered = false ;
70
73
} ) ;
71
74
72
- // TODO: need a better way to exclude IE8 without resorting to $.browser.version
75
+ // TODO: move to theme, ask FG how
73
76
// fix inline-block issues for IE. Since IE8 supports inline-block we need to exclude it.
74
77
if ( ! $ . support . opacity && uiSpinner . css ( 'display' ) == 'inline-block' && $ . browser . version < 8 ) {
75
78
uiSpinner . css ( 'display' , 'inline' ) ;
@@ -110,12 +113,7 @@ $.widget('ui.spinner', {
110
113
this . buttons = uiSpinner . find ( '.ui-spinner-button' )
111
114
. attr ( "tabIndex" , - 1 )
112
115
. button ( )
113
- . first ( )
114
- . removeClass ( "ui-corner-all" )
115
- . end ( )
116
- . last ( )
117
- . removeClass ( "ui-corner-all" )
118
- . end ( )
116
+ . removeClass ( "ui-corner-all" )
119
117
. bind ( 'mousedown' , function ( event ) {
120
118
if ( self . options . disabled ) {
121
119
return ;
@@ -129,9 +127,6 @@ $.widget('ui.spinner', {
129
127
if ( self . options . disabled ) {
130
128
return ;
131
129
}
132
- if ( self . counter == 1 ) {
133
- self . _spin ( ( $ ( this ) . hasClass ( 'ui-spinner-up' ) ? 1 : - 1 ) * self . options . step , event ) ;
134
- }
135
130
if ( self . spinning ) {
136
131
self . _stop ( event ) ;
137
132
self . _change ( event ) ;
@@ -150,7 +145,7 @@ $.widget('ui.spinner', {
150
145
}
151
146
} )
152
147
. bind ( "mouseleave" , function ( ) {
153
- if ( self . timer && self . spinning ) {
148
+ if ( self . spinning ) {
154
149
self . _stop ( event ) ;
155
150
self . _change ( event ) ;
156
151
}
@@ -197,11 +192,9 @@ $.widget('ui.spinner', {
197
192
return false ;
198
193
}
199
194
self . _spin ( ( delta > 0 ? 1 : - 1 ) * self . options . step , event ) ;
200
- if ( self . timeout ) {
201
- window . clearTimeout ( self . timeout ) ;
202
- }
195
+ clearTimeout ( self . timeout ) ;
203
196
// TODO can we implement that without a timeout?
204
- self . timeout = window . setTimeout ( function ( ) {
197
+ self . timeout = setTimeout ( function ( ) {
205
198
if ( self . spinning ) {
206
199
self . _stop ( event ) ;
207
200
self . _change ( event ) ;
@@ -231,34 +224,33 @@ $.widget('ui.spinner', {
231
224
return false ;
232
225
} ,
233
226
234
- // TODO tune repeat behaviour, see http://jsbin.com/aruki4/2 for reference
235
227
_repeat : function ( i , steps , event ) {
236
228
var self = this ;
237
- i = i || 100 ;
229
+ i = i || 500 ;
238
230
239
- if ( this . timer ) {
240
- window . clearTimeout ( this . timer ) ;
241
- }
242
-
243
- this . timer = window . setTimeout ( function ( ) {
244
- self . _repeat ( self . options . incremental && self . counter > 20 ? 20 : i , steps , event ) ;
231
+ clearTimeout ( this . timer ) ;
232
+ this . timer = setTimeout ( function ( ) {
233
+ self . _repeat ( 40 , steps , event ) ;
245
234
} , i ) ;
246
235
247
- self . _spin ( steps * self . options . step , event ) ;
236
+ self . _spin ( steps * self . options . step , event ) ;
248
237
} ,
249
238
250
239
_spin : function ( step , event ) {
251
240
if ( ! this . counter ) {
252
241
this . counter = 1 ;
253
242
}
254
243
255
- var newVal = this . options . value + step * ( this . options . incremental && this . counter > 100
256
- ? this . counter > 200
257
- ? 100
258
- : 10
259
- : 1 ) ;
244
+ // TODO refactor, maybe figure out some non-linear math
245
+ var newVal = this . options . value + step * ( this . options . incremental &&
246
+ this . counter > 20
247
+ ? this . counter > 100
248
+ ? this . counter > 200
249
+ ? 100
250
+ : 10
251
+ : 2
252
+ : 1 ) ;
260
253
261
- // cancelable
262
254
if ( this . _trigger ( 'spin' , event , { value : newVal } ) !== false ) {
263
255
this . value ( newVal ) ;
264
256
this . counter ++ ;
@@ -288,28 +280,32 @@ $.widget('ui.spinner', {
288
280
if ( value > this . options . max ) {
289
281
value = this . options . max ;
290
282
}
291
- }
283
+ }
284
+ if ( key == 'disabled' ) {
285
+ if ( value ) {
286
+ this . element . attr ( "disabled" , true ) ;
287
+ this . buttons . button ( "disable" ) ;
288
+ } else {
289
+ this . element . removeAttr ( "disabled" ) ;
290
+ this . buttons . button ( "enable" ) ;
291
+ }
292
+ }
292
293
$ . Widget . prototype . _setOption . call ( this , key , value ) ;
293
- this . _afterSetData ( key , value ) ;
294
294
} ,
295
295
296
- _afterSetData : function ( key , value ) {
297
- switch ( key ) {
298
- case 'value' :
299
- this . _format ( this . options . value ) ;
300
- case 'max' :
301
- case 'min' :
302
- case 'step' :
303
- this . _aria ( ) ;
296
+ _setOptions : function ( options ) {
297
+ $ . Widget . prototype . _setOptions . call ( this , options ) ;
298
+ if ( "value" in options ) {
299
+ this . _format ( this . options . value ) ;
304
300
}
301
+ this . _aria ( ) ;
305
302
} ,
306
303
307
304
_aria : function ( ) {
308
- // TODO remove check, as soon as this method doesn't get called anymore before uiSpinner is initalized
309
- this . uiSpinner && this . uiSpinner
310
- . attr ( 'aria-valuemin' , this . options . min )
311
- . attr ( 'aria-valuemax' , this . options . max )
312
- . attr ( 'aria-valuenow' , this . options . value ) ;
305
+ this . uiSpinner
306
+ . attr ( 'aria-valuemin' , this . options . min )
307
+ . attr ( 'aria-valuemax' , this . options . max )
308
+ . attr ( 'aria-valuenow' , this . options . value ) ;
313
309
} ,
314
310
315
311
_parse : function ( val ) {
@@ -327,6 +323,7 @@ $.widget('ui.spinner', {
327
323
} ,
328
324
329
325
_format : function ( num ) {
326
+ var num = this . options . value ;
330
327
this . element . val ( window . Globalization && this . options . numberformat ? Globalization . format ( num , this . options . numberformat ) : num ) ;
331
328
} ,
332
329
@@ -339,30 +336,12 @@ $.widget('ui.spinner', {
339
336
this . uiSpinner . replaceWith ( this . element ) ;
340
337
} ,
341
338
342
- enable : function ( ) {
343
- this . element
344
- . removeAttr ( 'disabled' )
345
- . parent ( )
346
- . removeClass ( 'ui-spinner-disabled ui-state-disabled' ) ;
347
- this . options . disabled = false ;
348
- this . buttons . button ( "enable" ) ;
349
- } ,
350
-
351
- disable : function ( ) {
352
- this . element
353
- . attr ( 'disabled' , true )
354
- . parent ( )
355
- . addClass ( 'ui-spinner-disabled ui-state-disabled' ) ;
356
- this . options . disabled = true ;
357
- this . buttons . button ( "disable" ) ;
358
- } ,
359
-
360
339
stepUp : function ( steps ) {
361
- this . _spin ( ( steps || 1 ) * this . options . step , null ) ;
340
+ this . _spin ( ( steps || 1 ) * this . options . step ) ;
362
341
} ,
363
342
364
343
stepDown : function ( steps ) {
365
- this . _spin ( ( steps || 1 ) * - this . options . step , null ) ;
344
+ this . _spin ( ( steps || 1 ) * - this . options . step ) ;
366
345
} ,
367
346
368
347
pageUp : function ( pages ) {
@@ -377,7 +356,7 @@ $.widget('ui.spinner', {
377
356
if ( ! arguments . length ) {
378
357
return this . options . value ;
379
358
}
380
- this . _setOption ( 'value' , newVal ) ;
359
+ this . option ( 'value' , newVal ) ;
381
360
} ,
382
361
383
362
widget : function ( ) {
0 commit comments