Merge commit '7f7c9b378f' as 'jquery-ui'

This commit is contained in:
Mark Schouten 2016-08-05 12:57:52 +02:00
commit 0115f4500d
629 changed files with 341074 additions and 0 deletions

View file

@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Draggable Test Suite</title>
<script src="../../../external/jquery/jquery.js"></script>
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
<link rel="stylesheet" href="../qunit-composite.css">
<script src="../../../external/qunit/qunit.js"></script>
<script src="../qunit-composite.js"></script>
<script src="../subsuite.js"></script>
<script>
testAllVersions( "draggable" );
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
</div>
</body>
</html>

View file

@ -0,0 +1,126 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Draggable Test Suite</title>
<script src="../../jquery.js"></script>
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
<style>
#main {
width: 1000px;
height: 1000px;
overflow: scroll;
overflow-x: scroll;
overflow-y: scroll;
position: relative;
left: 0;
top: 0;
}
#main-forceScrollable {
position: absolute;
left: 0;
top: 0;
width: 1100px;
height: 1100px;
}
#scrollParent {
width: 1200px;
height: 1200px;
position: relative;
left: 0;
top: 0;
overflow: hidden;
overflow-x: hidden;
overflow-y: hidden;
}
#scrollParent-forceScrollable {
position: absolute;
left: 0;
top: 0;
width: 1300px;
height: 1300px;
}
/* See #9077 */
#draggable3, #draggable4 {
z-index: 100;
}
.sortable {
position: relative;
top: 8000px;
left: 10px;
width: 300px;
padding: 0;
margin: 0;
border: 0;
}
.sortable li {
height: 100px;
padding: 0;
margin: 0;
border: 0;
list-style: none;
display: inline-block;
}
</style>
<script src="../../../external/qunit/qunit.js"></script>
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
<script>
TestHelpers.loadResources({
css: [ "core" ],
js: [
"ui/core.js",
"ui/widget.js",
"ui/mouse.js",
"ui/resizable.js",
"ui/draggable.js",
"ui/droppable.js",
"ui/sortable.js"
]
});
</script>
<script src="draggable_common.js"></script>
<script src="draggable_core.js"></script>
<script src="draggable_events.js"></script>
<script src="draggable_methods.js"></script>
<script src="draggable_options.js"></script>
<script src="draggable_test_helpers.js"></script>
<script src="../swarminject.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<div id="scrollParent">
<div id="main">
<div id="draggable1" style="background: green; width: 200px; height: 100px; position: relative; top: 0; left: 0;">Relative</div>
<div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span><em>Absolute</em></span></div>
<div id="draggable3" style="background: green; position: absolute; right: 5px; bottom: 5px; padding: 7px; border: 3px solid black;"><span><em>Absolute right-bottom</em></span></div>
<div id="droppable" style="background: green; width: 200px; height: 100px; position: absolute; top: 110px; left: 110px;"><span>Absolute</span></div>
<div id="main-forceScrollable"></div>
</div>
<div id="scrollParent-forceScrollable"></div>
</div>
<div style="width: 1px; height: 1000px;"></div>
<div style="position: absolute; width: 1px; height: 2000px;"></div>
<ul id="sortable" class="sortable">
<li id="draggableSortable">Item 0</li>
<li id="draggableSortable2">Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ul id="sortable2" class="sortable">
<li id="draggableSortableClone" class="sortable2Item">Item 0</li>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</body>
</html>

View file

@ -0,0 +1,40 @@
TestHelpers.commonWidgetTests( "draggable", {
defaults: {
appendTo: "parent",
axis: false,
cancel: "input,textarea,button,select,option",
connectToSortable: false,
containment: false,
cursor: "auto",
cursorAt: false,
disabled: false,
grid: false,
handle: false,
helper: "original",
opacity: false,
refreshPositions: false,
revert: false,
revertDuration: 500,
scroll: true,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false,
zIndex: false,
//todo: remove the following option checks when interactions are rewritten:
addClasses: true,
delay: 0,
distance: 1,
iframeFix: false,
// callbacks
create: null,
drag: null,
start: null,
stop: null
}
});

