@@ -110,48 +110,6 @@ test( "input type should degrade to number when slider is created", function() {
deepEqual ( $ ( "#range-slider-up" ) . attr ( "type" ) , "number" ) ;
} ) ;
// generic switch test function
var sliderSwitchTest = function ( opts ) {
var slider = $ ( "#slider-switch" ) ,
handle = slider . siblings ( '.ui-slider-switch' ) . find ( 'a' ) ,
switchValues = {
'off' : 0 ,
'on' : 1
} ;
// One for the select and one for the aria-valuenow
expect ( opts . keyCodes . length * 2 ) ;
$ . each ( opts . keyCodes , function ( i , elem ) {
// reset the values
slider [ 0 ] . selectedIndex = switchValues [ opts . start ] ;
handle . attr ( { 'aria-valuenow' : opts . start } ) ;
// stub the keycode and trigger the event
$ . Event . prototype . keyCode = $ . mobile . keyCode [ elem ] ;
handle . trigger ( 'keydown' ) ;
deepEqual ( handle . attr ( 'aria-valuenow' ) , opts . finish , "handle value is " + opts . finish ) ;
deepEqual ( slider [ 0 ] . selectedIndex , switchValues [ opts . finish ] , "select input has correct index" ) ;
} ) ;
} ;
test ( "switch should select on with up, right, page up and end" , function ( ) {
sliderSwitchTest ( {
start : 'off' ,
finish : 'on' ,
keyCodes : [ 'UP' , 'RIGHT' , 'PAGE_UP' , 'END' ]
} ) ;
} ) ;
test ( "switch should select off with down, left, page down and home" , function ( ) {
sliderSwitchTest ( {
start : 'on' ,
finish : 'off' ,
keyCodes : [ 'DOWN' , 'LEFT' , 'PAGE_DOWN' , 'HOME' ]
} ) ;
} ) ;
test ( "onchange should not be called on create" , function ( ) {
equal ( onChangeCnt , 0 , "onChange should not have been called" ) ;
} ) ;
@@ -175,36 +133,6 @@ var createEvent = function( name, target, x, y ) {
return event ;
} ;
test ( "toggle switch should fire one change event when clicked" , function ( ) {
var control = $ ( "#slider-switch" ) ,
widget = control . data ( "mobile-slider" ) ,
slider = widget . slider ,
handle = widget . handle ,
changeCount = 0 ,
changeFunc = function ( e ) {
ok ( control [ 0 ] . selectedIndex !== currentValue , "change event should only be triggered if the value changes" ) ;
++ changeCount ;
} ,
event = null ,
offset = handle . offset ( ) ,
currentValue = control [ 0 ] . selectedIndex ;
control . bind ( "change" , changeFunc ) ;
// The toggle switch actually updates on mousedown and mouseup events, so we go through
// the motions of generating all the events that happen during a click to make sure that
// during all of those events, the value only changes once.
slider . trigger ( createEvent ( "mousedown" , handle [ 0 ] , offset . left + 10 , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "mouseup" , handle [ 0 ] , offset . left + 10 , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "click" , handle [ 0 ] , offset . left + 10 , offset . top + 10 ) ) ;
control . unbind ( "change" , changeFunc ) ;
ok ( control [ 0 ] . selectedIndex !== currentValue , "value did change" ) ;
deepEqual ( changeCount , 1 , "change event should be fired once during a click" ) ;
} ) ;
var assertLeftCSS = function ( obj , opts ) {
var integerLeft , compare , css , threshold ;
@@ -224,156 +152,6 @@ var assertLeftCSS = function( obj, opts ) {
}
} ;
asyncTest ( "toggle switch handle should snap in the old position if dragged less than half of the slider width, in the new position if dragged more than half of the slider width" , function ( ) {
var control = $ ( "#slider-switch" ) ,
widget = control . data ( "mobile-slider" ) ,
slider = widget . slider ,
handle = widget . handle ,
width = handle . width ( ) ,
offset = null ;
$ . testHelper . sequence ( [
function ( ) {
// initialize the switch
control . val ( 'on' ) . slider ( 'refresh' ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '100%' ,
pixels : handle . parent ( ) . css ( 'width' ) ,
message : 'handle starts on the right side'
} ) ;
// simulate dragging less than a half
offset = handle . offset ( ) ;
slider . trigger ( createEvent ( "mousedown" , handle [ 0 ] , offset . left + width - 10 , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "mousemove" , handle [ 0 ] , offset . left + width - 20 , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "mouseup" , handle [ 0 ] , offset . left + width - 20 , offset . top + 10 ) ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '100%' ,
pixels : handle . parent ( ) . css ( 'width' ) ,
message : 'handle ends on the right side'
} ) ;
// initialize the switch
control . val ( 'on' ) . slider ( 'refresh' ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '100%' ,
pixels : handle . parent ( ) . css ( 'width' ) ,
message : 'handle starts on the right side'
} ) ;
// simulate dragging more than a half
offset = handle . offset ( ) ;
slider . trigger ( createEvent ( "mousedown" , handle [ 0 ] , offset . left + 10 , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "mousemove" , handle [ 0 ] , offset . left - ( width / 2 + 10 ) , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "mouseup" , handle [ 0 ] , offset . left - ( width / 2 + 10 ) , offset . top + 10 ) ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '0%' ,
pixels : '0px' ,
message : 'handle ends on the left side'
} ) ;
start ( ) ;
}
] , 500 ) ;
} ) ;
asyncTest ( "toggle switch handle should not move if user is dragging and value is changed" , function ( ) {
var control = $ ( "#slider-switch" ) ,
widget = control . data ( "mobile-slider" ) ,
slider = widget . slider ,
handle = widget . handle ,
width = handle . width ( ) ,
offset = null ;
$ . testHelper . sequence ( [
function ( ) {
// initialize the switch
control . val ( 'on' ) . slider ( 'refresh' ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '100%' ,
pixels : handle . parent ( ) . css ( 'width' ) ,
message : 'handle starts on the right side'
} ) ;
// simulate dragging more than a half
offset = handle . offset ( ) ;
slider . trigger ( createEvent ( "mousedown" , handle [ 0 ] , offset . left + 10 , offset . top + 10 ) ) ;
slider . trigger ( createEvent ( "mousemove" , handle [ 0 ] , offset . left - ( width / 2 ) , offset . top + 10 ) ) ;
} ,
function ( ) {
var min , max ;
if ( handle . css ( 'left' ) . indexOf ( "%" ) > - 1 ) {
min = "0%" ;
max = "100%" ;
} else {
min = "0px" ;
max = handle . parent ( ) . css ( 'width' ) ;
}
notEqual ( handle . css ( 'left' ) , min , 'handle is not on the left side' ) ;
notEqual ( handle . css ( 'left' ) , max , 'handle is not on the right side' ) ;
// reset slider state so it is ready for other tests
slider . trigger ( createEvent ( "mouseup" , handle [ 0 ] , offset . left - ( width / 2 ) , offset . top + 10 ) ) ;
start ( ) ;
}
] , 500 ) ;
} ) ;
asyncTest ( "toggle switch should refresh when disabled" , function ( ) {
var control = $ ( "#slider-switch" ) ,
handle = control . data ( "mobile-slider" ) . handle ;
$ . testHelper . sequence ( [
function ( ) {
// set the initial value
control . val ( 'off' ) . slider ( 'refresh' ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '0%' ,
pixels : '0px' ,
message : 'handle starts on the left side'
} ) ;
// disable and change value
control . slider ( 'disable' ) ;
control . val ( 'on' ) . slider ( 'refresh' ) ;
} ,
function ( ) {
assertLeftCSS ( handle , {
percent : '100%' ,
pixels : handle . parent ( ) . css ( 'width' ) ,
message : 'handle ends on the right side'
} ) ;
// reset slider state so it is ready for other tests
control . slider ( 'enable' ) ;
start ( ) ;
}
] , 500 ) ;
} ) ;
asyncTest ( "drag should start only when clicked with left button" , function ( ) {
expect ( 5 ) ;