Slider: Style updates

Ref #14246
This commit is contained in:
Alexander Schmitz 2015-08-24 08:58:09 -04:00
parent 62c8217185
commit e583a512d7
6 changed files with 185 additions and 181 deletions

View File

@ -30,6 +30,6 @@ common.testWidget( "slider", {
start: null, start: null,
stop: null stop: null
} }
}); } );
} ); } );

View File

@ -14,7 +14,7 @@ module( "slider: core" );
test( "markup structure", function( assert ) { test( "markup structure", function( assert ) {
expect( 4 ); expect( 4 );
var element = $( "<div>" ).slider({ range: true }), var element = $( "<div>" ).slider( { range: true } ),
handle = element.find( "span" ), handle = element.find( "span" ),
range = element.find( "div" ); range = element.find( "div" );
@ -22,7 +22,7 @@ test( "markup structure", function( assert ) {
assert.hasClasses( range, "ui-slider-range ui-widget-header" ); assert.hasClasses( range, "ui-slider-range ui-widget-header" );
assert.hasClasses( handle[ 0 ], "ui-slider-handle" ); assert.hasClasses( handle[ 0 ], "ui-slider-handle" );
assert.hasClasses( handle[ 1 ], "ui-slider-handle" ); assert.hasClasses( handle[ 1 ], "ui-slider-handle" );
}); } );
test( "keydown HOME on handle sets value to min", function() { test( "keydown HOME on handle sets value to min", function() {
expect( 2 ); expect( 2 );
@ -38,7 +38,7 @@ test( "keydown HOME on handle sets value to min", function() {
element.slider( "value", 0 ); element.slider( "value", 0 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
element.slider( "destroy" ); element.slider( "destroy" );
@ -54,10 +54,10 @@ test( "keydown HOME on handle sets value to min", function() {
element.slider( "value", 0 ); element.slider( "value", 0 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal(element.slider( "value" ), options.min) ; equal( element.slider( "value" ), options.min ) ;
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "keydown END on handle sets value to max", function() { test( "keydown END on handle sets value to max", function() {
expect( 2 ); expect( 2 );
@ -73,7 +73,7 @@ test( "keydown END on handle sets value to max", function() {
element.slider( "value", 0 ); element.slider( "value", 0 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal(element.slider( "value" ), options.max) ; equal( element.slider( "value" ), options.max ) ;
element.slider( "destroy" ); element.slider( "destroy" );
@ -89,10 +89,10 @@ test( "keydown END on handle sets value to max", function() {
element.slider( "value", 0 ); element.slider( "value", 0 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() { test( "keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() {
expect( 4 ); expect( 4 );
@ -106,17 +106,17 @@ test( "keydown PAGE_UP on handle increases value by 1/5 range, not greater than
}; };
element.slider( options ); element.slider( options );
element.slider( "value", 70); element.slider( "value", 70 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal(element.slider( "value" ), 90); equal( element.slider( "value" ), 90 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal(element.slider( "value" ), 100); equal( element.slider( "value" ), 100 );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
}); } );
test( "keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() { test( "keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() {
expect( 4 ); expect( 4 );
@ -130,17 +130,17 @@ test( "keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than m
}; };
element.slider( options ); element.slider( options );
element.slider( "value", 30); element.slider( "value", 30 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal(element.slider( "value" ), 10); equal( element.slider( "value" ), 10 );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal(element.slider( "value" ), 0 ); equal( element.slider( "value" ), 0 );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
}); } );
test( "keydown UP on handle increases value by step, not greater than max", function() { test( "keydown UP on handle increases value by step, not greater than max", function() {
expect( 4 ); expect( 4 );
@ -151,15 +151,15 @@ test( "keydown UP on handle increases value by step, not greater than max", func
orientation: "horizontal", orientation: "horizontal",
step: 1 step: 1
}; };
element.slider(options); element.slider( options );
element.slider( "value", options.max - options.step ); element.slider( "value", options.max - options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
element.slider( "destroy" ); element.slider( "destroy" );
@ -175,13 +175,13 @@ test( "keydown UP on handle increases value by step, not greater than max", func
element.slider( "value", options.max - options.step ); element.slider( "value", options.max - options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "keydown RIGHT on handle increases value by step, not greater than max", function() { test( "keydown RIGHT on handle increases value by step, not greater than max", function() {
expect( 4 ); expect( 4 );
@ -192,15 +192,15 @@ test( "keydown RIGHT on handle increases value by step, not greater than max", f
orientation: "horizontal", orientation: "horizontal",
step: 1 step: 1
}; };
element.slider(options); element.slider( options );
element.slider( "value", options.max - options.step ); element.slider( "value", options.max - options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max); equal( element.slider( "value" ), options.max );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
element.slider( "destroy" ); element.slider( "destroy" );
@ -216,13 +216,13 @@ test( "keydown RIGHT on handle increases value by step, not greater than max", f
element.slider( "value", options.max - options.step ); element.slider( "value", options.max - options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max ); equal( element.slider( "value" ), options.max );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "keydown DOWN on handle decreases value by step, not less than min", function() { test( "keydown DOWN on handle decreases value by step, not less than min", function() {
expect( 4 ); expect( 4 );
@ -238,10 +238,10 @@ test( "keydown DOWN on handle decreases value by step, not less than min", funct
element.slider( "value", options.min + options.step ); element.slider( "value", options.min + options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min); equal( element.slider( "value" ), options.min );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
element.slider( "destroy" ); element.slider( "destroy" );
@ -257,13 +257,13 @@ test( "keydown DOWN on handle decreases value by step, not less than min", funct
element.slider( "value", options.min + options.step ); element.slider( "value", options.min + options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min); equal( element.slider( "value" ), options.min );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "keydown LEFT on handle decreases value by step, not less than min", function() { test( "keydown LEFT on handle decreases value by step, not less than min", function() {
expect( 4 ); expect( 4 );
@ -274,15 +274,15 @@ test( "keydown LEFT on handle decreases value by step, not less than min", funct
orientation: "horizontal", orientation: "horizontal",
step: 1 step: 1
}; };
element.slider(options); element.slider( options );
element.slider( "value", options.min + options.step ); element.slider( "value", options.min + options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
element.slider( "destroy" ); element.slider( "destroy" );
@ -298,12 +298,12 @@ test( "keydown LEFT on handle decreases value by step, not less than min", funct
element.slider( "value", options.min + options.step ); element.slider( "value", options.min + options.step );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min ); equal( element.slider( "value" ), options.min );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
} ); } );

View File

@ -13,11 +13,11 @@ test( "mouse based interaction", function() {
expect( 4 ); expect( 4 );
var element = $( "#slider1" ) var element = $( "#slider1" )
.slider({ .slider( {
start: function( event ) { start: function( event ) {
equal( event.originalEvent.type, "mousedown", "start triggered by mousedown" ); equal( event.originalEvent.type, "mousedown", "start triggered by mousedown" );
}, },
slide: function( event) { slide: function( event ) {
equal( event.originalEvent.type, "mousemove", "slider triggered by mousemove" ); equal( event.originalEvent.type, "mousemove", "slider triggered by mousemove" );
}, },
stop: function( event ) { stop: function( event ) {
@ -26,18 +26,18 @@ test( "mouse based interaction", function() {
change: function( event ) { change: function( event ) {
equal( event.originalEvent.type, "mouseup", "change triggered by mouseup" ); equal( event.originalEvent.type, "mouseup", "change triggered by mouseup" );
} }
}); } );
element.find( ".ui-slider-handle" ).eq( 0 ) element.find( ".ui-slider-handle" ).eq( 0 )
.simulate( "drag", { dx: 10, dy: 10 } ); .simulate( "drag", { dx: 10, dy: 10 } );
}); } );
test( "keyboard based interaction", function() { test( "keyboard based interaction", function() {
expect( 3 ); expect( 3 );
// Test keyup at end of handle slide (keyboard) // Test keyup at end of handle slide (keyboard)
var element = $( "#slider1" ) var element = $( "#slider1" )
.slider({ .slider( {
start: function( event ) { start: function( event ) {
equal( event.originalEvent.type, "keydown", "start triggered by keydown" ); equal( event.originalEvent.type, "keydown", "start triggered by keydown" );
}, },
@ -50,113 +50,113 @@ test( "keyboard based interaction", function() {
change: function( event ) { change: function( event ) {
equal( event.originalEvent.type, "keyup", "change triggered by keyup" ); equal( event.originalEvent.type, "keyup", "change triggered by keyup" );
} }
}); } );
element.find( ".ui-slider-handle" ).eq( 0 ) element.find( ".ui-slider-handle" ).eq( 0 )
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } )
.simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } )
.simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } ); .simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } );
}); } );
test( "programmatic event triggers", function() { test( "programmatic event triggers", function() {
expect( 6 ); expect( 6 );
// Test value method // Test value method
var element = $( "<div></div>" ) var element = $( "<div></div>" )
.slider({ .slider( {
change: function() { change: function() {
ok( true, "change triggered by value method" ); ok( true, "change triggered by value method" );
} }
}) } )
.slider( "value", 0 ); .slider( "value", 0 );
// Test values method // Test values method
element = $( "<div></div>" ) element = $( "<div></div>" )
.slider({ .slider( {
values: [ 10, 20 ], values: [ 10, 20 ],
change: function() { change: function() {
ok( true, "change triggered by values method" ); ok( true, "change triggered by values method" );
} }
}) } )
.slider( "values", [ 80, 90 ] ); .slider( "values", [ 80, 90 ] );
// Test value option // Test value option
element = $( "<div></div>" ) element = $( "<div></div>" )
.slider({ .slider( {
change: function() { change: function() {
ok( true, "change triggered by value option" ); ok( true, "change triggered by value option" );
} }
}) } )
.slider( "option", "value", 0 ); .slider( "option", "value", 0 );
// Test values option // Test values option
element = $( "<div></div>" ) element = $( "<div></div>" )
.slider({ .slider( {
values: [ 10, 20 ], values: [ 10, 20 ],
change: function() { change: function() {
ok( true, "change triggered by values option" ); ok( true, "change triggered by values option" );
} }
}) } )
.slider( "option", "values", [ 80, 90 ] ); .slider( "option", "values", [ 80, 90 ] );
}); } );
test( "mouse based interaction part two: when handles overlap", function() { test( "mouse based interaction part two: when handles overlap", function() {
expect( 6 ); expect( 6 );
var element = $( "#slider1" ) var element = $( "#slider1" )
.slider({ .slider( {
values: [ 0, 0, 0 ], values: [ 0, 0, 0 ],
start: function( event, ui ) { start: function( event, ui ) {
equal( handles.index( ui.handle ), 2, "rightmost handle activated when overlapping at minimum (#3736)" ); equal( handles.index( ui.handle ), 2, "rightmost handle activated when overlapping at minimum (#3736)" );
} }
}), } ),
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
handles.eq( 0 ).simulate( "drag", { dx: 10 } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } );
element.slider( "destroy" ); element.slider( "destroy" );
element = $( "#slider1" ) element = $( "#slider1" )
.slider({ .slider( {
values: [ 10, 10, 10 ], values: [ 10, 10, 10 ],
max: 10, max: 10,
start: function( event, ui ) { start: function( event, ui ) {
equal( handles.index( ui.handle ), 0, "leftmost handle activated when overlapping at maximum" ); equal( handles.index( ui.handle ), 0, "leftmost handle activated when overlapping at maximum" );
} }
}), } ),
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
handles.eq( 0 ).simulate( "drag", { dx: -10 } ); handles.eq( 0 ).simulate( "drag", { dx: -10 } );
element.slider( "destroy" ); element.slider( "destroy" );
element = $( "#slider1" ) element = $( "#slider1" )
.slider({ .slider( {
values: [ 19, 20 ] values: [ 19, 20 ]
}), } ),
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
handles.eq( 0 ).simulate( "drag", { dx: 10 } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } );
element.one( "slidestart", function( event, ui ) { element.one( "slidestart", function( event, ui ) {
equal( handles.index( ui.handle ), 0, "left handle activated if left was moved last" ); equal( handles.index( ui.handle ), 0, "left handle activated if left was moved last" );
}); } );
handles.eq( 0 ).simulate( "drag", { dx: 10 } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } );
element.slider( "destroy" ); element.slider( "destroy" );
element = $( "#slider1" ) element = $( "#slider1" )
.slider({ .slider( {
values: [ 19, 20 ] values: [ 19, 20 ]
}), } ),
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
handles.eq( 1 ).simulate( "drag", { dx: -10 } ); handles.eq( 1 ).simulate( "drag", { dx: -10 } );
element.one( "slidestart", function( event, ui ) { element.one( "slidestart", function( event, ui ) {
equal( handles.index( ui.handle ), 1, "right handle activated if right was moved last (#3467)" ); equal( handles.index( ui.handle ), 1, "right handle activated if right was moved last (#3467)" );
}); } );
handles.eq( 0 ).simulate( "drag", { dx: 10 } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } );
element = $( "#slider1" ) element = $( "#slider1" )
.slider({ .slider( {
range: true, range: true,
min: 0, min: 0,
max: 100, max: 100,
values: [ 0, 50 ] values: [ 0, 50 ]
}), } ),
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
element.slider( "option", { values: [ 100, 100 ] } ); element.slider( "option", { values: [ 100, 100 ] } );
@ -166,7 +166,7 @@ test( "mouse based interaction part two: when handles overlap", function() {
element.slider( "option", { values: [ 0, 0 ] } ); element.slider( "option", { values: [ 0, 0 ] } );
handles.eq( 1 ).simulate( "drag", { dx: 10 } ); handles.eq( 1 ).simulate( "drag", { dx: 10 } );
equal( element.slider( "values" )[ 1 ], 1, "setting both values of range slider to the minimum doesn't lock slider" ); equal( element.slider( "values" )[ 1 ], 1, "setting both values of range slider to the minimum doesn't lock slider" );
}); } );
test( "event data", function() { test( "event data", function() {
expect( 6 ); expect( 6 );
@ -175,7 +175,7 @@ test( "event data", function() {
values = [ 8, 9, 7, 4 ], values = [ 8, 9, 7, 4 ],
newValues = [ 8, 9, 7, 5 ], newValues = [ 8, 9, 7, 5 ],
element = $( "#slider1" ) element = $( "#slider1" )
.slider({ .slider( {
values: values, values: values,
start: function( event, ui ) { start: function( event, ui ) {
deepEqual( ui, expectedUiHash, "passing ui to start event" ); deepEqual( ui, expectedUiHash, "passing ui to start event" );
@ -189,7 +189,7 @@ test( "event data", function() {
change: function( event, ui ) { change: function( event, ui ) {
deepEqual( ui, expectedChangedUiHash, "passing ui to change event" ); deepEqual( ui, expectedChangedUiHash, "passing ui to change event" );
} }
}), } ),
handles = element.find( ".ui-slider-handle" ), handles = element.find( ".ui-slider-handle" ),
expectedUiHash = { expectedUiHash = {
handle: handles.eq( slideHandleIndex )[ 0 ], handle: handles.eq( slideHandleIndex )[ 0 ],
@ -200,33 +200,33 @@ test( "event data", function() {
expectedChangedUiHash = $.extend( {}, expectedUiHash, { expectedChangedUiHash = $.extend( {}, expectedUiHash, {
values: newValues, values: newValues,
value: newValues[ slideHandleIndex ] value: newValues[ slideHandleIndex ]
}); } );
handles.eq( slideHandleIndex ).simulate( "drag", { dx: 10 } ); handles.eq( slideHandleIndex ).simulate( "drag", { dx: 10 } );
element.slider( "destroy" ); element.slider( "destroy" );
element = $( "#slider1" ).slider({ element = $( "#slider1" ).slider( {
min: 0, min: 0,
max: 100, max: 100,
value: 1, value: 1,
slide: function ( event, ui ) { slide: function( event, ui ) {
equal( ui.value, 0, "should pass 0 value if slider reaches it" ); equal( ui.value, 0, "should pass 0 value if slider reaches it" );
} }
}); } );
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
handles.eq( 0 ).simulate( "drag", { dx: -10 } ); handles.eq( 0 ).simulate( "drag", { dx: -10 } );
element.slider( "destroy" ); element.slider( "destroy" );
element = $( "#slider1" ).slider({ element = $( "#slider1" ).slider( {
min: 0, min: 0,
max: 100, max: 100,
values: [ 1, 2 ], values: [ 1, 2 ],
slide: function ( event, ui ) { slide: function( event, ui ) {
equal( ui.value, 0, "should pass 0 value if one of handles reaches it" ); equal( ui.value, 0, "should pass 0 value if one of handles reaches it" );
} }
}); } );
handles = element.find( ".ui-slider-handle" ); handles = element.find( ".ui-slider-handle" );
handles.eq( 0 ).simulate( "drag", { dx: -10 } ); handles.eq( 0 ).simulate( "drag", { dx: -10 } );
}); } );
} ); } );

View File

@ -6,7 +6,7 @@ define( [
module( "slider: methods" ); module( "slider: methods" );
test( "init", function() { test( "init", function() {
expect(5); expect( 5 );
$( "<div></div>" ).appendTo( "body" ).slider().remove(); $( "<div></div>" ).appendTo( "body" ).slider().remove();
ok( true, ".slider() called on element" ); ok( true, ".slider() called on element" );
@ -24,65 +24,67 @@ test( "init", function() {
$( "<div></div>" ).slider().slider( "option", "foo", "bar" ).remove(); $( "<div></div>" ).slider().slider( "option", "foo", "bar" ).remove();
ok( true, "arbitrary option setter after init" ); ok( true, "arbitrary option setter after init" );
}); } );
test( "destroy", function( assert ) { test( "destroy", function( assert ) {
expect( 1 ); expect( 1 );
assert.domEqual( "#slider1", function() { assert.domEqual( "#slider1", function() {
$( "#slider1" ).slider().slider( "destroy" ); $( "#slider1" ).slider().slider( "destroy" );
}); } );
}); } );
test( "enable", function( assert ) { test( "enable", function( assert ) {
expect( 3 ); expect( 3 );
var element, var element,
expected = $( "<div></div>" ).slider(), expected = $( "<div></div>" ).slider(),
actual = expected.slider( "enable" ); actual = expected.slider( "enable" );
equal(actual, expected, "enable is chainable" ); equal( actual, expected, "enable is chainable" );
element = $( "<div></div>" ).slider({ disabled: true }); element = $( "<div></div>" ).slider( { disabled: true } );
assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" ); assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" );
element.slider( "enable" ); element.slider( "enable" );
assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" ); assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" );
}); } );
test( "disable", function( assert ) { test( "disable", function( assert ) {
expect( 4 ); expect( 4 );
var element, var element,
expected = $( "<div></div>" ).slider(), expected = $( "<div></div>" ).slider(),
actual = expected.slider( "disable" ); actual = expected.slider( "disable" );
equal(actual, expected, "disable is chainable" ); equal( actual, expected, "disable is chainable" );
element = $( "<div></div>" ).slider({ disabled: false }); element = $( "<div></div>" ).slider( { disabled: false } );
assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" ); assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" );
element.slider( "disable" ); element.slider( "disable" );
assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" ); assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" );
ok( !element.attr( "aria-disabled" ), "slider does not have aria-disabled attr after disable method call" ); ok( !element.attr( "aria-disabled" ), "slider does not have aria-disabled attr after disable method call" );
}); } );
test( "value", function() { test( "value", function() {
expect( 19 ); expect( 19 );
$( [ false, "min", "max" ] ).each(function() { $( [ false, "min", "max" ] ).each( function() {
var element = $( "<div></div>" ).slider({ var element = $( "<div></div>" ).slider( {
range: this, range: this,
value: 5 value: 5
}); } );
equal( element.slider( "value" ), 5, "range: " + this + " slider method get" ); equal( element.slider( "value" ), 5, "range: " + this + " slider method get" );
equal( element.slider( "value", 10), element, "value method is chainable" ); equal( element.slider( "value", 10 ), element, "value method is chainable" );
equal( element.slider( "value" ), 10, "range: " + this + " slider method set" ); equal( element.slider( "value" ), 10, "range: " + this + " slider method set" );
element.remove(); element.remove();
}); } );
var element = $( "<div></div>" ).slider({ var element = $( "<div></div>" ).slider( {
min: -1, value: 0, max: 1 min: -1, value: 0, max: 1
}); } );
// min with value option vs value method // min with value option vs value method
element.slider( "option", "value", -2 ); element.slider( "option", "value", -2 );
equal( element.slider( "option", "value" ), -2, "value option does not respect min" ); equal( element.slider( "option", "value" ), -2, "value option does not respect min" );
equal( element.slider( "value" ), -1, "value method get respects min" ); equal( element.slider( "value" ), -1, "value method get respects min" );
equal( element.slider( "value", -2 ), element, "value method is chainable" ); equal( element.slider( "value", -2 ), element, "value method is chainable" );
equal( element.slider( "option", "value" ), -1, "value method set respects min" ); equal( element.slider( "option", "value" ), -1, "value method set respects min" );
// max with value option vs value method // max with value option vs value method
element.slider( "option", "value", 2); element.slider( "option", "value", 2 );
equal( element.slider( "option", "value" ), 2, "value option does not respect max" ); equal( element.slider( "option", "value" ), 2, "value option does not respect max" );
equal( element.slider( "value" ), 1, "value method get respects max" ); equal( element.slider( "value" ), 1, "value method get respects max" );
equal( element.slider( "value", 2 ), element, "value method is chainable" ); equal( element.slider( "value", 2 ), element, "value method is chainable" );
@ -94,20 +96,20 @@ test( "value", function() {
value: 2, value: 2,
max: 2.4, max: 2.4,
step: 0.01 step: 0.01
}); } );
element.slider( "option", "value", 2.4 ); element.slider( "option", "value", 2.4 );
equal( element.slider( "value" ), 2.4, "value is set to max with 0.01 step" ); equal( element.slider( "value" ), 2.4, "value is set to max with 0.01 step" );
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
value: 100, value: 100,
min: 10, min: 10,
max: 500, max: 500,
step: 50 step: 50
}); } );
element.slider( "option", "value", 510 ); element.slider( "option", "value", 510 );
equal( element.slider( "value" ), 460, "value is restricted to maximum valid step" ); equal( element.slider( "value" ), 460, "value is restricted to maximum valid step" );
}); } );
//test( "values", function() { //test( "values", function() {
// ok(false, "missing test - untested code is broken code." ); // ok(false, "missing test - untested code is broken code." );

View File

@ -11,18 +11,18 @@ function handle() {
module( "slider: options" ); module( "slider: options" );
test( "disabled", function( assert ){ test( "disabled", function( assert ) {
expect( 8 ); expect( 8 );
var count = 0; var count = 0;
element = $( "#slider1" ).slider(); element = $( "#slider1" ).slider();
element.on( "slidestart", function() { element.on( "slidestart", function() {
count++; count++;
}); } );
// Enabled // Enabled
assert.lacksClasses( element, "ui-slider-disabled" ); assert.lacksClasses( element, "ui-slider-disabled" );
equal( element.slider( "option", "disabled" ), false , "is not disabled" ); equal( element.slider( "option", "disabled" ), false, "is not disabled" );
handle().simulate( "drag", { dx: 10 } ); handle().simulate( "drag", { dx: 10 } );
equal( count, 1, "slider moved" ); equal( count, 1, "slider moved" );
@ -40,7 +40,7 @@ test( "disabled", function( assert ){
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal( count, 2, "slider did not move" ); equal( count, 2, "slider did not move" );
}); } );
test( "max", function() { test( "max", function() {
expect( 5 ); expect( 5 );
@ -87,7 +87,7 @@ test( "max", function() {
ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" ); ok( element.slider( "value" ) === options.max, "value method will max, step is changed and step is float" );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "min", function() { test( "min", function() {
expect( 2 ); expect( 2 );
@ -106,7 +106,7 @@ test( "min", function() {
ok( element.slider( "value" ) === options.min, "value method is contained by min" ); ok( element.slider( "value" ) === options.min, "value method is contained by min" );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
test( "orientation", function( assert ) { test( "orientation", function( assert ) {
expect( 14 ); expect( 14 );
@ -126,7 +126,7 @@ test( "orientation", function( assert ) {
assert.hasClasses( element, "ui-slider-horizontal" ); assert.hasClasses( element, "ui-slider-horizontal" );
assert.lacksClasses( element, "ui-slider-vertical" ); assert.lacksClasses( element, "ui-slider-vertical" );
equal( element.find( ".ui-slider-handle" )[ 0 ].style.bottom, "", "CSS bottom reset" ); equal( element.find( ".ui-slider-handle" )[ 0 ].style.bottom, "", "CSS bottom reset" );
equal( handle()[0].style.left, percentVal + "%", "horizontal slider handle is positioned with left: %" ); equal( handle()[ 0 ].style.left, percentVal + "%", "horizontal slider handle is positioned with left: %" );
element.slider( "destroy" ) ; element.slider( "destroy" ) ;
@ -143,17 +143,17 @@ test( "orientation", function( assert ) {
assert.hasClasses( element, "ui-slider-vertical" ); assert.hasClasses( element, "ui-slider-vertical" );
assert.lacksClasses( element, "ui-slider-horizontal" ); assert.lacksClasses( element, "ui-slider-horizontal" );
equal( element.find( ".ui-slider-handle" )[ 0 ].style.left, "", "CSS left reset" ); equal( element.find( ".ui-slider-handle" )[ 0 ].style.left, "", "CSS left reset" );
equal( handle()[0].style.bottom, percentVal + "%", "vertical slider handle is positioned with bottom: %" ); equal( handle()[ 0 ].style.bottom, percentVal + "%", "vertical slider handle is positioned with bottom: %" );
element.slider( "destroy" ); element.slider( "destroy" );
newValue = 7; newValue = 7;
rangeSize = 500 - (500 * newValue / 10); rangeSize = 500 - ( 500 * newValue / 10 );
element = $( "#slider2" ).slider({ element = $( "#slider2" ).slider( {
range: "max", range: "max",
min: 0, min: 0,
max: 10 max: 10
}); } );
element.slider( "option", "value", newValue ); element.slider( "option", "value", newValue );
element.slider( "option", "orientation", "vertical" ); element.slider( "option", "orientation", "vertical" );
@ -170,11 +170,11 @@ test( "orientation", function( assert ) {
element.slider( "destroy" ); element.slider( "destroy" );
element = $( "#slider2" ).slider({ element = $( "#slider2" ).slider( {
range: true, range: true,
min: 0, min: 0,
max: 100 max: 100
}); } );
element.slider( "option", { values: [ 60, 70 ] } ); element.slider( "option", { values: [ 60, 70 ] } );
notEqual( element.find( ".ui-slider-range " ).position().left, 0, notEqual( element.find( ".ui-slider-range " ).position().left, 0,
"range should not pull over to the track's border" ); "range should not pull over to the track's border" );
@ -183,19 +183,19 @@ test( "orientation", function( assert ) {
"range should pull over to the track's border" ); "range should pull over to the track's border" );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
//spec: http://wiki.jqueryui.com/Slider#specs //spec: http://wiki.jqueryui.com/Slider#specs
// value option/method: the value option is not restricted by min/max/step. // value option/method: the value option is not restricted by min/max/step.
// What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple) // What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple)
test( "step", function() { test( "step", function() {
expect( 9 ); expect( 9 );
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
min: 0, min: 0,
value: 0, value: 0,
step: 10, step: 10,
max: 100 max: 100
}); } );
equal( element.slider( "value" ), 0 ); equal( element.slider( "value" ), 0 );
element.slider( "value", 1 ); element.slider( "value", 1 );
@ -210,12 +210,12 @@ test( "step", function() {
element.slider( "value", 19 ); element.slider( "value", 19 );
equal( element.slider( "value" ), 20 ); equal( element.slider( "value" ), 20 );
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
min: 0, min: 0,
value: 0, value: 0,
step: 20, step: 20,
max: 100 max: 100
}); } );
element.slider( "value", 0 ); element.slider( "value", 0 );
element.slider( "option", "value", 1 ); element.slider( "option", "value", 1 );
@ -231,7 +231,7 @@ test( "step", function() {
equal( element.slider( "value" ), 20 ); equal( element.slider( "value" ), 20 );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
//test( "value", function() { //test( "value", function() {
// ok(false, "missing test - untested code is broken code." ); // ok(false, "missing test - untested code is broken code." );
@ -243,13 +243,13 @@ test( "values", function() {
// Testing multiple ranges on the same page, the object reference to the values // Testing multiple ranges on the same page, the object reference to the values
// property is preserved via multiple range elements, so updating options.values // property is preserved via multiple range elements, so updating options.values
// of 1 slider updates options.values of all the others // of 1 slider updates options.values of all the others
var ranges = $([ var ranges = $( [
document.createElement( "div" ), document.createElement( "div" ),
document.createElement( "div" ) document.createElement( "div" )
]).slider({ ] ).slider( {
range: true, range: true,
values: [ 25, 75 ] values: [ 25, 75 ]
}); } );
notStrictEqual( notStrictEqual(
ranges.eq( 0 ).slider( "instance" ).options.values, ranges.eq( 0 ).slider( "instance" ).options.values,
@ -264,43 +264,43 @@ test( "values", function() {
ranges.eq( 1 ).slider( "values", 0 ), ranges.eq( 1 ).slider( "values", 0 ),
"the values for multiple sliders should be different" "the values for multiple sliders should be different"
); );
}); } );
test( "range", function( assert ) { test( "range", function( assert ) {
expect( 32 ); expect( 32 );
var range; var range;
// Min // Min
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: "min", range: "min",
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}); } );
equal( element.find( ".ui-slider-handle" ).length, 1, "range min, one handle" ); equal( element.find( ".ui-slider-handle" ).length, 1, "range min, one handle" );
equal( element.find( ".ui-slider-range-min" ).length, 1, "range min" ); equal( element.find( ".ui-slider-range-min" ).length, 1, "range min" );
element.slider( "destroy" ); element.slider( "destroy" );
// Max // Max
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: "max", range: "max",
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}); } );
equal( element.find( ".ui-slider-handle" ).length, 1, "range max, one handle" ); equal( element.find( ".ui-slider-handle" ).length, 1, "range max, one handle" );
equal( element.find( ".ui-slider-range-max" ).length, 1, "range max" ); equal( element.find( ".ui-slider-range-max" ).length, 1, "range max" );
element.slider( "destroy" ); element.slider( "destroy" );
// True // True
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: true, range: true,
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}); } );
range = element.find( ".ui-slider-range" ); range = element.find( ".ui-slider-range" );
equal( element.find( ".ui-slider-handle" ).length, 2, "range true, two handles" ); equal( element.find( ".ui-slider-handle" ).length, 2, "range true, two handles" );
@ -308,12 +308,12 @@ test( "range", function( assert ) {
element.slider( "destroy" ); element.slider( "destroy" );
// Change range from min to max // Change range from min to max
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: "min", range: "min",
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}).slider( "option", "range", "max" ); } ).slider( "option", "range", "max" );
equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from min to max, one handle" ); equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from min to max, one handle" );
equal( element.find( ".ui-slider-range-min" ).length, 0, "range switch from min to max" ); equal( element.find( ".ui-slider-range-min" ).length, 0, "range switch from min to max" );
@ -321,12 +321,12 @@ test( "range", function( assert ) {
element.slider( "destroy" ); element.slider( "destroy" );
// Change range from max to min // Change range from max to min
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: "max", range: "max",
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}).slider( "option", "range", "min" ); } ).slider( "option", "range", "min" );
equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from max to min, one handle" ); equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from max to min, one handle" );
equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from max to min" ); equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from max to min" );
@ -334,53 +334,53 @@ test( "range", function( assert ) {
element.slider( "destroy" ); element.slider( "destroy" );
// Change range from max to true // Change range from max to true
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: "max", range: "max",
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}).slider( "option", "range", true ); } ).slider( "option", "range", true );
equal( element.find( ".ui-slider-handle" ).length, 2, "range switch from max to true, two handles" ); equal( element.find( ".ui-slider-handle" ).length, 2, "range switch from max to true, two handles" );
equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from max to true" ); equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from max to true" );
equal( element.find( ".ui-slider-range-min" ).length, 0, "range switch from max to true" ); equal( element.find( ".ui-slider-range-min" ).length, 0, "range switch from max to true" );
equal( element.slider( "option", "value" ), 0 , "option value" ); equal( element.slider( "option", "value" ), 0, "option value" );
equal( element.slider( "value" ), 1 , "value" ); equal( element.slider( "value" ), 1, "value" );
deepEqual( element.slider( "option", "values" ), [1, 1], "option values" ); deepEqual( element.slider( "option", "values" ), [ 1, 1 ], "option values" );
deepEqual( element.slider( "values" ), [1, 1], "values" ); deepEqual( element.slider( "values" ), [ 1, 1 ], "values" );
element.slider( "destroy" ); element.slider( "destroy" );
// Change range from true to min // Change range from true to min
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: true, range: true,
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}).slider( "option", "range", "min" ); } ).slider( "option", "range", "min" );
equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from true to min, one handle" ); equal( element.find( ".ui-slider-handle" ).length, 1, "range switch from true to min, one handle" );
equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from true to min" ); equal( element.find( ".ui-slider-range-max" ).length, 0, "range switch from true to min" );
equal( element.find( ".ui-slider-range-min" ).length, 1, "range switch from true to min" ); equal( element.find( ".ui-slider-range-min" ).length, 1, "range switch from true to min" );
equal( element.slider( "option", "value" ), 1, "value" ); equal( element.slider( "option", "value" ), 1, "value" );
equal( element.slider( "value" ), 1 , "value" ); equal( element.slider( "value" ), 1, "value" );
equal( element.slider( "option", "values" ), null, "values" ); equal( element.slider( "option", "values" ), null, "values" );
deepEqual( element.slider( "values" ), [] , "values" ); deepEqual( element.slider( "values" ), [], "values" );
element.slider( "destroy" ); element.slider( "destroy" );
// Change range from true to false // Change range from true to false
element = $( "<div></div>" ).slider({ element = $( "<div></div>" ).slider( {
range: true, range: true,
min: 1, min: 1,
max: 10, max: 10,
step: 1 step: 1
}).slider( "option", "range", false ); } ).slider( "option", "range", false );
equal( element.find( ".ui-slider-handle" ).length, 2, "range switch from true to false, both handles remain" ); equal( element.find( ".ui-slider-handle" ).length, 2, "range switch from true to false, both handles remain" );
equal( element.find( ".ui-slider-range" ).length, 0, "range switch from true to false" ); equal( element.find( ".ui-slider-range" ).length, 0, "range switch from true to false" );
equal( element.slider( "option", "value" ), 0 , "option value" ); equal( element.slider( "option", "value" ), 0, "option value" );
equal( element.slider( "value" ), 1 , "value" ); equal( element.slider( "value" ), 1, "value" );
deepEqual( element.slider( "option", "values" ), [1, 1], "option values" ); deepEqual( element.slider( "option", "values" ), [ 1, 1 ], "option values" );
deepEqual( element.slider( "values" ), [1, 1], "values" ); deepEqual( element.slider( "values" ), [ 1, 1 ], "values" );
element.slider( "destroy" ); element.slider( "destroy" );
}); } );
} ); } );

View File

@ -16,11 +16,11 @@
//>>css.structure: ../themes/base/slider.css //>>css.structure: ../themes/base/slider.css
//>>css.theme: ../themes/base/theme.css //>>css.theme: ../themes/base/theme.css
(function( factory ) { ( function( factory ) {
if ( typeof define === "function" && define.amd ) { if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define([ define( [
"jquery", "jquery",
"./mouse", "./mouse",
"../keycode", "../keycode",
@ -32,7 +32,7 @@
// Browser globals // Browser globals
factory( jQuery ); factory( jQuery );
} }
}(function( $ ) { }( function( $ ) {
return $.widget( "ui.slider", $.ui.mouse, { return $.widget( "ui.slider", $.ui.mouse, {
version: "@VERSION", version: "@VERSION",
@ -117,9 +117,9 @@ return $.widget( "ui.slider", $.ui.mouse, {
this.handle = this.handles.eq( 0 ); this.handle = this.handles.eq( 0 );
this.handles.each(function( i ) { this.handles.each( function( i ) {
$( this ).data( "ui-slider-handle-index", i ); $( this ).data( "ui-slider-handle-index", i );
}); } );
}, },
_createRange: function() { _createRange: function() {
@ -130,9 +130,9 @@ return $.widget( "ui.slider", $.ui.mouse, {
if ( !options.values ) { if ( !options.values ) {
options.values = [ this._valueMin(), this._valueMin() ]; options.values = [ this._valueMin(), this._valueMin() ];
} else if ( options.values.length && options.values.length !== 2 ) { } else if ( options.values.length && options.values.length !== 2 ) {
options.values = [ options.values[0], options.values[0] ]; options.values = [ options.values[ 0 ], options.values[ 0 ] ];
} else if ( $.isArray( options.values ) ) { } else if ( $.isArray( options.values ) ) {
options.values = options.values.slice(0); options.values = options.values.slice( 0 );
} }
} }
@ -145,10 +145,10 @@ return $.widget( "ui.slider", $.ui.mouse, {
this._removeClass( this.range, "ui-slider-range-min ui-slider-range-max" ); this._removeClass( this.range, "ui-slider-range-min ui-slider-range-max" );
// Handle range switching from true to min/max // Handle range switching from true to min/max
this.range.css({ this.range.css( {
"left": "", "left": "",
"bottom": "" "bottom": ""
}); } );
} }
if ( options.range === "min" || options.range === "max" ) { if ( options.range === "min" || options.range === "max" ) {
this._addClass( this.range, "ui-slider-range-" + options.range ); this._addClass( this.range, "ui-slider-range-" + options.range );
@ -195,16 +195,16 @@ return $.widget( "ui.slider", $.ui.mouse, {
position = { x: event.pageX, y: event.pageY }; position = { x: event.pageX, y: event.pageY };
normValue = this._normValueFromMouse( position ); normValue = this._normValueFromMouse( position );
distance = this._valueMax() - this._valueMin() + 1; distance = this._valueMax() - this._valueMin() + 1;
this.handles.each(function( i ) { this.handles.each( function( i ) {
var thisDistance = Math.abs( normValue - that.values(i) ); var thisDistance = Math.abs( normValue - that.values( i ) );
if (( distance > thisDistance ) || if ( ( distance > thisDistance ) ||
( distance === thisDistance && ( distance === thisDistance &&
(i === that._lastChangedValue || that.values(i) === o.min ))) { ( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) {
distance = thisDistance; distance = thisDistance;
closestHandle = $( this ); closestHandle = $( this );
index = i; index = i;
} }
}); } );
allowed = this._start( event, index ); allowed = this._start( event, index );
if ( allowed === false ) { if ( allowed === false ) {
@ -223,9 +223,9 @@ return $.widget( "ui.slider", $.ui.mouse, {
left: event.pageX - offset.left - ( closestHandle.width() / 2 ), left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
top: event.pageY - offset.top - top: event.pageY - offset.top -
( closestHandle.height() / 2 ) - ( closestHandle.height() / 2 ) -
( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) - ( parseInt( closestHandle.css( "borderTopWidth" ), 10 ) || 0 ) -
( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) + ( parseInt( closestHandle.css( "borderBottomWidth" ), 10 ) || 0 ) +
( parseInt( closestHandle.css("marginTop"), 10 ) || 0) ( parseInt( closestHandle.css( "marginTop" ), 10 ) || 0 )
}; };
if ( !this.handles.hasClass( "ui-state-hover" ) ) { if ( !this.handles.hasClass( "ui-state-hover" ) ) {
@ -361,6 +361,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
_change: function( event, index ) { _change: function( event, index ) {
if ( !this._keySliding && !this._mouseSliding ) { if ( !this._keySliding && !this._mouseSliding ) {
//store the last changed value index for reference when handles overlap //store the last changed value index for reference when handles overlap
this._lastChangedValue = index; this._lastChangedValue = index;
this._trigger( "change", event, this._uiHash( index ) ); this._trigger( "change", event, this._uiHash( index ) );
@ -503,10 +504,11 @@ return $.widget( "ui.slider", $.ui.mouse, {
return val; return val;
} else if ( this._hasMultipleValues() ) { } else if ( this._hasMultipleValues() ) {
// .slice() creates a copy of the array // .slice() creates a copy of the array
// this copy gets trimmed by min and max and then returned // this copy gets trimmed by min and max and then returned
vals = this.options.values.slice(); vals = this.options.values.slice();
for ( i = 0; i < vals.length; i += 1) { for ( i = 0; i < vals.length; i += 1 ) {
vals[ i ] = this._trimAlignValue( vals[ i ] ); vals[ i ] = this._trimAlignValue( vals[ i ] );
} }
@ -525,16 +527,16 @@ return $.widget( "ui.slider", $.ui.mouse, {
return this._valueMax(); return this._valueMax();
} }
var step = ( this.options.step > 0 ) ? this.options.step : 1, var step = ( this.options.step > 0 ) ? this.options.step : 1,
valModStep = (val - this._valueMin()) % step, valModStep = ( val - this._valueMin() ) % step,
alignValue = val - valModStep; alignValue = val - valModStep;
if ( Math.abs(valModStep) * 2 >= step ) { if ( Math.abs( valModStep ) * 2 >= step ) {
alignValue += ( valModStep > 0 ) ? step : ( -step ); alignValue += ( valModStep > 0 ) ? step : ( -step );
} }
// Since JavaScript has problems with large floats, round // Since JavaScript has problems with large floats, round
// the final value to 5 digits after the decimal point (see #4124) // the final value to 5 digits after the decimal point (see #4124)
return parseFloat( alignValue.toFixed(5) ); return parseFloat( alignValue.toFixed( 5 ) );
}, },
_calculateNewMax: function() { _calculateNewMax: function() {
@ -568,7 +570,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
return this.max; return this.max;
}, },
_refreshRange: function ( orientation ) { _refreshRange: function( orientation ) {
if ( orientation === "vertical" ) { if ( orientation === "vertical" ) {
this.range.css( { "width": "", "left": "" } ); this.range.css( { "width": "", "left": "" } );
} }
@ -586,8 +588,8 @@ return $.widget( "ui.slider", $.ui.mouse, {
_set = {}; _set = {};
if ( this._hasMultipleValues() ) { if ( this._hasMultipleValues() ) {
this.handles.each(function( i ) { this.handles.each( function( i ) {
valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; valPercent = ( that.values( i ) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100;
_set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
$( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
if ( that.options.range === true ) { if ( that.options.range === true ) {
@ -608,7 +610,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
} }
} }
lastValPercent = valPercent; lastValPercent = valPercent;
}); } );
} else { } else {
value = this.value(); value = this.value();
valueMin = this._valueMin(); valueMin = this._valueMin();
@ -681,7 +683,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
break; break;
case $.ui.keyCode.PAGE_DOWN: case $.ui.keyCode.PAGE_DOWN:
newVal = this._trimAlignValue( newVal = this._trimAlignValue(
curVal - ( (this._valueMax() - this._valueMin()) / this.numPages ) ); curVal - ( ( this._valueMax() - this._valueMin() ) / this.numPages ) );
break; break;
case $.ui.keyCode.UP: case $.ui.keyCode.UP:
case $.ui.keyCode.RIGHT: case $.ui.keyCode.RIGHT:
@ -712,6 +714,6 @@ return $.widget( "ui.slider", $.ui.mouse, {
} }
} }
} }
}); } );
})); } ) );