From e583a512d7cc66a2b3d0915db1b0164b9a0a710e Mon Sep 17 00:00:00 2001 From: Alexander Schmitz Date: Mon, 24 Aug 2015 08:58:09 -0400 Subject: [PATCH] Slider: Style updates Ref #14246 --- tests/unit/slider/common.js | 2 +- tests/unit/slider/core.js | 82 ++++++++++++++-------------- tests/unit/slider/events.js | 78 +++++++++++++-------------- tests/unit/slider/methods.js | 46 ++++++++-------- tests/unit/slider/options.js | 100 +++++++++++++++++------------------ ui/widgets/slider.js | 58 ++++++++++---------- 6 files changed, 185 insertions(+), 181 deletions(-) diff --git a/tests/unit/slider/common.js b/tests/unit/slider/common.js index 5cc3e66c5..df53cda4f 100644 --- a/tests/unit/slider/common.js +++ b/tests/unit/slider/common.js @@ -30,6 +30,6 @@ common.testWidget( "slider", { start: null, stop: null } -}); +} ); } ); diff --git a/tests/unit/slider/core.js b/tests/unit/slider/core.js index 7fdb8c68c..109c9e01a 100644 --- a/tests/unit/slider/core.js +++ b/tests/unit/slider/core.js @@ -14,7 +14,7 @@ module( "slider: core" ); test( "markup structure", function( assert ) { expect( 4 ); - var element = $( "
" ).slider({ range: true }), + var element = $( "
" ).slider( { range: true } ), handle = element.find( "span" ), range = element.find( "div" ); @@ -22,7 +22,7 @@ test( "markup structure", function( assert ) { assert.hasClasses( range, "ui-slider-range ui-widget-header" ); assert.hasClasses( handle[ 0 ], "ui-slider-handle" ); assert.hasClasses( handle[ 1 ], "ui-slider-handle" ); -}); +} ); test( "keydown HOME on handle sets value to min", function() { expect( 2 ); @@ -38,7 +38,7 @@ test( "keydown HOME on handle sets value to min", function() { element.slider( "value", 0 ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal(element.slider( "value" ), options.min ); + equal( element.slider( "value" ), options.min ); element.slider( "destroy" ); @@ -54,10 +54,10 @@ test( "keydown HOME on handle sets value to min", function() { element.slider( "value", 0 ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal(element.slider( "value" ), options.min) ; + equal( element.slider( "value" ), options.min ) ; element.slider( "destroy" ); -}); +} ); test( "keydown END on handle sets value to max", function() { expect( 2 ); @@ -73,7 +73,7 @@ test( "keydown END on handle sets value to max", function() { element.slider( "value", 0 ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal(element.slider( "value" ), options.max) ; + equal( element.slider( "value" ), options.max ) ; element.slider( "destroy" ); @@ -89,10 +89,10 @@ test( "keydown END on handle sets value to max", function() { element.slider( "value", 0 ); handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal(element.slider( "value" ), options.max ); + equal( element.slider( "value" ), options.max ); element.slider( "destroy" ); -}); +} ); test( "keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() { 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( "value", 70); + element.slider( "value", 70 ); 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 } ); - equal(element.slider( "value" ), 100); + equal( element.slider( "value" ), 100 ); element.slider( "destroy" ); - }); -}); + } ); +} ); test( "keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() { 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( "value", 30); + element.slider( "value", 30 ); 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 } ); - equal(element.slider( "value" ), 0 ); + equal( element.slider( "value" ), 0 ); element.slider( "destroy" ); - }); -}); + } ); +} ); test( "keydown UP on handle increases value by step, not greater than max", function() { expect( 4 ); @@ -151,15 +151,15 @@ test( "keydown UP on handle increases value by step, not greater than max", func orientation: "horizontal", step: 1 }; - element.slider(options); + element.slider( options ); element.slider( "value", options.max - options.step ); 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 } ); - equal(element.slider( "value" ), options.max ); + equal( element.slider( "value" ), options.max ); 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 ); 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 } ); - equal(element.slider( "value" ), options.max ); + equal( element.slider( "value" ), options.max ); element.slider( "destroy" ); -}); +} ); test( "keydown RIGHT on handle increases value by step, not greater than max", function() { expect( 4 ); @@ -192,15 +192,15 @@ test( "keydown RIGHT on handle increases value by step, not greater than max", f orientation: "horizontal", step: 1 }; - element.slider(options); + element.slider( options ); element.slider( "value", options.max - options.step ); 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 } ); - equal(element.slider( "value" ), options.max ); + equal( element.slider( "value" ), options.max ); 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 ); 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 } ); - equal(element.slider( "value" ), options.max ); + equal( element.slider( "value" ), options.max ); element.slider( "destroy" ); -}); +} ); test( "keydown DOWN on handle decreases value by step, not less than min", function() { 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 ); 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 } ); - equal(element.slider( "value" ), options.min ); + equal( element.slider( "value" ), options.min ); 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 ); 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 } ); - equal(element.slider( "value" ), options.min ); + equal( element.slider( "value" ), options.min ); element.slider( "destroy" ); -}); +} ); test( "keydown LEFT on handle decreases value by step, not less than min", function() { expect( 4 ); @@ -274,15 +274,15 @@ test( "keydown LEFT on handle decreases value by step, not less than min", funct orientation: "horizontal", step: 1 }; - element.slider(options); + element.slider( options ); element.slider( "value", options.min + options.step ); 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 } ); - equal(element.slider( "value" ), options.min ); + equal( element.slider( "value" ), options.min ); 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 ); 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 } ); - equal(element.slider( "value" ), options.min ); + equal( element.slider( "value" ), options.min ); element.slider( "destroy" ); -}); +} ); } ); diff --git a/tests/unit/slider/events.js b/tests/unit/slider/events.js index 0256a2093..2cf67b5fe 100644 --- a/tests/unit/slider/events.js +++ b/tests/unit/slider/events.js @@ -13,11 +13,11 @@ test( "mouse based interaction", function() { expect( 4 ); var element = $( "#slider1" ) - .slider({ + .slider( { start: function( event ) { equal( event.originalEvent.type, "mousedown", "start triggered by mousedown" ); }, - slide: function( event) { + slide: function( event ) { equal( event.originalEvent.type, "mousemove", "slider triggered by mousemove" ); }, stop: function( event ) { @@ -26,18 +26,18 @@ test( "mouse based interaction", function() { change: function( event ) { equal( event.originalEvent.type, "mouseup", "change triggered by mouseup" ); } - }); + } ); element.find( ".ui-slider-handle" ).eq( 0 ) .simulate( "drag", { dx: 10, dy: 10 } ); -}); +} ); test( "keyboard based interaction", function() { expect( 3 ); // Test keyup at end of handle slide (keyboard) var element = $( "#slider1" ) - .slider({ + .slider( { start: function( event ) { equal( event.originalEvent.type, "keydown", "start triggered by keydown" ); }, @@ -50,113 +50,113 @@ test( "keyboard based interaction", function() { change: function( event ) { equal( event.originalEvent.type, "keyup", "change triggered by keyup" ); } - }); + } ); element.find( ".ui-slider-handle" ).eq( 0 ) .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } ); -}); +} ); test( "programmatic event triggers", function() { expect( 6 ); // Test value method var element = $( "
" ) - .slider({ + .slider( { change: function() { ok( true, "change triggered by value method" ); } - }) + } ) .slider( "value", 0 ); // Test values method element = $( "
" ) - .slider({ + .slider( { values: [ 10, 20 ], change: function() { ok( true, "change triggered by values method" ); } - }) + } ) .slider( "values", [ 80, 90 ] ); // Test value option element = $( "
" ) - .slider({ + .slider( { change: function() { ok( true, "change triggered by value option" ); } - }) + } ) .slider( "option", "value", 0 ); // Test values option element = $( "
" ) - .slider({ + .slider( { values: [ 10, 20 ], change: function() { ok( true, "change triggered by values option" ); } - }) + } ) .slider( "option", "values", [ 80, 90 ] ); -}); +} ); test( "mouse based interaction part two: when handles overlap", function() { expect( 6 ); var element = $( "#slider1" ) - .slider({ + .slider( { values: [ 0, 0, 0 ], start: function( event, ui ) { equal( handles.index( ui.handle ), 2, "rightmost handle activated when overlapping at minimum (#3736)" ); } - }), + } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element.slider( "destroy" ); element = $( "#slider1" ) - .slider({ + .slider( { values: [ 10, 10, 10 ], max: 10, start: function( event, ui ) { equal( handles.index( ui.handle ), 0, "leftmost handle activated when overlapping at maximum" ); } - }), + } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); element.slider( "destroy" ); element = $( "#slider1" ) - .slider({ + .slider( { values: [ 19, 20 ] - }), + } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element.one( "slidestart", function( event, ui ) { equal( handles.index( ui.handle ), 0, "left handle activated if left was moved last" ); - }); + } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element.slider( "destroy" ); element = $( "#slider1" ) - .slider({ + .slider( { values: [ 19, 20 ] - }), + } ), handles = element.find( ".ui-slider-handle" ); handles.eq( 1 ).simulate( "drag", { dx: -10 } ); element.one( "slidestart", function( event, ui ) { equal( handles.index( ui.handle ), 1, "right handle activated if right was moved last (#3467)" ); - }); + } ); handles.eq( 0 ).simulate( "drag", { dx: 10 } ); element = $( "#slider1" ) - .slider({ + .slider( { range: true, min: 0, max: 100, values: [ 0, 50 ] - }), + } ), handles = element.find( ".ui-slider-handle" ); 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 ] } ); 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" ); -}); +} ); test( "event data", function() { expect( 6 ); @@ -175,7 +175,7 @@ test( "event data", function() { values = [ 8, 9, 7, 4 ], newValues = [ 8, 9, 7, 5 ], element = $( "#slider1" ) - .slider({ + .slider( { values: values, start: function( event, ui ) { deepEqual( ui, expectedUiHash, "passing ui to start event" ); @@ -189,7 +189,7 @@ test( "event data", function() { change: function( event, ui ) { deepEqual( ui, expectedChangedUiHash, "passing ui to change event" ); } - }), + } ), handles = element.find( ".ui-slider-handle" ), expectedUiHash = { handle: handles.eq( slideHandleIndex )[ 0 ], @@ -200,33 +200,33 @@ test( "event data", function() { expectedChangedUiHash = $.extend( {}, expectedUiHash, { values: newValues, value: newValues[ slideHandleIndex ] - }); + } ); handles.eq( slideHandleIndex ).simulate( "drag", { dx: 10 } ); element.slider( "destroy" ); - element = $( "#slider1" ).slider({ + element = $( "#slider1" ).slider( { min: 0, max: 100, value: 1, - slide: function ( event, ui ) { + slide: function( event, ui ) { equal( ui.value, 0, "should pass 0 value if slider reaches it" ); } - }); + } ); handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); element.slider( "destroy" ); - element = $( "#slider1" ).slider({ + element = $( "#slider1" ).slider( { min: 0, max: 100, 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" ); } - }); + } ); handles = element.find( ".ui-slider-handle" ); handles.eq( 0 ).simulate( "drag", { dx: -10 } ); -}); +} ); } ); diff --git a/tests/unit/slider/methods.js b/tests/unit/slider/methods.js index a4187bd7f..15b2e8726 100644 --- a/tests/unit/slider/methods.js +++ b/tests/unit/slider/methods.js @@ -6,7 +6,7 @@ define( [ module( "slider: methods" ); test( "init", function() { - expect(5); + expect( 5 ); $( "
" ).appendTo( "body" ).slider().remove(); ok( true, ".slider() called on element" ); @@ -24,65 +24,67 @@ test( "init", function() { $( "
" ).slider().slider( "option", "foo", "bar" ).remove(); ok( true, "arbitrary option setter after init" ); -}); +} ); test( "destroy", function( assert ) { expect( 1 ); assert.domEqual( "#slider1", function() { $( "#slider1" ).slider().slider( "destroy" ); - }); -}); + } ); +} ); test( "enable", function( assert ) { expect( 3 ); var element, expected = $( "
" ).slider(), actual = expected.slider( "enable" ); - equal(actual, expected, "enable is chainable" ); + equal( actual, expected, "enable is chainable" ); - element = $( "
" ).slider({ disabled: true }); + element = $( "
" ).slider( { disabled: true } ); assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" ); element.slider( "enable" ); assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" ); -}); +} ); test( "disable", function( assert ) { expect( 4 ); var element, expected = $( "
" ).slider(), actual = expected.slider( "disable" ); - equal(actual, expected, "disable is chainable" ); + equal( actual, expected, "disable is chainable" ); - element = $( "
" ).slider({ disabled: false }); + element = $( "
" ).slider( { disabled: false } ); assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" ); element.slider( "disable" ); 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" ); -}); +} ); test( "value", function() { expect( 19 ); - $( [ false, "min", "max" ] ).each(function() { - var element = $( "
" ).slider({ + $( [ false, "min", "max" ] ).each( function() { + var element = $( "
" ).slider( { range: this, value: 5 - }); + } ); 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" ); element.remove(); - }); - var element = $( "
" ).slider({ + } ); + var element = $( "
" ).slider( { min: -1, value: 0, max: 1 - }); + } ); + // min with value option vs value method element.slider( "option", "value", -2 ); 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", -2 ), element, "value method is chainable" ); equal( element.slider( "option", "value" ), -1, "value method set respects min" ); + // 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( "value" ), 1, "value method get respects max" ); equal( element.slider( "value", 2 ), element, "value method is chainable" ); @@ -94,20 +96,20 @@ test( "value", function() { value: 2, max: 2.4, step: 0.01 - }); + } ); element.slider( "option", "value", 2.4 ); equal( element.slider( "value" ), 2.4, "value is set to max with 0.01 step" ); - element = $( "
" ).slider({ + element = $( "
" ).slider( { value: 100, min: 10, max: 500, step: 50 - }); + } ); element.slider( "option", "value", 510 ); equal( element.slider( "value" ), 460, "value is restricted to maximum valid step" ); -}); +} ); //test( "values", function() { // ok(false, "missing test - untested code is broken code." ); diff --git a/tests/unit/slider/options.js b/tests/unit/slider/options.js index f6b61a2b3..031031cdc 100644 --- a/tests/unit/slider/options.js +++ b/tests/unit/slider/options.js @@ -11,18 +11,18 @@ function handle() { module( "slider: options" ); -test( "disabled", function( assert ){ +test( "disabled", function( assert ) { expect( 8 ); var count = 0; element = $( "#slider1" ).slider(); element.on( "slidestart", function() { count++; - }); + } ); // Enabled 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 } ); equal( count, 1, "slider moved" ); @@ -40,7 +40,7 @@ test( "disabled", function( assert ){ handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); equal( count, 2, "slider did not move" ); -}); +} ); test( "max", function() { 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" ); element.slider( "destroy" ); -}); +} ); test( "min", function() { expect( 2 ); @@ -106,7 +106,7 @@ test( "min", function() { ok( element.slider( "value" ) === options.min, "value method is contained by min" ); element.slider( "destroy" ); -}); +} ); test( "orientation", function( assert ) { expect( 14 ); @@ -126,7 +126,7 @@ test( "orientation", function( assert ) { assert.hasClasses( element, "ui-slider-horizontal" ); assert.lacksClasses( element, "ui-slider-vertical" ); 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" ) ; @@ -143,17 +143,17 @@ test( "orientation", function( assert ) { assert.hasClasses( element, "ui-slider-vertical" ); assert.lacksClasses( element, "ui-slider-horizontal" ); 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" ); newValue = 7; - rangeSize = 500 - (500 * newValue / 10); - element = $( "#slider2" ).slider({ + rangeSize = 500 - ( 500 * newValue / 10 ); + element = $( "#slider2" ).slider( { range: "max", min: 0, max: 10 - }); + } ); element.slider( "option", "value", newValue ); element.slider( "option", "orientation", "vertical" ); @@ -170,11 +170,11 @@ test( "orientation", function( assert ) { element.slider( "destroy" ); - element = $( "#slider2" ).slider({ + element = $( "#slider2" ).slider( { range: true, min: 0, max: 100 - }); + } ); element.slider( "option", { values: [ 60, 70 ] } ); notEqual( element.find( ".ui-slider-range " ).position().left, 0, "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" ); element.slider( "destroy" ); -}); +} ); //spec: http://wiki.jqueryui.com/Slider#specs // 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) test( "step", function() { expect( 9 ); - element = $( "
" ).slider({ + element = $( "
" ).slider( { min: 0, value: 0, step: 10, max: 100 - }); + } ); equal( element.slider( "value" ), 0 ); element.slider( "value", 1 ); @@ -210,12 +210,12 @@ test( "step", function() { element.slider( "value", 19 ); equal( element.slider( "value" ), 20 ); - element = $( "
" ).slider({ + element = $( "
" ).slider( { min: 0, value: 0, step: 20, max: 100 - }); + } ); element.slider( "value", 0 ); element.slider( "option", "value", 1 ); @@ -231,7 +231,7 @@ test( "step", function() { equal( element.slider( "value" ), 20 ); element.slider( "destroy" ); -}); +} ); //test( "value", function() { // 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 // property is preserved via multiple range elements, so updating options.values // of 1 slider updates options.values of all the others - var ranges = $([ + var ranges = $( [ document.createElement( "div" ), document.createElement( "div" ) - ]).slider({ + ] ).slider( { range: true, values: [ 25, 75 ] - }); + } ); notStrictEqual( ranges.eq( 0 ).slider( "instance" ).options.values, @@ -264,43 +264,43 @@ test( "values", function() { ranges.eq( 1 ).slider( "values", 0 ), "the values for multiple sliders should be different" ); -}); +} ); test( "range", function( assert ) { expect( 32 ); var range; // Min - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: "min", min: 1, max: 10, step: 1 - }); + } ); equal( element.find( ".ui-slider-handle" ).length, 1, "range min, one handle" ); equal( element.find( ".ui-slider-range-min" ).length, 1, "range min" ); element.slider( "destroy" ); // Max - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: "max", min: 1, max: 10, step: 1 - }); + } ); equal( element.find( ".ui-slider-handle" ).length, 1, "range max, one handle" ); equal( element.find( ".ui-slider-range-max" ).length, 1, "range max" ); element.slider( "destroy" ); // True - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: true, min: 1, max: 10, step: 1 - }); + } ); range = element.find( ".ui-slider-range" ); equal( element.find( ".ui-slider-handle" ).length, 2, "range true, two handles" ); @@ -308,12 +308,12 @@ test( "range", function( assert ) { element.slider( "destroy" ); // Change range from min to max - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: "min", min: 1, max: 10, 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-range-min" ).length, 0, "range switch from min to max" ); @@ -321,12 +321,12 @@ test( "range", function( assert ) { element.slider( "destroy" ); // Change range from max to min - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: "max", min: 1, max: 10, 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-range-max" ).length, 0, "range switch from max to min" ); @@ -334,53 +334,53 @@ test( "range", function( assert ) { element.slider( "destroy" ); // Change range from max to true - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: "max", min: 1, max: 10, 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-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.slider( "option", "value" ), 0 , "option value" ); - equal( element.slider( "value" ), 1 , "value" ); - deepEqual( element.slider( "option", "values" ), [1, 1], "option values" ); - deepEqual( element.slider( "values" ), [1, 1], "values" ); + equal( element.slider( "option", "value" ), 0, "option value" ); + equal( element.slider( "value" ), 1, "value" ); + deepEqual( element.slider( "option", "values" ), [ 1, 1 ], "option values" ); + deepEqual( element.slider( "values" ), [ 1, 1 ], "values" ); element.slider( "destroy" ); // Change range from true to min - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: true, min: 1, max: 10, 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-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.slider( "option", "value" ), 1, "value" ); - equal( element.slider( "value" ), 1 , "value" ); + equal( element.slider( "value" ), 1, "value" ); equal( element.slider( "option", "values" ), null, "values" ); - deepEqual( element.slider( "values" ), [] , "values" ); + deepEqual( element.slider( "values" ), [], "values" ); element.slider( "destroy" ); // Change range from true to false - element = $( "
" ).slider({ + element = $( "
" ).slider( { range: true, min: 1, max: 10, 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-range" ).length, 0, "range switch from true to false" ); - equal( element.slider( "option", "value" ), 0 , "option value" ); - equal( element.slider( "value" ), 1 , "value" ); - deepEqual( element.slider( "option", "values" ), [1, 1], "option values" ); - deepEqual( element.slider( "values" ), [1, 1], "values" ); + equal( element.slider( "option", "value" ), 0, "option value" ); + equal( element.slider( "value" ), 1, "value" ); + deepEqual( element.slider( "option", "values" ), [ 1, 1 ], "option values" ); + deepEqual( element.slider( "values" ), [ 1, 1 ], "values" ); element.slider( "destroy" ); -}); +} ); } ); diff --git a/ui/widgets/slider.js b/ui/widgets/slider.js index 792fa4da2..5c4f252d5 100644 --- a/ui/widgets/slider.js +++ b/ui/widgets/slider.js @@ -16,11 +16,11 @@ //>>css.structure: ../themes/base/slider.css //>>css.theme: ../themes/base/theme.css -(function( factory ) { +( function( factory ) { if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. - define([ + define( [ "jquery", "./mouse", "../keycode", @@ -32,7 +32,7 @@ // Browser globals factory( jQuery ); } -}(function( $ ) { +}( function( $ ) { return $.widget( "ui.slider", $.ui.mouse, { version: "@VERSION", @@ -117,9 +117,9 @@ return $.widget( "ui.slider", $.ui.mouse, { this.handle = this.handles.eq( 0 ); - this.handles.each(function( i ) { + this.handles.each( function( i ) { $( this ).data( "ui-slider-handle-index", i ); - }); + } ); }, _createRange: function() { @@ -130,9 +130,9 @@ return $.widget( "ui.slider", $.ui.mouse, { if ( !options.values ) { options.values = [ this._valueMin(), this._valueMin() ]; } 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 ) ) { - 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" ); // Handle range switching from true to min/max - this.range.css({ + this.range.css( { "left": "", "bottom": "" - }); + } ); } if ( options.range === "min" || options.range === "max" ) { 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 }; normValue = this._normValueFromMouse( position ); distance = this._valueMax() - this._valueMin() + 1; - this.handles.each(function( i ) { - var thisDistance = Math.abs( normValue - that.values(i) ); - if (( distance > thisDistance ) || + this.handles.each( function( i ) { + var thisDistance = Math.abs( normValue - that.values( i ) ); + if ( ( distance > thisDistance ) || ( distance === thisDistance && - (i === that._lastChangedValue || that.values(i) === o.min ))) { + ( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) { distance = thisDistance; closestHandle = $( this ); index = i; } - }); + } ); allowed = this._start( event, index ); if ( allowed === false ) { @@ -223,9 +223,9 @@ return $.widget( "ui.slider", $.ui.mouse, { left: event.pageX - offset.left - ( closestHandle.width() / 2 ), top: event.pageY - offset.top - ( closestHandle.height() / 2 ) - - ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) - - ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) + - ( parseInt( closestHandle.css("marginTop"), 10 ) || 0) + ( parseInt( closestHandle.css( "borderTopWidth" ), 10 ) || 0 ) - + ( parseInt( closestHandle.css( "borderBottomWidth" ), 10 ) || 0 ) + + ( parseInt( closestHandle.css( "marginTop" ), 10 ) || 0 ) }; if ( !this.handles.hasClass( "ui-state-hover" ) ) { @@ -361,6 +361,7 @@ return $.widget( "ui.slider", $.ui.mouse, { _change: function( event, index ) { if ( !this._keySliding && !this._mouseSliding ) { + //store the last changed value index for reference when handles overlap this._lastChangedValue = index; this._trigger( "change", event, this._uiHash( index ) ); @@ -503,10 +504,11 @@ return $.widget( "ui.slider", $.ui.mouse, { return val; } else if ( this._hasMultipleValues() ) { + // .slice() creates a copy of the array // this copy gets trimmed by min and max and then returned 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 ] ); } @@ -525,16 +527,16 @@ return $.widget( "ui.slider", $.ui.mouse, { return this._valueMax(); } var step = ( this.options.step > 0 ) ? this.options.step : 1, - valModStep = (val - this._valueMin()) % step, + valModStep = ( val - this._valueMin() ) % step, alignValue = val - valModStep; - if ( Math.abs(valModStep) * 2 >= step ) { + if ( Math.abs( valModStep ) * 2 >= step ) { alignValue += ( valModStep > 0 ) ? step : ( -step ); } // Since JavaScript has problems with large floats, round // the final value to 5 digits after the decimal point (see #4124) - return parseFloat( alignValue.toFixed(5) ); + return parseFloat( alignValue.toFixed( 5 ) ); }, _calculateNewMax: function() { @@ -568,7 +570,7 @@ return $.widget( "ui.slider", $.ui.mouse, { return this.max; }, - _refreshRange: function ( orientation ) { + _refreshRange: function( orientation ) { if ( orientation === "vertical" ) { this.range.css( { "width": "", "left": "" } ); } @@ -586,8 +588,8 @@ return $.widget( "ui.slider", $.ui.mouse, { _set = {}; if ( this._hasMultipleValues() ) { - this.handles.each(function( i ) { - valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; + this.handles.each( function( i ) { + valPercent = ( that.values( i ) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); if ( that.options.range === true ) { @@ -608,7 +610,7 @@ return $.widget( "ui.slider", $.ui.mouse, { } } lastValPercent = valPercent; - }); + } ); } else { value = this.value(); valueMin = this._valueMin(); @@ -681,7 +683,7 @@ return $.widget( "ui.slider", $.ui.mouse, { break; case $.ui.keyCode.PAGE_DOWN: newVal = this._trimAlignValue( - curVal - ( (this._valueMax() - this._valueMin()) / this.numPages ) ); + curVal - ( ( this._valueMax() - this._valueMin() ) / this.numPages ) ); break; case $.ui.keyCode.UP: case $.ui.keyCode.RIGHT: @@ -712,6 +714,6 @@ return $.widget( "ui.slider", $.ui.mouse, { } } } -}); +} ); -})); +} ) );