View file

@ -0,0 +1,377 @@
/*
* draggable_core.js
*/
(function( $ ) {
module( "draggable: core" );
test( "element types", function() {
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" +
",acronym,code,samp,kbd,var,img,hr" +
",input,button,label,select,iframe"
).split(",");
expect( typeNames.length * 2 );
$.each( typeNames, function( i ) {
var offsetBefore, offsetAfter,
typeName = typeNames[ i ],
el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
if ( typeName === "table" ) {
el.append("<tr><td>content</td></tr>");
}
// intrinsic height is incorrect in FF for buttons with no content
// https://bugzilla.mozilla.org/show_bug.cgi?id=471763
// Support: FF
if ( typeName === "button" ) {
el.text( "button" );
}
el.draggable({ cancel: "" });
offsetBefore = el.offset();
el.simulate( "drag", {
dx: 50,
dy: 50
});
offsetAfter = el.offset();
// Support: FF, Chrome, and IE9,
// there are some rounding errors in so we can't say equal, we have to settle for close enough
closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + "> left" );
closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + "> top" );
el.draggable("destroy");
el.remove();
});
});
test( "No options, relative", function() {
expect( 2 );
TestHelpers.draggable.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" );
});
test( "No options, absolute", function() {
expect( 2 );
TestHelpers.draggable.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" );
});
test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 );
$( "#draggable1" )
.append(
$("<div>")
.addClass("ui-resizable-handle ui-resizable-w")
.append( $("<div>") )
);
var handle = $(".ui-resizable-w div"),
target = $( "#draggable1" ).draggable().resizable({ handles: "all" });
// todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: -50 } );
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" );
});
test( "#8269: Removing draggable element on drop", function() {
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" );
}
}),
dropOffset = $( "#droppable" ).offset();
$( "#droppable" ).droppable({
drop: function() {
$( "#wrapper" ).remove();
ok( true, "element removed from DOM on drop" );
}
});
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
if ( TestHelpers.draggable.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" );
} else {
element.simulate( "drag", {
handle: "corner",
x: dropOffset.left,
y: dropOffset.top
});
}
});
// 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 );
var element = $( "#draggable1" ).draggable({ scroll: false });
// In IE8, when content is placed under the mouse (e.g. when draggable content is replaced
// on mousedown), mousemove is triggered on those elements even though the mouse hasn't moved.
// Support: IE <9
element.bind( "mousedown", function() {
$( document ).simulate( "mousemove", { button: -1 });
});
TestHelpers.draggable.shouldMove( element, "element is draggable" );
});
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
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" );
$( "html" )
.css( "overflow-y", oldOverflowY )
.css( "overflow-x", oldOverflowX )
.scrollTop( 0 )
.scrollLeft( 0 );
}
}),
oldOverflowY = $( "html" ).css( "overflow-y" ),
oldOverflowX = $( "html" ).css( "overflow-x" );
TestHelpers.forceScrollableWindow();
$( "html" )
.css( "overflow-y", "scroll" )
.css( "overflow-x", "scroll" )
.scrollTop( 300 )
.scrollLeft( 300 );
element.simulate( "drag", {
dx: 1,
dy: 1,
moves: 1
});
});
test( "#9315: jumps down with offset of scrollbar", function() {
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" );
$( "html" ).scrollTop( 0 ).scrollLeft( 0 );
}
});
TestHelpers.forceScrollableWindow();
$( "html" ).scrollTop( 300 ).scrollLeft( 300 );
element.simulate( "drag", {
dx: 1,
dy: 1,
moves: 1
});
});
test( "scroll offset with fixed ancestors", function() {
expect( 2 );
var startValue = 300,
element = $( "#draggable1" )
// http://bugs.jqueryui.com/ticket/5009
// scroll not working with parent's position fixed
.wrap( "<div id='wrapper' />" )
// http://bugs.jqueryui.com/ticket/9612
// abspos elements inside of fixed elements moving away from the mouse when scrolling
.wrap( "<div id='wrapper2' />" )
.draggable({
drag: function() {
startValue += 100;
$( 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" );
$( document ).scrollTop( 0 ).scrollLeft( 0 );
}
});
TestHelpers.forceScrollableWindow();
$( "#wrapper" ).css( "position", "fixed" );
$( "#wrapper2" ).css( "position", "absolute" );
element.simulate( "drag", {
dx: 10,
dy: 10,
moves: 3
});
});
$( [ "hidden", "auto", "scroll" ] ).each(function() {
var overflow = this;
// 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-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
$( "#inner" ).css({ position: "absolute", width: "500px", height: "500px" });
$( "#outer" ).css({ position: "absolute", width: "300px", height: "300px" });
$( "#dragged" ).css({ width: "10px", height: "10px" });
var moves = 3,
startValue = 0,
dragDelta = 20,
delta = 100,
// we scroll after each drag event, so subtract 1 from number of moves for expected
expected = delta + ( ( moves - 1 ) * dragDelta ),
element = $( "#dragged" ).draggable({
drag: function() {
startValue += dragDelta;
$( "#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" );
}
});
$( "#outer" ).css( "overflow", overflow );
element.simulate( "drag", {
dy: delta,
dx: delta,
moves: moves
});
});
});
test( "#5727: draggable from iframe", function() {
expect( 1 );
var iframeBody, draggable1,
iframe = $( "<iframe />" ).appendTo( "#qunit-fixture" ),
iframeDoc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document;
iframeDoc.write( "<!doctype html><html><body>" );
iframeDoc.close();
iframeBody = $( iframeDoc.body ).append( "<div style='width: 2px; height: 2px;' />" );
draggable1 = iframeBody.find( "div" );
draggable1.draggable();
equal( draggable1.closest( iframeBody ).length, 1 );
// TODO: fix draggable within an IFRAME to fire events on the element properly
// and these TestHelpers.draggable.shouldMove relies on events for testing
//TestHelpers.draggable.shouldMove( 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 );
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" );
});
TestHelpers.draggable.move( element, 50, 50 );
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
});
asyncTest( "blur behavior", function() {
expect( 3 );
var element = $( "#draggable1" ).draggable(),
focusElement = $( "<div tabindex='1'></div>" ).appendTo( element );
TestHelpers.onFocus( focusElement, function() {
strictEqual( document.activeElement, focusElement.get( 0 ), "test element is focused before mousing down on a draggable" );
TestHelpers.draggable.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" );
TestHelpers.draggable.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();
});
});
test( "ui-draggable-handle assigned to appropriate element", function() {
expect( 5 );
var p = $( "<p>" ).appendTo( "#qunit-fixture" ),
element = $( "<div><p></p></div>" ).appendTo( "#qunit-fixture" ).draggable();
ok( element.hasClass( "ui-draggable-handle" ), "handle is element by default" );
element.draggable( "option", "handle", "p" );
ok( !element.hasClass( "ui-draggable-handle" ), "removed from element" );
ok( element.find( "p" ).hasClass( "ui-draggable-handle" ), "added to handle" );
ok( !p.hasClass( "ui-draggable-handle" ),
"ensure handle class name is constrained within the draggble (#10212)" );
element.draggable( "destroy" );
ok( !element.find( "p" ).hasClass( "ui-draggable-handle" ), "removed in destroy()" );
});
test( "ui-draggable-handle managed correctly in nested draggables", function() {
expect( 4 );
var parent = $( "<div><div></div></div>" ).draggable().appendTo( "#qunit-fixture" ),
child = parent.find( "div" ).draggable();
ok( parent.hasClass( "ui-draggable-handle" ), "parent has class name on init" );
ok( child.hasClass( "ui-draggable-handle" ), "child has class name on init" );
parent.draggable( "destroy" );
ok( !parent.hasClass( "ui-draggable-handle" ), "parent loses class name on destroy" );
ok( child.hasClass( "ui-draggable-handle" ), "child retains class name on destroy" );
});
// http://bugs.jqueryui.com/ticket/7772
// when css 'right' is set, element resizes on drag
test( "setting right/bottom css shouldn't cause resize", function() {
expect( 4 );
var finalOffset,
element = $( "#draggable3" ),
origWidth = element.width(),
origHeight = element.height(),
origOffset = element.offset();
element.draggable();
TestHelpers.draggable.move( element, -50, -50 );
finalOffset = element.offset();
finalOffset.left += 50;
finalOffset.top += 50;
closeEnough( element.width(), origWidth, 1, "element retains width" );
closeEnough( element.height(), origHeight, 1, "element retains height" );
closeEnough( finalOffset.top, origOffset.top, "element moves the correct vertical distance" );
closeEnough( finalOffset.top, origOffset.top, "element moves the correct horizontal distance" );
});
})( jQuery );

