@@ -297,88 +297,72 @@ return $.widget( "ui.slider", $.ui.mouse, {
297
297
return this . _trimAlignValue ( valueMouse ) ;
298
298
} ,
299
299
300
- _start : function ( event , index ) {
300
+ _uiHash : function ( index , value , values ) {
301
301
var uiHash = {
302
302
handle : this . handles [ index ] ,
303
- value : this . value ( )
303
+ handleIndex : index ,
304
+ value : value || this . value ( )
304
305
} ;
305
- if ( this . options . values && this . options . values . length ) {
306
- uiHash . value = this . values ( index ) ;
307
- uiHash . values = this . values ( ) ;
306
+
307
+ if ( this . _hasMultipleValues ( ) ) {
308
+ uiHash . value = value || this . values ( index ) ;
309
+ uiHash . values = values || this . values ( ) ;
308
310
}
309
- return this . _trigger ( "start" , event , uiHash ) ;
311
+
312
+ return uiHash ;
313
+ } ,
314
+
315
+ _hasMultipleValues : function ( ) {
316
+ return this . options . values && this . options . values . length ;
317
+ } ,
318
+
319
+ _start : function ( event , index ) {
320
+ return this . _trigger ( "start" , event , this . _uiHash ( index ) ) ;
310
321
} ,
311
322
312
323
_slide : function ( event , index , newVal ) {
313
- var otherVal ,
314
- newValues ,
315
- allowed ;
324
+ var allowed , otherVal ,
325
+ currentValue = this . value ( ) ,
326
+ newValues = this . values ( ) ;
316
327
317
- if ( this . options . values && this . options . values . length ) {
328
+ if ( this . _hasMultipleValues ( ) ) {
318
329
otherVal = this . values ( index ? 0 : 1 ) ;
330
+ currentValue = this . values ( index ) ;
319
331
320
- if ( ( this . options . values . length === 2 && this . options . range === true ) &&
321
- ( ( index === 0 && newVal > otherVal ) || ( index === 1 && newVal < otherVal ) )
322
- ) {
323
- newVal = otherVal ;
332
+ if ( this . options . values . length === 2 && this . options . range === true ) {
333
+ newVal = index === 0 ? Math . min ( otherVal , newVal ) : Math . max ( otherVal , newVal ) ;
324
334
}
325
335
326
- if ( newVal !== this . values ( index ) ) {
327
- newValues = this . values ( ) ;
328
- newValues [ index ] = newVal ;
329
- // A slide can be canceled by returning false from the slide callback
330
- allowed = this . _trigger ( "slide" , event , {
331
- handle : this . handles [ index ] ,
332
- value : newVal ,
333
- values : newValues
334
- } ) ;
335
- otherVal = this . values ( index ? 0 : 1 ) ;
336
- if ( allowed !== false ) {
337
- this . values ( index , newVal ) ;
338
- }
339
- }
336
+ newValues [ index ] = newVal ;
337
+ }
338
+
339
+ if ( newVal === currentValue ) {
340
+ return ;
341
+ }
342
+
343
+ allowed = this . _trigger ( "slide" , event , this . _uiHash ( index , newVal , newValues ) ) ;
344
+
345
+ // A slide can be canceled by returning false from the slide callback
346
+ if ( allowed === false ) {
347
+ return ;
348
+ }
349
+
350
+ if ( this . _hasMultipleValues ( ) ) {
351
+ this . values ( index , newVal ) ;
340
352
} else {
341
- if ( newVal !== this . value ( ) ) {
342
- // A slide can be canceled by returning false from the slide callback
343
- allowed = this . _trigger ( "slide" , event , {
344
- handle : this . handles [ index ] ,
345
- value : newVal
346
- } ) ;
347
- if ( allowed !== false ) {
348
- this . value ( newVal ) ;
349
- }
350
- }
353
+ this . value ( newVal ) ;
351
354
}
352
355
} ,
353
356
354
357
_stop : function ( event , index ) {
355
- var uiHash = {
356
- handle : this . handles [ index ] ,
357
- value : this . value ( )
358
- } ;
359
- if ( this . options . values && this . options . values . length ) {
360
- uiHash . value = this . values ( index ) ;
361
- uiHash . values = this . values ( ) ;
362
- }
363
-
364
- this . _trigger ( "stop" , event , uiHash ) ;
358
+ this . _trigger ( "stop" , event , this . _uiHash ( index ) ) ;
365
359
} ,
366
360
367
361
_change : function ( event , index ) {
368
362
if ( ! this . _keySliding && ! this . _mouseSliding ) {
369
- var uiHash = {
370
- handle : this . handles [ index ] ,
371
- value : this . value ( )
372
- } ;
373
- if ( this . options . values && this . options . values . length ) {
374
- uiHash . value = this . values ( index ) ;
375
- uiHash . values = this . values ( ) ;
376
- }
377
-
378
363
//store the last changed value index for reference when handles overlap
379
364
this . _lastChangedValue = index ;
380
-
381
- this . _trigger ( "change" , event , uiHash ) ;
365
+ this . _trigger ( "change" , event , this . _uiHash ( index ) ) ;
382
366
}
383
367
} ,
384
368
@@ -415,7 +399,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
415
399
}
416
400
this . _refreshValue ( ) ;
417
401
} else {
418
- if ( this . options . values && this . options . values . length ) {
402
+ if ( this . _hasMultipleValues ( ) ) {
419
403
return this . _values ( index ) ;
420
404
} else {
421
405
return this . value ( ) ;
@@ -512,7 +496,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
512
496
val = this . _trimAlignValue ( val ) ;
513
497
514
498
return val ;
515
- } else if ( this . options . values && this . options . values . length ) {
499
+ } else if ( this . _hasMultipleValues ( ) ) {
516
500
// .slice() creates a copy of the array
517
501
// this copy gets trimmed by min and max and then returned
518
502
vals = this . options . values . slice ( ) ;
@@ -586,7 +570,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
586
570
animate = ( ! this . _animateOff ) ? o . animate : false ,
587
571
_set = { } ;
588
572
589
- if ( this . options . values && this . options . values . length ) {
573
+ if ( this . _hasMultipleValues ( ) ) {
590
574
this . handles . each ( function ( i ) {
591
575
valPercent = ( that . values ( i ) - that . _valueMin ( ) ) / ( that . _valueMax ( ) - that . _valueMin ( ) ) * 100 ;
592
576
_set [ that . orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%" ;
@@ -662,7 +646,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
662
646
}
663
647
664
648
step = this . options . step ;
665
- if ( this . options . values && this . options . values . length ) {
649
+ if ( this . _hasMultipleValues ( ) ) {
666
650
curVal = newVal = this . values ( index ) ;
667
651
} else {
668
652
curVal = newVal = this . value ( ) ;
0 commit comments