mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Draggable: Shift to use no globals
This commit is contained in:
parent
86fd11d5a7
commit
46f607af97
@ -31,7 +31,7 @@ common.testWidget( "draggable", {
|
||||
stack: false,
|
||||
zIndex: false,
|
||||
|
||||
//todo: remove the following option checks when interactions are rewritten:
|
||||
//Todo: remove the following option checks when interactions are rewritten:
|
||||
addClasses: true,
|
||||
delay: 0,
|
||||
distance: 1,
|
||||
|
@ -1,14 +1,15 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"./helper",
|
||||
"ui/widgets/draggable",
|
||||
"ui/widgets/droppable",
|
||||
"ui/widgets/resizable"
|
||||
], function( $, testHelper ) {
|
||||
], function( QUnit, $, testHelper ) {
|
||||
|
||||
module( "draggable: core" );
|
||||
QUnit.module( "draggable: core" );
|
||||
|
||||
test( "element types", function( assert ) {
|
||||
QUnit.test( "element types", function( assert ) {
|
||||
var typeNames = (
|
||||
"p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
|
||||
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
|
||||
@ -16,7 +17,7 @@ test( "element types", function( assert ) {
|
||||
",input,button,label,select,iframe"
|
||||
).split( "," );
|
||||
|
||||
expect( typeNames.length * 2 );
|
||||
assert.expect( typeNames.length * 2 );
|
||||
|
||||
$.each( typeNames, function( i ) {
|
||||
var offsetBefore, offsetAfter,
|
||||
@ -44,18 +45,18 @@ test( "element types", function( assert ) {
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "No options, relative", function() {
|
||||
expect( 2 );
|
||||
testHelper.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" );
|
||||
QUnit.test( "No options, relative", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
testHelper.shouldMove( assert, $( "#draggable1" ).draggable(), "no options, relative" );
|
||||
} );
|
||||
|
||||
test( "No options, absolute", function() {
|
||||
expect( 2 );
|
||||
testHelper.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" );
|
||||
QUnit.test( "No options, absolute", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
testHelper.shouldMove( assert, $( "#draggable2" ).draggable(), "no options, absolute" );
|
||||
} );
|
||||
|
||||
test( "resizable handle with complex markup (#8756 / #8757)", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "resizable handle with complex markup (#8756 / #8757)", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
$( "#draggable1" )
|
||||
.append(
|
||||
@ -69,19 +70,19 @@ test( "resizable handle with complex markup (#8756 / #8757)", function() {
|
||||
|
||||
// Todo: fix resizable so it doesn't require a mouseover
|
||||
handle.simulate( "mouseover" ).simulate( "drag", { dx: -50 } );
|
||||
equal( target.width(), 250, "compare width" );
|
||||
assert.equal( target.width(), 250, "compare width" );
|
||||
|
||||
// Todo: fix resizable so it doesn't require a mouseover
|
||||
handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } );
|
||||
equal( target.width(), 200, "compare width" );
|
||||
assert.equal( target.width(), 200, "compare width" );
|
||||
} );
|
||||
|
||||
test( "#8269: Removing draggable element on drop", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "#8269: Removing draggable element on drop", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
|
||||
stop: function() {
|
||||
ok( true, "stop still called despite element being removed from DOM on drop" );
|
||||
assert.ok( true, "stop still called despite element being removed from DOM on drop" );
|
||||
}
|
||||
} ),
|
||||
dropOffset = $( "#droppable" ).offset();
|
||||
@ -89,14 +90,14 @@ test( "#8269: Removing draggable element on drop", function() {
|
||||
$( "#droppable" ).droppable( {
|
||||
drop: function() {
|
||||
$( "#wrapper" ).remove();
|
||||
ok( true, "element removed from DOM on drop" );
|
||||
assert.ok( true, "element removed from DOM on drop" );
|
||||
}
|
||||
} );
|
||||
|
||||
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
|
||||
if ( testHelper.unreliableContains ) {
|
||||
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
||||
ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
||||
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
||||
assert.ok( true, "Opera <12.14 and Safari <6.0 report wrong values for $.contains in jQuery < 1.8" );
|
||||
} else {
|
||||
element.simulate( "drag", {
|
||||
handle: "corner",
|
||||
@ -108,8 +109,8 @@ test( "#8269: Removing draggable element on drop", function() {
|
||||
|
||||
// http://bugs.jqueryui.com/ticket/7778
|
||||
// drag element breaks in IE8 when its content is replaced onmousedown
|
||||
test( "Stray mousemove after mousedown still drags", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "Stray mousemove after mousedown still drags", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#draggable1" ).draggable( { scroll: false } );
|
||||
|
||||
@ -120,16 +121,16 @@ test( "Stray mousemove after mousedown still drags", function() {
|
||||
$( document ).simulate( "mousemove", { button: -1 } );
|
||||
} );
|
||||
|
||||
testHelper.shouldMove( element, "element is draggable" );
|
||||
testHelper.shouldMove( assert, element, "element is draggable" );
|
||||
} );
|
||||
|
||||
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#draggable1" ).draggable( {
|
||||
stop: function( event, ui ) {
|
||||
equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
|
||||
equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
|
||||
assert.equal( ui.position.left, 1, "left position is correct despite overflow on HTML" );
|
||||
assert.equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
|
||||
$( "html" )
|
||||
.css( "overflow-y", oldOverflowY )
|
||||
.css( "overflow-x", oldOverflowX )
|
||||
@ -155,13 +156,13 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "#9315: jumps down with offset of scrollbar", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "#9315: jumps down with offset of scrollbar", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#draggable2" ).draggable( {
|
||||
stop: function( event, ui ) {
|
||||
equal( ui.position.left, 11, "left position is correct when position is absolute" );
|
||||
equal( ui.position.top, 11, "top position is correct when position is absolute" );
|
||||
assert.equal( ui.position.left, 11, "left position is correct when position is absolute" );
|
||||
assert.equal( ui.position.top, 11, "top position is correct when position is absolute" );
|
||||
$( "html" ).scrollTop( 0 ).scrollLeft( 0 );
|
||||
}
|
||||
} );
|
||||
@ -177,8 +178,8 @@ test( "#9315: jumps down with offset of scrollbar", function() {
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "scroll offset with fixed ancestors", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "scroll offset with fixed ancestors", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var startValue = 300,
|
||||
element = $( "#draggable1" )
|
||||
@ -196,8 +197,8 @@ test( "scroll offset with fixed ancestors", function() {
|
||||
$( document ).scrollTop( startValue ).scrollLeft( startValue );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
|
||||
equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
|
||||
assert.equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
|
||||
assert.equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
|
||||
$( document ).scrollTop( 0 ).scrollLeft( 0 );
|
||||
}
|
||||
} );
|
||||
@ -219,8 +220,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() {
|
||||
|
||||
// Http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div
|
||||
// http://bugs.jqueryui.com/ticket/10147 - Wrong position in a parent with "overflow: hidden"
|
||||
test( "position in scrollable parent with overflow: " + overflow, function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "position in scrollable parent with overflow: " + overflow, function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
$( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
|
||||
$( "#inner" ).css( { position: "absolute", width: "500px", height: "500px" } );
|
||||
@ -240,8 +241,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() {
|
||||
$( "#outer" ).scrollTop( startValue ).scrollLeft( startValue );
|
||||
},
|
||||
stop: function( event, ui ) {
|
||||
equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
|
||||
equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
|
||||
assert.equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" );
|
||||
assert.equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
|
||||
}
|
||||
} );
|
||||
|
||||
@ -255,8 +256,8 @@ $( [ "hidden", "auto", "scroll" ] ).each( function() {
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "#5727: draggable from iframe", function() {
|
||||
expect( 1 );
|
||||
QUnit.test( "#5727: draggable from iframe", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var iframeBody, draggable1,
|
||||
iframe = $( "<iframe />" ).appendTo( "#qunit-fixture" ),
|
||||
@ -270,53 +271,55 @@ test( "#5727: draggable from iframe", function() {
|
||||
|
||||
draggable1.draggable();
|
||||
|
||||
equal( draggable1.closest( iframeBody ).length, 1 );
|
||||
assert.equal( draggable1.closest( iframeBody ).length, 1 );
|
||||
|
||||
// TODO: fix draggable within an IFRAME to fire events on the element properly
|
||||
// and these testHelper.shouldMove relies on events for testing
|
||||
//testHelper.shouldMove( draggable1, "draggable from an iframe" );
|
||||
//testHelper.shouldMove( assert, draggable1, "draggable from an iframe" );
|
||||
} );
|
||||
|
||||
test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "<a href='#'>link</a>" ).appendTo( "#qunit-fixture" ).draggable();
|
||||
|
||||
$( document ).one( "mousemove", function() {
|
||||
notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
|
||||
assert.notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
|
||||
} );
|
||||
|
||||
testHelper.move( element, 50, 50 );
|
||||
|
||||
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
|
||||
assert.strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
|
||||
} );
|
||||
|
||||
asyncTest( "blur behavior - handle is main element", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "blur behavior - handle is main element", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 3 );
|
||||
|
||||
var element = $( "#draggable1" ).draggable(),
|
||||
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
|
||||
|
||||
testHelper.onFocus( focusElement, function() {
|
||||
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
||||
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
||||
|
||||
testHelper.move( focusElement, 1, 1 );
|
||||
|
||||
// Http://bugs.jqueryui.com/ticket/10527
|
||||
// Draggable: Can't select option in modal dialog (IE8)
|
||||
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" );
|
||||
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused after mousing down on itself" );
|
||||
|
||||
testHelper.move( element, 50, 50 );
|
||||
|
||||
// Http://bugs.jqueryui.com/ticket/4261
|
||||
// active element should blur when mousing down on a draggable
|
||||
notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
|
||||
start();
|
||||
assert.notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
asyncTest( "blur behavior - descendant of handle", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "blur behavior - descendant of handle", function( assert ) {
|
||||
var ready = assert.async();
|
||||
assert.expect( 2 );
|
||||
|
||||
var element = $( "#draggable2" ).draggable( { handle: "span" } ),
|
||||
|
||||
@ -325,18 +328,18 @@ asyncTest( "blur behavior - descendant of handle", function() {
|
||||
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
|
||||
|
||||
testHelper.onFocus( focusElement, function() {
|
||||
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
||||
assert.strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
|
||||
|
||||
testHelper.move( handle, 50, 50 );
|
||||
|
||||
// Elements outside of the handle should blur (#12472, #14905)
|
||||
notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
|
||||
start();
|
||||
assert.notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
|
||||
ready();
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "ui-draggable-handle assigned to appropriate element", function( assert ) {
|
||||
expect( 5 );
|
||||
QUnit.test( "ui-draggable-handle assigned to appropriate element", function( assert ) {
|
||||
assert.expect( 5 );
|
||||
|
||||
var p = $( "<p>" ).appendTo( "#qunit-fixture" ),
|
||||
element = $( "<div><p></p></div>" ).appendTo( "#qunit-fixture" ).draggable();
|
||||
@ -352,8 +355,8 @@ test( "ui-draggable-handle assigned to appropriate element", function( assert )
|
||||
assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" );
|
||||
} );
|
||||
|
||||
test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
|
||||
expect( 4 );
|
||||
QUnit.test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
var parent = $( "<div><div></div></div>" ).draggable().appendTo( "#qunit-fixture" ),
|
||||
child = parent.find( "div" ).draggable();
|
||||
|
||||
@ -371,7 +374,7 @@ test( "ui-draggable-handle managed correctly in nested draggables", function( as
|
||||
QUnit[ document.documentMode === 8 ? "skip" : "test" ](
|
||||
"does not stop propagation to window",
|
||||
function( assert ) {
|
||||
expect( 1 );
|
||||
assert.expect( 1 );
|
||||
var element = $( "#draggable1" ).draggable();
|
||||
|
||||
var handler = function() {
|
||||
|
@ -1,21 +1,22 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/draggable"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
var element;
|
||||
|
||||
module( "draggable: events", {
|
||||
setup: function() {
|
||||
QUnit.module( "draggable: events", {
|
||||
beforeEach: function() {
|
||||
element = $( "<div>" ).appendTo( "#qunit-fixture" );
|
||||
},
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
element.draggable( "destroy" );
|
||||
}
|
||||
} );
|
||||
|
||||
test( "callbacks occurrence count", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "callbacks occurrence count", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
var start = 0,
|
||||
stop = 0,
|
||||
@ -38,13 +39,13 @@ test( "callbacks occurrence count", function() {
|
||||
dy: 10
|
||||
} );
|
||||
|
||||
equal( start, 1, "start callback should happen exactly once" );
|
||||
equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
|
||||
equal( stop, 1, "stop callback should happen exactly once" );
|
||||
assert.equal( start, 1, "start callback should happen exactly once" );
|
||||
assert.equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
|
||||
assert.equal( stop, 1, "stop callback should happen exactly once" );
|
||||
} );
|
||||
|
||||
test( "stopping the start callback", function() {
|
||||
expect( 3 );
|
||||
QUnit.test( "stopping the start callback", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
var start = 0,
|
||||
stop = 0,
|
||||
@ -68,13 +69,13 @@ test( "stopping the start callback", function() {
|
||||
dy: 10
|
||||
} );
|
||||
|
||||
equal( start, 1, "start callback should happen exactly once" );
|
||||
equal( dragc, 0, "drag callback should not happen at all" );
|
||||
equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
|
||||
assert.equal( start, 1, "start callback should happen exactly once" );
|
||||
assert.equal( dragc, 0, "drag callback should not happen at all" );
|
||||
assert.equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
|
||||
} );
|
||||
|
||||
test( "stopping the drag callback", function() {
|
||||
expect( 2 );
|
||||
QUnit.test( "stopping the drag callback", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var start = 0,
|
||||
stop = 0,
|
||||
@ -98,12 +99,12 @@ test( "stopping the drag callback", function() {
|
||||
dy: 10
|
||||
} );
|
||||
|
||||
equal( start, 1, "start callback should happen exactly once" );
|
||||
equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
|
||||
assert.equal( start, 1, "start callback should happen exactly once" );
|
||||
assert.equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
|
||||
} );
|
||||
|
||||
test( "stopping the stop callback", function() {
|
||||
expect( 1 );
|
||||
QUnit.test( "stopping the stop callback", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
element.draggable( {
|
||||
helper: "clone",
|
||||
@ -117,13 +118,13 @@ test( "stopping the stop callback", function() {
|
||||
dy: 10
|
||||
} );
|
||||
|
||||
ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
|
||||
assert.ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
|
||||
} );
|
||||
|
||||
// http://bugs.jqueryui.com/ticket/6884
|
||||
// Draggable: ui.offset.left differs between the "start" and "drag" hooks
|
||||
test( "position and offset in hash is consistent between start, drag, and stop", function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "position and offset in hash is consistent between start, drag, and stop", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
var startPos, startOffset, dragPos, dragOffset, stopPos, stopOffset;
|
||||
|
||||
@ -155,10 +156,10 @@ test( "position and offset in hash is consistent between start, drag, and stop",
|
||||
startOffset.left += 10;
|
||||
startOffset.top += 10;
|
||||
|
||||
deepEqual( startPos, dragPos, "start position equals drag position plus distance" );
|
||||
deepEqual( dragPos, stopPos, "drag position equals stop position" );
|
||||
deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" );
|
||||
deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
|
||||
assert.deepEqual( startPos, dragPos, "start position equals drag position plus distance" );
|
||||
assert.deepEqual( dragPos, stopPos, "drag position equals stop position" );
|
||||
assert.deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" );
|
||||
assert.deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
|
||||
} );
|
||||
|
||||
} );
|
||||
|
@ -1,8 +1,9 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"lib/helper",
|
||||
"ui/widgets/draggable"
|
||||
], function( $, helper ) {
|
||||
], function( QUnit, $, helper ) {
|
||||
|
||||
return $.extend( helper, {
|
||||
|
||||
@ -16,40 +17,40 @@ return $.extend( helper, {
|
||||
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
|
||||
} )(),
|
||||
|
||||
testDragPosition: function( el, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
testDragPosition: function( assert, el, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
msg = msg ? msg + "." : "";
|
||||
|
||||
$( el ).one( "dragstop", function( event, ui ) {
|
||||
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
|
||||
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
|
||||
assert.deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
|
||||
} );
|
||||
},
|
||||
|
||||
testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
testDragOffset: function( assert, el, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
msg = msg ? msg + "." : "";
|
||||
|
||||
var offsetBefore = el.offset(),
|
||||
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
||||
|
||||
$( el ).one( "dragstop", function( event, ui ) {
|
||||
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
||||
assert.deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
||||
} );
|
||||
},
|
||||
|
||||
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
testDragHelperOffset: function( assert, el, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
msg = msg ? msg + "." : "";
|
||||
|
||||
var offsetBefore = el.offset(),
|
||||
offsetExpected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY };
|
||||
|
||||
$( el ).one( "dragstop", function( event, ui ) {
|
||||
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
||||
assert.deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
|
||||
} );
|
||||
},
|
||||
|
||||
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
this.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
|
||||
this.testDragOffset( el, dx, dy, expectedDX, expectedDY, msg );
|
||||
testDrag: function( assert, el, handle, dx, dy, expectedDX, expectedDY, msg ) {
|
||||
this.testDragPosition( assert, el, dx, dy, expectedDX, expectedDY, msg );
|
||||
this.testDragOffset( assert, el, dx, dy, expectedDX, expectedDY, msg );
|
||||
|
||||
$( handle ).simulate( "drag", {
|
||||
dx: dx,
|
||||
@ -57,10 +58,10 @@ return $.extend( helper, {
|
||||
} );
|
||||
},
|
||||
|
||||
shouldMovePositionButNotOffset: function( el, msg, handle ) {
|
||||
shouldMovePositionButNotOffset: function( assert, el, msg, handle ) {
|
||||
handle = handle || el;
|
||||
this.testDragPosition( el, 100, 100, 100, 100, msg );
|
||||
this.testDragHelperOffset( el, 100, 100, 0, 0, msg );
|
||||
this.testDragPosition( assert, el, 100, 100, 100, 100, msg );
|
||||
this.testDragHelperOffset( assert, el, 100, 100, 0, 0, msg );
|
||||
|
||||
$( handle ).simulate( "drag", {
|
||||
dx: 100,
|
||||
@ -68,17 +69,17 @@ return $.extend( helper, {
|
||||
} );
|
||||
},
|
||||
|
||||
shouldMove: function( el, msg, handle ) {
|
||||
shouldMove: function( assert, el, msg, handle ) {
|
||||
handle = handle || el;
|
||||
this.testDrag( el, handle, 100, 100, 100, 100, msg );
|
||||
this.testDrag( assert, el, handle, 100, 100, 100, 100, msg );
|
||||
},
|
||||
|
||||
shouldNotMove: function( el, msg, handle ) {
|
||||
shouldNotMove: function( assert, el, msg, handle ) {
|
||||
handle = handle || el;
|
||||
this.testDrag( el, handle, 100, 100, 0, 0, msg );
|
||||
this.testDrag( assert, el, handle, 100, 100, 0, 0, msg );
|
||||
},
|
||||
|
||||
shouldNotDrag: function( el, msg, handle ) {
|
||||
shouldNotDrag: function( assert, el, msg, handle ) {
|
||||
handle = handle || el;
|
||||
|
||||
var newOffset,
|
||||
@ -86,7 +87,7 @@ return $.extend( helper, {
|
||||
beginOffset = element.offset();
|
||||
|
||||
element.on( "dragstop", function() {
|
||||
ok( false, "should not drag " + msg );
|
||||
assert.ok( false, "should not drag " + msg );
|
||||
} );
|
||||
|
||||
$( handle ).simulate( "drag", {
|
||||
@ -98,8 +99,8 @@ return $.extend( helper, {
|
||||
|
||||
// Also assert that draggable did not move, to ensure it isn't just
|
||||
// that drag did not fire and draggable still somehow moved
|
||||
equal( newOffset.left, beginOffset.left, "Offset left should not be different" );
|
||||
equal( newOffset.top, beginOffset.top, "Offset top should not be different" );
|
||||
assert.equal( newOffset.left, beginOffset.left, "Offset left should not be different" );
|
||||
assert.equal( newOffset.top, beginOffset.top, "Offset top should not be different" );
|
||||
|
||||
element.off( "dragstop" );
|
||||
},
|
||||
@ -109,10 +110,10 @@ return $.extend( helper, {
|
||||
$( what ).css( { overflow: overflow, overflowX: overflow, overflowY: overflow } );
|
||||
},
|
||||
|
||||
testScroll: function( el, position ) {
|
||||
testScroll: function( assert, el, position ) {
|
||||
var oldPosition = $( "#main" ).css( "position" );
|
||||
$( "#main" ).css( { position: position, top: "0px", left: "0px" } );
|
||||
this.shouldMove( el, position + " parent" );
|
||||
this.shouldMove( assert, el, position + " parent" );
|
||||
$( "#main" ).css( "position", oldPosition );
|
||||
},
|
||||
|
||||
|
@ -1,104 +1,105 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"./helper",
|
||||
"ui/widgets/draggable"
|
||||
], function( $, testHelper ) {
|
||||
], function( QUnit, $, testHelper ) {
|
||||
|
||||
var element;
|
||||
|
||||
module( "draggable: methods", {
|
||||
setup: function() {
|
||||
QUnit.module( "draggable: methods", {
|
||||
beforeEach: function() {
|
||||
element = $( "<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>" ).appendTo( "#qunit-fixture" );
|
||||
},
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
element.remove();
|
||||
}
|
||||
} );
|
||||
|
||||
test( "init", function() {
|
||||
expect( 5 );
|
||||
QUnit.test( "init", function( assert ) {
|
||||
assert.expect( 5 );
|
||||
|
||||
element.draggable();
|
||||
ok( true, ".draggable() called on element" );
|
||||
assert.ok( true, ".draggable() called on element" );
|
||||
|
||||
$( [] ).draggable();
|
||||
ok( true, ".draggable() called on empty collection" );
|
||||
assert.ok( true, ".draggable() called on empty collection" );
|
||||
|
||||
$( "<div></div>" ).draggable();
|
||||
ok( true, ".draggable() called on disconnected DOMElement" );
|
||||
assert.ok( true, ".draggable() called on disconnected DOMElement" );
|
||||
|
||||
element.draggable( "option", "foo" );
|
||||
ok( true, "arbitrary option getter after init" );
|
||||
assert.ok( true, "arbitrary option getter after init" );
|
||||
|
||||
element.draggable( "option", "foo", "bar" );
|
||||
ok( true, "arbitrary option setter after init" );
|
||||
assert.ok( true, "arbitrary option setter after init" );
|
||||
} );
|
||||
|
||||
test( "destroy", function() {
|
||||
expect( 4 );
|
||||
QUnit.test( "destroy", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
element.draggable().draggable( "destroy" );
|
||||
ok( true, ".draggable('destroy') called on element" );
|
||||
assert.ok( true, ".draggable('destroy') called on element" );
|
||||
|
||||
$( [] ).draggable().draggable( "destroy" );
|
||||
ok( true, ".draggable('destroy') called on empty collection" );
|
||||
assert.ok( true, ".draggable('destroy') called on empty collection" );
|
||||
|
||||
element.draggable().draggable( "destroy" );
|
||||
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
|
||||
assert.ok( true, ".draggable('destroy') called on disconnected DOMElement" );
|
||||
|
||||
var expected = element.draggable(),
|
||||
actual = expected.draggable( "destroy" );
|
||||
equal( actual, expected, "destroy is chainable" );
|
||||
assert.equal( actual, expected, "destroy is chainable" );
|
||||
} );
|
||||
|
||||
test( "enable", function() {
|
||||
expect( 11 );
|
||||
QUnit.test( "enable", function( assert ) {
|
||||
assert.expect( 11 );
|
||||
|
||||
element.draggable( { disabled: true } );
|
||||
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
|
||||
testHelper.shouldNotDrag( assert, element, ".draggable({ disabled: true })" );
|
||||
|
||||
element.draggable( "enable" );
|
||||
testHelper.shouldMove( element, ".draggable('enable')" );
|
||||
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
|
||||
testHelper.shouldMove( assert, element, ".draggable('enable')" );
|
||||
assert.equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
|
||||
|
||||
element.draggable( "destroy" );
|
||||
element.draggable( { disabled: true } );
|
||||
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
|
||||
testHelper.shouldNotDrag( assert, element, ".draggable({ disabled: true })" );
|
||||
|
||||
element.draggable( "option", "disabled", false );
|
||||
equal( element.draggable( "option", "disabled" ), false, "disabled option setter" );
|
||||
testHelper.shouldMove( element, ".draggable('option', 'disabled', false)" );
|
||||
assert.equal( element.draggable( "option", "disabled" ), false, "disabled option setter" );
|
||||
testHelper.shouldMove( assert, element, ".draggable('option', 'disabled', false)" );
|
||||
|
||||
var expected = element.draggable(),
|
||||
actual = expected.draggable( "enable" );
|
||||
equal( actual, expected, "enable is chainable" );
|
||||
assert.equal( actual, expected, "enable is chainable" );
|
||||
} );
|
||||
|
||||
test( "disable", function( assert ) {
|
||||
expect( 14 );
|
||||
QUnit.test( "disable", function( assert ) {
|
||||
assert.expect( 14 );
|
||||
|
||||
element = $( "#draggable2" ).draggable( { disabled: false } );
|
||||
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
|
||||
testHelper.shouldMove( assert, element, ".draggable({ disabled: false })" );
|
||||
|
||||
element.draggable( "disable" );
|
||||
testHelper.shouldNotDrag( element, ".draggable('disable')" );
|
||||
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
|
||||
testHelper.shouldNotDrag( assert, element, ".draggable('disable')" );
|
||||
assert.equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
|
||||
|
||||
element.draggable( "destroy" );
|
||||
element.draggable( { disabled: false } );
|
||||
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
|
||||
testHelper.shouldMove( assert, element, ".draggable({ disabled: false })" );
|
||||
|
||||
element.draggable( "option", "disabled", true );
|
||||
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
|
||||
testHelper.shouldNotDrag( element, ".draggable('option', 'disabled', true)" );
|
||||
assert.equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
|
||||
testHelper.shouldNotDrag( assert, element, ".draggable('option', 'disabled', true)" );
|
||||
|
||||
assert.lacksClasses( element.draggable( "widget" ), "ui-state-disabled" );
|
||||
ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
|
||||
assert.ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
|
||||
assert.hasClasses( element.draggable( "widget" ), "ui-draggable-disabled" );
|
||||
|
||||
var expected = element.draggable(),
|
||||
actual = expected.draggable( "disable" );
|
||||
equal( actual, expected, "disable is chainable" );
|
||||
assert.equal( actual, expected, "disable is chainable" );
|
||||
} );
|
||||
|
||||
} );
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user