View file

@ -0,0 +1,164 @@
/*
* draggable_events.js
*/
(function( $ ) {
var element;
module( "draggable: events", {
setup: function() {
element = $("<div>").appendTo("#qunit-fixture");
},
teardown: function() {
element.draggable("destroy");
}
});
test( "callbacks occurrence count", function() {
expect( 3 );
var start = 0,
stop = 0,
dragc = 0;
element.draggable({
start: function() {
start++;
},
drag: function() {
dragc++;
},
stop: function() {
stop++;
}
});
element.simulate( "drag", {
dx: 10,
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" );
});
test( "stopping the start callback", function() {
expect( 3 );
var start = 0,
stop = 0,
dragc = 0;
element.draggable({
start: function() {
start++;
return false;
},
drag: function() {
dragc++;
},
stop: function() {
stop++;
}
});
element.simulate( "drag", {
dx: 10,
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" );
});
test( "stopping the drag callback", function() {
expect( 2 );
var start = 0,
stop = 0,
dragc = 0;
element.draggable({
start: function() {
start++;
},
drag: function() {
dragc++;
return false;
},
stop: function() {
stop++;
}
});
element.simulate( "drag", {
dx: 10,
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" );
});
test( "stopping the stop callback", function() {
expect( 1 );
element.draggable({
helper: "clone",
stop: function() {
return false;
}
});
element.simulate( "drag", {
dx: 10,
dy: 10
});
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 );
var startPos, startOffset, dragPos, dragOffset, stopPos, stopOffset;
element = $( "<div style='margin: 2px;'></div>" ).appendTo( "#qunit-fixture" );
element.draggable({
start: function( event, ui ) {
startPos = ui.position;
startOffset = ui.offset;
},
drag: function( event, ui ) {
dragPos = ui.position;
dragOffset = ui.offset;
},
stop: function( event, ui ) {
stopPos = ui.position;
stopOffset = ui.offset;
}
});
element.simulate( "drag", {
dx: 10,
dy: 10,
moves: 1
});
startPos.left += 10;
startPos.top += 10;
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" );
});
})( jQuery );

View file

@ -0,0 +1,103 @@
/*
* draggable_methods.js
*/
(function( $ ) {
var element;
module( "draggable: methods", {
setup: 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() {
element.remove();
}
});
test( "init", function() {
expect( 5 );
element.draggable();
ok( true, ".draggable() called on element" );
$([]).draggable();
ok( true, ".draggable() called on empty collection" );
$("<div></div>").draggable();
ok( true, ".draggable() called on disconnected DOMElement" );
element.draggable( "option", "foo" );
ok( true, "arbitrary option getter after init" );
element.draggable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" );
});
test( "destroy", function() {
expect( 4 );
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on element" );
$([]).draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on empty collection" );
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
var expected = element.draggable(),
actual = expected.draggable("destroy");
equal( actual, expected, "destroy is chainable" );
});
test( "enable", function() {
expect( 11 );
element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable("enable");
TestHelpers.draggable.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
element.draggable("destroy");
element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable( "option", "disabled", false );
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
TestHelpers.draggable.shouldMove( element, ".draggable('option', 'disabled', false)" );
var expected = element.draggable(),
actual = expected.draggable("enable");
equal( actual, expected, "enable is chainable" );
});
test( "disable", function() {
expect( 14 );
element = $( "#draggable2" ).draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "disable" );
TestHelpers.draggable.shouldNotDrag( element, ".draggable('disable')" );
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
element.draggable( "destroy" );
element.draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "option", "disabled", true );
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
TestHelpers.draggable.shouldNotDrag( element, ".draggable('option', 'disabled', true)" );
ok( !element.draggable( "widget" ).hasClass( "ui-state-disabled" ), "element does not get ui-state-disabled" );
ok( !element.draggable( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
ok( element.draggable( "widget" ).hasClass( "ui-draggable-disabled" ), "element gets ui-draggable-disabled" );
var expected = element.draggable(),
actual = expected.draggable( "disable" );
equal( actual, expected, "disable is chainable" );
});
})( jQuery );

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,131 @@
TestHelpers.draggable = {
// TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
unreliableContains: (function() {
var element = $( "<div>" );
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
})(),
testDragPosition: function( 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 );
});
},
testDragOffset: function( 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 );
});
},
testDragHelperOffset: function( 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 );
});
},
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
TestHelpers.draggable.testDragPosition( el, dx, dy, expectedDX, expectedDY, msg );
TestHelpers.draggable.testDragOffset( el, dx, dy, expectedDX, expectedDY, msg );
$( handle ).simulate( "drag", {
dx: dx,
dy: dy
});
},
shouldMovePositionButNotOffset: function( el, msg, handle ) {
handle = handle || el;
TestHelpers.draggable.testDragPosition( el, 100, 100, 100, 100, msg );
TestHelpers.draggable.testDragHelperOffset( el, 100, 100, 0, 0, msg );
$( handle ).simulate( "drag", {
dx: 100,
dy: 100
});
},
shouldMove: function( el, msg, handle ) {
handle = handle || el;
TestHelpers.draggable.testDrag( el, handle, 100, 100, 100, 100, msg );
},
shouldNotMove: function( el, msg, handle ) {
handle = handle || el;
TestHelpers.draggable.testDrag( el, handle, 100, 100, 0, 0, msg );
},
shouldNotDrag: function( el, msg, handle ) {
handle = handle || el;
var newOffset,
element = $( el ),
beginOffset = element.offset();
element.bind( "dragstop", function() {
ok( false, "should not drag " + msg );
});
$( handle ).simulate( "drag", {
dx: 100,
dy: 100
});
newOffset = element.offset();
// 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" );
element.unbind( "dragstop" );
},
setScrollable: function( what, isScrollable ) {
var overflow = isScrollable ? "scroll" : "hidden";
$( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow });
},
testScroll: function( el, position ) {
var oldPosition = $( "#main" ).css( "position" );
$( "#main" ).css({ position: position, top: "0px", left: "0px" });
TestHelpers.draggable.shouldMove( el, position + " parent" );
$( "#main" ).css( "position", oldPosition );
},
restoreScroll: function( what ) {
$( what ).scrollTop( 0 ).scrollLeft( 0 );
},
setScroll: function( what ) {
$( what ).scrollTop( 100 ).scrollLeft( 100 );
},
border: function( el, side ) {
return parseInt( el.css( "border-" + side + "-width" ), 10 ) || 0;
},
margin: function( el, side ) {
return parseInt( el.css( "margin-" + side ), 10 ) || 0;
},
move: function( el, x, y ) {
$( el ).simulate( "drag", {
dx: x,
dy: y
});
},
trackMouseCss: function( el ) {
el.bind( "drag", function() {
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
});
},
trackAppendedParent: function( el ) {
// TODO: appendTo is currently ignored if helper is original (see #7044)
el.draggable( "option", "helper", "clone" );
// Get what parent is at time of drag
el.bind( "drag", function(e, ui) {
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
});
}
};