start: null,
stop: null
}
-});
+} );
} );
test( "markup structure", function( assert ) {
expect( 4 );
- var element = $( "<div>" ).slider({ range: true }),
+ var element = $( "<div>" ).slider( { range: true } ),
handle = element.find( "span" ),
range = element.find( "div" );
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 );
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" );
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 );
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" );
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 );
};
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 );
};
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 );
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" );
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 );
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" );
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 );
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" );
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 );
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" );
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" );
-});
+} );
} );
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 ) {
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" );
},
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 = $( "<div></div>" )
- .slider({
+ .slider( {
change: function() {
ok( true, "change triggered by value method" );
}
- })
+ } )
.slider( "value", 0 );
// Test values method
element = $( "<div></div>" )
- .slider({
+ .slider( {
values: [ 10, 20 ],
change: function() {
ok( true, "change triggered by values method" );
}
- })
+ } )
.slider( "values", [ 80, 90 ] );
// Test value option
element = $( "<div></div>" )
- .slider({
+ .slider( {
change: function() {
ok( true, "change triggered by value option" );
}
- })
+ } )
.slider( "option", "value", 0 );
// Test values option
element = $( "<div></div>" )
- .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 ] } );
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 );
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" );
change: function( event, ui ) {
deepEqual( ui, expectedChangedUiHash, "passing ui to change event" );
}
- }),
+ } ),
handles = element.find( ".ui-slider-handle" ),
expectedUiHash = {
handle: handles.eq( slideHandleIndex )[ 0 ],
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 } );
-});
+} );
} );
module( "slider: methods" );
test( "init", function() {
- expect(5);
+ expect( 5 );
$( "<div></div>" ).appendTo( "body" ).slider().remove();
ok( true, ".slider() called on element" );
$( "<div></div>" ).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 = $( "<div></div>" ).slider(),
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" );
element.slider( "enable" );
assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" );
-});
+} );
test( "disable", function( assert ) {
expect( 4 );
var element,
expected = $( "<div></div>" ).slider(),
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" );
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 = $( "<div></div>" ).slider({
+ $( [ false, "min", "max" ] ).each( function() {
+ var element = $( "<div></div>" ).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 = $( "<div></div>" ).slider({
+ } );
+ var element = $( "<div></div>" ).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" );
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 = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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." );
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" );
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal( count, 2, "slider did not move" );
-});
+} );
test( "max", function() {
expect( 5 );
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 );
ok( element.slider( "value" ) === options.min, "value method is contained by min" );
element.slider( "destroy" );
-});
+} );
test( "orientation", function( assert ) {
expect( 14 );
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" ) ;
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" );
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" );
"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 = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).slider( {
min: 0,
value: 0,
step: 10,
max: 100
- });
+ } );
equal( element.slider( "value" ), 0 );
element.slider( "value", 1 );
element.slider( "value", 19 );
equal( element.slider( "value" ), 20 );
- element = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).slider( {
min: 0,
value: 0,
step: 20,
max: 100
- });
+ } );
element.slider( "value", 0 );
element.slider( "option", "value", 1 );
equal( element.slider( "value" ), 20 );
element.slider( "destroy" );
-});
+} );
//test( "value", function() {
// ok(false, "missing test - untested code is broken code." );
// 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,
ranges.eq( 1 ).slider( "values", 0 ),
"the values for multiple sliders should be different"
);
-});
+} );
test( "range", function( assert ) {
expect( 32 );
var range;
// Min
- element = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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 = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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 = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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" );
element.slider( "destroy" );
// Change range from min to max
- element = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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" );
element.slider( "destroy" );
// Change range from max to min
- element = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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" );
element.slider( "destroy" );
// Change range from max to true
- element = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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 = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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 = $( "<div></div>" ).slider({
+ element = $( "<div></div>" ).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" );
-});
+} );
} );
//>>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",
// Browser globals
factory( jQuery );
}
-}(function( $ ) {
+}( function( $ ) {
return $.widget( "ui.slider", $.ui.mouse, {
version: "@VERSION",
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() {
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 );
}
}
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 );
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 ) {
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" ) ) {
_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 ) );
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 ] );
}
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() {
return this.max;
},
- _refreshRange: function ( orientation ) {
+ _refreshRange: function( orientation ) {
if ( orientation === "vertical" ) {
this.range.css( { "width": "", "left": "" } );
}
_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 ) {
}
}
lastValPercent = valPercent;
- });
+ } );
} else {
value = this.value();
valueMin = this._valueMin();
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:
}
}
}
-});
+} );
-}));
+} ) );