diff options
author | Alvin Li <liweitianux@gmail.com> | 2013-10-09 15:52:53 +0800 |
---|---|---|
committer | Alvin Li <liweitianux@gmail.com> | 2013-10-09 15:52:53 +0800 |
commit | 02afd8a32edb13ea7fc2266ac80092ea15c0930c (patch) | |
tree | c7a2a3f50378c017b425da47e04a71c6beaae56c /97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable | |
parent | fafce2cfc72f4e1cd14ff6cb693c8ec7854159c5 (diff) | |
download | 97dev-02afd8a32edb13ea7fc2266ac80092ea15c0930c.tar.bz2 |
* treat 'apps/utils' as regular django app; which used to store
general tools for used in other apps
* moved 'templatetags' from 'apps/indicator' to 'apps/utils'
* '.gitignore' to ignore 'fixtures_bak'
* moved js plugins from 'apps/indicator/static/plugins' to
'staticfiles/plugins'
apps/recommend:
* updated 'recommend.models';
o commented 'recommend.models.ResearchCombination' (not used)
* implemented views 'add_edit_blog_info' and 'ajax_add_edit_configs';
* added pages 'templates/recommend/add_edit_blog_info.html',
'add_edit_blog_info_error.html';
o related css and javascripts files
* added 'tools.py';
* added 'utils/tools.py' for placing generic functions;
* deleted 'initial_data.json' (mv 'fixtures' to 'fixtures_bak');
* small fixes to 'indicator.models', 'sciblog.models' and
'sfaccount.views'
* fixed automatically show 'proper_nouns' annotation in blog:
recovered the line 'import signals' in 'sciblog.models'
* added 'is_ok()' method for 'recommend.models.ResearchConfig';
Diffstat (limited to '97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable')
8 files changed, 2002 insertions, 0 deletions
diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/all.html b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/all.html new file mode 100644 index 0000000..e096c88 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Draggable Test Suite</title> + + <script src="../../../jquery-1.9.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../qunit-composite.css"> + <script src="../../../external/qunit.js"></script> + <script src="../qunit-composite.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "draggable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Draggable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable.html b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable.html new file mode 100644 index 0000000..3d1d332 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable.html @@ -0,0 +1,58 @@ +<!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.css"> + + <style> + /* See #9077 */ + #draggable3, #draggable4 { z-index: 100; } + </style> + + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + <script> + TestHelpers.loadResources({ + css: [ "ui.core" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.resizable.js", + "ui/jquery.ui.draggable.js", + "ui/jquery.ui.droppable.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> + +<h1 id="qunit-header">jQuery UI Draggable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + <div id="main"></div> + <div id="draggable1" style="background: green; width: 200px; height: 100px;">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="droppable" style="background: green; width: 200px; height: 100px; position: absolute; top: 110px; left: 110px;"><span>Absolute</span></div> + <div style="width: 1px; height: 1000px;"></div> + <div style="position: absolute; width: 1px; height: 2000px;"></div> +</div> + +</body> +</html> diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_common.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_common.js new file mode 100644 index 0000000..5abd09e --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_common.js @@ -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 + } +}); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_core.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_core.js new file mode 100644 index 0000000..5370384 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_core.js @@ -0,0 +1,167 @@ +/* + * 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>"); + } + + 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 + ">" ); + closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" ); + el.draggable("destroy"); + el.remove(); + }); +}); + +test( "No options, relative", function() { + expect( 1 ); + TestHelpers.draggable.shouldMove( $( "#draggable1" ).draggable() ); +}); + +test( "No options, absolute", function() { + expect( 1 ); + TestHelpers.draggable.shouldMove( $( "#draggable2" ).draggable() ); +}); + +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( 1 ); + + var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable(), + 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" ); + } else { + element.simulate( "drag", { + handle: "corner", + x: dropOffset.left, + y: dropOffset.top + }); + } +}); + +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 ); + } + }), + contentToForceScroll = $( "<div>" ).css({ + height: "10000px", + width: "10000px" + }), + oldOverflowY = $( "html" ).css( "overflow-y" ), + oldOverflowX = $( "html" ).css( "overflow-x" ); + + contentToForceScroll.appendTo( "#qunit-fixture" ); + $( "html" ) + .css( "overflow-y", "scroll" ) + .css( "overflow-x", "scroll" ) + .scrollTop( 300 ) + .scrollLeft( 300 ); + + element.simulate( "drag", { + dx: 1, + dy: 1, + moves: 1 + }); +}); + +test( "#5009: scroll not working with parent's position fixed", function() { + expect( 2 ); + + var startValue = 300, + element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).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 ); + } + }), + contentToForceScroll = $( "<div>" ).css({ + height: "20000px", + width: "20000px" + }); + + $( "#qunit-fixture" ).append( contentToForceScroll ); + $( "#wrapper" ).css( "position", "fixed" ); + + element.simulate( "drag", { + dx: 10, + dy: 10, + moves: 3 + }); +}); + +})( jQuery ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_events.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_events.js new file mode 100644 index 0000000..199561b --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_events.js @@ -0,0 +1,125 @@ +/* + * 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.data("ui-draggable").helper, "the clone should not be deleted if the stop callback is stopped" ); + + +}); + +})( jQuery ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_methods.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_methods.js new file mode 100644 index 0000000..901c261 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_methods.js @@ -0,0 +1,99 @@ +/* + * 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( 7 ); + + element.draggable({ disabled: true }); + TestHelpers.draggable.shouldNotMove( 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.shouldNotMove( 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( 7 ); + + element = $("#draggable2").draggable({ disabled: false }); + TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" ); + + element.draggable("disable"); + TestHelpers.draggable.shouldNotMove( 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.shouldNotMove( element, ".draggable('option', 'disabled', true)" ); + + var expected = element.draggable(), + actual = expected.draggable("disable"); + equal( actual, expected, "disable is chainable" ); +}); + +})( jQuery ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_options.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_options.js new file mode 100644 index 0000000..635d318 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_options.js @@ -0,0 +1,1404 @@ +(function( $ ) { + +module( "draggable: options" ); + +// TODO: This doesn't actually test whether append happened, possibly remove +test( "{ appendTo: 'parent' }, default, no clone", function() { + expect( 2 ); + var element = $( "#draggable2" ).draggable({ appendTo: "parent" }); + TestHelpers.draggable.shouldMove( element ); + + element = $( "#draggable1" ).draggable({ appendTo: "parent" }); + TestHelpers.draggable.shouldMove( element ); +}); + +// TODO: This doesn't actually test whether append happened, possibly remove +test( "{ appendTo: Element }, no clone", function() { + expect( 2 ); + var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] }); + + TestHelpers.draggable.shouldMove( element ); + + element = $( "#draggable1" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] }); + TestHelpers.draggable.shouldMove( element ); +}); + +// TODO: This doesn't actually test whether append happened, possibly remove +test( "{ appendTo: Selector }, no clone", function() { + expect( 2 ); + var element = $( "#draggable2" ).draggable({ appendTo: "#main" }); + TestHelpers.draggable.shouldMove( element ); + + element = $( "#draggable1" ).draggable({ appendTo: "#main" }); + TestHelpers.draggable.shouldMove( element ); +}); + +test( "{ appendTo: 'parent' }, default", function() { + expect( 2 ); + + var element = $( "#draggable1" ).draggable(); + + TestHelpers.draggable.trackAppendedParent( element ); + + equal( element.draggable( "option", "appendTo" ), "parent" ); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] ); +}); + +test( "{ appendTo: Element }", function() { + expect( 1 ); + + var appendTo = $( "#draggable2" ).parent()[ 0 ], + element = $( "#draggable1" ).draggable({ appendTo: appendTo }); + + TestHelpers.draggable.trackAppendedParent( element ); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_parent" ), appendTo ); +}); + +test( "{ appendTo: jQuery }", function() { + expect( 1 ); + + var appendTo = $( "#draggable2" ).parent(), + element = $( "#draggable1" ).draggable({ appendTo: appendTo }); + + TestHelpers.draggable.trackAppendedParent( element ); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_parent" ), appendTo[ 0 ] ); +}); + +test( "{ appendTo: Selector }", function() { + expect( 1 ); + + var appendTo = "#main", + element = $( "#draggable1" ).draggable({ appendTo: appendTo }); + + TestHelpers.draggable.trackAppendedParent( element ); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_parent" ), $(appendTo)[ 0 ] ); +}); + +test( "appendTo, default, switching after initialization", function() { + expect( 2 ); + + var element = $( "#draggable1" ).draggable({ helper : "clone" }); + + TestHelpers.draggable.trackAppendedParent( element ); + + // Move and make sure element was appended to fixture + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] ); + + // Move and make sure element was appended to main + element.draggable( "option", "appendTo", $( "#main" ) ); + TestHelpers.draggable.move( element, 2, 2 ); + equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] ); +}); + +test( "{ axis: false }, default", function() { + expect( 1 ); + var element = $( "#draggable2" ).draggable({ axis: false }); + TestHelpers.draggable.shouldMove( element ); +}); + +test( "{ axis: 'x' }", function() { + expect( 1 ); + var element = $( "#draggable2" ).draggable({ axis: "x" }); + TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0 ); +}); + +test( "{ axis: 'y' }", function() { + expect( 1 ); + var element = $( "#draggable2" ).draggable({ axis: "y" }); + TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50 ); +}); + +test( "{ axis: ? }, unexpected", function() { + var element, + unexpected = { + "true": true, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {}": function() {} + }; + + expect( 6 ); + + $.each(unexpected, function(key, val) { + element = $( "#draggable2" ).draggable({ axis: val }); + TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50, "axis: " + key ); + element.draggable( "destroy" ); + }); +}); + +test( "axis, default, switching after initialization", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable({ axis : false }); + + // Any Direction + TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 ); + + // Only horizontal + element.draggable( "option", "axis", "x" ); + TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 0 ); + + // Vertical only + element.draggable( "option", "axis", "y" ); + TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 50 ); + +}); + +test( "{ cancel: 'input,textarea,button,select,option' }, default", function() { + expect( 2 ); + + $( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" ); + + var element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" }); + TestHelpers.draggable.shouldMove( element ); + + element.draggable( "destroy" ); + + element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" }); + TestHelpers.draggable.testDrag( element, "#draggable-option-cancel-default input", 50, 50, 0, 0 ); + element.draggable( "destroy" ); +}); + +test( "{ cancel: 'span' }", function() { + expect( 2 ); + + var element = $( "#draggable2" ).draggable(); + TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50 ); + + element.draggable( "destroy" ); + + element = $( "#draggable2" ).draggable({ cancel: "span" }); + TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 0, 0 ); +}); + +test( "{ cancel: ? }, unexpected", function() { + expect( 6 ); + + var element, + unexpected = { + "true": true, + "false": false, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined + }; + + $.each( unexpected, function( key, val ) { + element = $( "#draggable2" ).draggable({ cancel: val }); + TestHelpers.draggable.shouldMove( element, "cancel: " + key ); + element.draggable( "destroy" ); + }); +}); + +/** +test( "{ cancel: Selectors }, matching parent selector", function() { + + expect( 5 ); + + var element = $( "#draggable2" ).draggable({ cancel: "span a" }); + + $( "#qunit-fixture" ).append( "<span id='wrapping'><a></a></span>" ); + + element.find( "span" ).append( "<a>" ); + + $( "#wrapping a" ).append( element ); + + TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span child" ); + TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ) ); + TestHelpers.draggable.shouldNotMove( $( "#wrapping a" ) ); + + $( "#draggable2" ).draggable( "option", "cancel", "span > a" ); + $( "#draggable2" ).find( "a" ).append( "<a>" ); + + + TestHelpers.draggable.testDrag( element, $( "#draggable2 span a" ).last(), 50, 50, 50, 50, "drag span child" ); + TestHelpers.draggable.shouldNotMove( $( "#draggable2 span a" ).first() ); + +}); +*/ + +test( "cancelement, default, switching after initialization", function() { + expect( 3 ); + + $( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#main" ); + + var input = $( "#draggable-option-cancel-default input" ), + element = $( "#draggable-option-cancel-default" ).draggable(); + + TestHelpers.draggable.testDrag( element, input, 50, 50, 0, 0 ); + + element.draggable( "option", "cancel", "textarea" ); + TestHelpers.draggable.testDrag( element, input, 50, 50, 50, 50 ); + + element.draggable( "option", "cancel", "input" ); + TestHelpers.draggable.testDrag( element, input, 50, 50, 0, 0 ); +}); + +/* + +test( "{ connectToSortable: selector }, default", function() { + expect( 1 ); + + ok(false, "missing test - untested code is broken code" ); +}); +*/ + +test( "{ containment: Element }", function() { + expect( 1 ); + + var offsetAfter, + element = $( "#draggable1" ).draggable({ containment: $( "#draggable1" ).parent()[ 0 ] }), + p = element.parent(), + po = p.offset(), + expected = { + left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), + top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) + }; + + element.simulate( "drag", { + dx: -100, + dy: -100 + }); + offsetAfter = element.offset(); + deepEqual( offsetAfter, expected, "compare offset to parent" ); +}); + +test( "{ containment: Selector }", function() { + expect( 1 ); + + var offsetAfter, + element = $( "#draggable1" ).draggable({ containment: $( "#qunit-fixture" ) }), + p = element.parent(), + po = p.offset(), + expected = { + left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), + top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) + }; + + element.simulate( "drag", { + dx: -100, + dy: -100 + }); + offsetAfter = element.offset(); + deepEqual( offsetAfter, expected, "compare offset to parent" ); +}); + +test( "{ containment: [x1, y1, x2, y2] }", function() { + expect( 1 ); + + var element = $( "#draggable1" ).draggable(), + eo = element.offset(); + + element.draggable( "option", "containment", [ eo.left, eo.top, eo.left + element.width() + 5, eo.top + element.height() + 5 ] ); + + TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0 ); +}); + +test( "{ containment: 'parent' }, relative", function() { + expect( 1 ); + + var offsetAfter, + element = $( "#draggable1" ).draggable({ containment: "parent" }), + p = element.parent(), + po = p.offset(), + expected = { + left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), + top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) + }; + + element.simulate( "drag", { + dx: -100, + dy: -100 + }); + offsetAfter = element.offset(); + deepEqual( offsetAfter, expected, "compare offset to parent" ); +}); + +test( "{ containment: 'parent' }, absolute", function() { + expect( 1 ); + + var offsetAfter, + element = $( "#draggable2" ).draggable({ containment: "parent" }), + p = element.parent(), + po = p.offset(), + expected = { + left: po.left + TestHelpers.draggable.border( p, "left" ) + TestHelpers.draggable.margin( element, "left" ), + top: po.top + TestHelpers.draggable.border( p, "top" ) + TestHelpers.draggable.margin( element, "top" ) + }; + + element.simulate( "drag", { + dx: -100, + dy: -100 + }); + offsetAfter = element.offset(); + deepEqual( offsetAfter, expected, "compare offset to parent" ); +}); + +test( "containment, account for border", function() { + expect( 2 ); + + var el = $("#draggable1").appendTo("#main"), + parent = el.parent().css({ + height: "100px", + width: "100px", + borderStyle: "solid", + borderWidth: "5px 10px 15px 20px" + }), + parentBottom = parent.offset().top + parent.outerHeight(), + parentRight = parent.offset().left + parent.outerWidth(), + parentBorderBottom = TestHelpers.draggable.border( parent, "bottom" ), + parentBorderRight = TestHelpers.draggable.border( parent, "right" ); + + el.css({ + height: "5px", + width: "5px" + }).draggable({ containment: "parent" }); + + el.simulate( "drag", { + dx: 100, + dy: 100 + }); + + equal( el.offset().top, parentBottom - parentBorderBottom - el.height(), + "The draggable should be on top of its parent's bottom border" ); + equal( el.offset().left, parentRight - parentBorderRight - el.width(), + "The draggable should be to the right of its parent's right border" ); +}); + +test( "containment, default, switching after initialization", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable({ containment: false }); + + TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100 ); + + element.draggable( "option", "containment", "parent" ) + .css({ + top: 0, + left: 0 + }) + .appendTo( $( "#main" ) ); + + TestHelpers.draggable.testDrag( element, element, -100, -100, 0, 0 ); + + element.draggable( "option", "containment", false ); + TestHelpers.draggable.testDrag( element, element, -100, -100, -100, -100 ); +}); + +test( "{ cursor: 'auto' }, default", function() { + function getCursor() { + return $( "#draggable2" ).css( "cursor" ); + } + + expect( 2 ); + + var actual, after, + expected = "auto", + element = $( "#draggable2" ).draggable({ + cursor: expected, + start: function() { + actual = getCursor(); + } + }), + before = getCursor(); + + element.simulate( "drag", { + dx: -1, + dy: -1 + }); + after = getCursor(); + + equal( actual, expected, "start callback: cursor '" + expected + "'" ); + equal( after, before, "after drag: cursor restored" ); +}); + +test( "{ cursor: 'move' }", function() { + function getCursor() { + return $( "body" ).css( "cursor" ); + } + + expect( 2 ); + + var actual, after, + expected = "move", + element = $( "#draggable2" ).draggable({ + cursor: expected, + start: function() { + actual = getCursor(); + } + }), + before = getCursor(); + + element.simulate( "drag", { + dx: -1, + dy: -1 + }); + after = getCursor(); + + equal( actual, expected, "start callback: cursor '" + expected + "'" ); + equal( after, before, "after drag: cursor restored" ); +}); + +test( "cursor, default, switching after initialization", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable(); + + TestHelpers.draggable.trackMouseCss( element ); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_cursor" ), "auto" ); + + element.draggable( "option", "cursor", "move" ); + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_cursor" ), "move" ); + + element.draggable( "option", "cursor", "ns-resize" ); + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.data( "last_dragged_cursor" ), "ns-resize" ); +}); + +test( "cursorAt", function() { + expect( 24 ); + + var deltaX = -3, + deltaY = -3, + tests = { + "false": { cursorAt : false }, + "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } }, + "[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] }, + "'10 20'": { x: 10, y: 20, cursorAt : "10 20" }, + "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } }, + "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } } + }; + + $.each( tests, function( testName, testData ) { + $.each( [ "relative", "absolute" ], function( i, position ) { + var element = $( "#draggable" + ( i + 1 ) ).draggable({ + cursorAt: testData.cursorAt, + drag: function( event, ui ) { + if( !testData.cursorAt ) { + equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" ); + equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" ); + } else if( testData.cursorAt.right ) { + equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); + equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" ); + } else { + equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); + equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); + } + } + }); + + element.simulate( "drag", { + moves: 1, + dx: deltaX, + dy: deltaY + }); + }); + }); +}); + +test( "cursorAt, switching after initialization", function() { + expect( 24 ); + + var deltaX = -3, + deltaY = -3, + tests = { + "false": { cursorAt : false }, + "{ left: -5, top: -5 }": { x: -5, y: -5, cursorAt : { left: -5, top: -5 } }, + "[ 10, 20 ]": { x: 10, y: 20, cursorAt : [ 10, 20 ] }, + "'10 20'": { x: 10, y: 20, cursorAt : "10 20" }, + "{ left: 20, top: 40 }": { x: 20, y: 40, cursorAt : { left: 20, top: 40 } }, + "{ right: 10, bottom: 20 }": { x: 10, y: 20, cursorAt : { right: 10, bottom: 20 } } + }; + + $.each( tests, function( testName, testData ) { + $.each( [ "relative", "absolute" ], function( i, position ) { + var element = $( "#draggable" + ( i + 1 ) ); + + element.draggable({ + drag: function( event, ui ) { + if( !testData.cursorAt ) { + equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" ); + equal( ui.position.top - ui.originalPosition.top, deltaY, testName + " " + position + " top" ); + } else if( testData.cursorAt.right ) { + equal( ui.helper.width() - ( event.clientX - ui.offset.left ), testData.x - TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); + equal( ui.helper.height() - ( event.clientY - ui.offset.top ), testData.y - TestHelpers.draggable.unreliableOffset, testName + " " +position + " top" ); + } else { + equal( event.clientX - ui.offset.left, testData.x + TestHelpers.draggable.unreliableOffset, testName + " " + position + " left" ); + equal( event.clientY - ui.offset.top, testData.y + TestHelpers.draggable.unreliableOffset, testName + " " + position + " top" ); + } + } + }); + + element.draggable( "option", "cursorAt", false ); + element.draggable( "option", "cursorAt", testData.cursorAt ); + + element.simulate( "drag", { + moves: 1, + dx: deltaX, + dy: deltaY + }); + }); + }); +}); + +test( "disabled", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable(); + + TestHelpers.draggable.shouldMove( element ); + + element.draggable( "option", "disabled", true ); + TestHelpers.draggable.shouldNotMove( element ); + + element.draggable( "option", "disabled", false ); + TestHelpers.draggable.shouldMove( element ); +}); + +test( "{ grid: [50, 50] }, relative", function() { + expect( 2 ); + + var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] }); + TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 ); + TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 ); +}); + +test( "{ grid: [50, 50] }, absolute", function() { + expect( 2 ); + + var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] }); + TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 ); + TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 ); +}); + +test( "grid, switching after initialization", function() { + expect( 4 ); + + var element = $( "#draggable1" ).draggable(); + + // Forward + TestHelpers.draggable.testDrag( element, element, 24, 24, 24, 24 ); + TestHelpers.draggable.testDrag( element, element, 0, 0, 0, 0 ); + + element.draggable( "option", "grid", [ 50,50 ] ); + + TestHelpers.draggable.testDrag( element, element, 24, 24, 0, 0 ); + TestHelpers.draggable.testDrag( element, element, 26, 25, 50, 50 ); +}); + +test( "{ handle: 'span' }", function() { + expect( 3 ); + + var element = $( "#draggable2" ).draggable({ handle: "span" }); + + TestHelpers.draggable.testDrag( element, "#draggable2 span", 50, 50, 50, 50, "drag span" ); + TestHelpers.draggable.testDrag( element, "#draggable2 span em", 50, 50, 50, 50, "drag span child" ); + TestHelpers.draggable.shouldNotMove( element, "drag element" ); +}); + +test( "handle, default, switching after initialization", function() { + expect( 6 ); + + var element = $( "#draggable2" ).draggable(); + + TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 ); + TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 ); + + // Switch + element.draggable( "option", "handle", "span" ); + TestHelpers.draggable.testDrag( element, element, 50, 50, 0, 0 ); + TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 ); + + // And back + element.draggable( "option", "handle", false ); + TestHelpers.draggable.testDrag( element, element, 50, 50, 50, 50 ); + TestHelpers.draggable.testDrag( element, "#draggable2 span", 100, 100, 100, 100 ); +}); + +test( "helper, default, switching after initialization", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable(); + TestHelpers.draggable.shouldMove( element ); + + element.draggable( "option", "helper", "clone" ); + TestHelpers.draggable.shouldNotMove( element ); + + element.draggable( "option", "helper", "original" ); + TestHelpers.draggable.shouldMove( element ); +}); + +test( "{ helper: 'clone' }, relative", function() { + expect( 1 ); + + var element = $( "#draggable1" ).draggable({ helper: "clone" }); + TestHelpers.draggable.shouldNotMove( element ); +}); + +test( "{ helper: 'clone' }, absolute", function() { + expect( 1 ); + + var element = $( "#draggable2" ).draggable({ helper: "clone" }); + TestHelpers.draggable.shouldNotMove( element ); +}); + +test( "{ helper: 'original' }, relative, with scroll offset on parent", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll(); +}); + +test( "{ helper: 'original' }, relative, with scroll offset on root", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'original' }, relative, with scroll offset on root and parent", function() { + expect( 3 ); + + var element = $( "#draggable1" ).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'original' }, absolute, with scroll offset on parent", function() { + expect( 3 ); + + var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll(); +}); + +test( "{ helper: 'original' }, absolute, with scroll offset on root", function() { + expect( 3 ); + + var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'original' }, absolute, with scroll offset on root and parent", function() { + expect( 3 ); + + var element = $( "#draggable1" ).css({ position: "absolute", top: 0, left: 0 }).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'original' }, fixed, with scroll offset on parent", function() { + expect( 3 ); + + var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll(); +}); + +test( "{ helper: 'original' }, fixed, with scroll offset on root", function() { + expect( 3 ); + + var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'original' }, fixed, with scroll offset on root and parent", function() { + expect( 3 ); + + var element = $( "#draggable1" ).css({ position: "fixed", top: 0, left: 0 }).draggable({ helper: "original" }); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "relative" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "static" ); + + TestHelpers.draggable.setScroll(); + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.testScroll( element, "absolute" ); + + TestHelpers.draggable.restoreScroll(); + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'clone' }, absolute", function() { + expect( 1 ); + + var helperOffset = null, + origOffset = $( "#draggable1" ).offset(), + element = $( "#draggable1" ).draggable({ helper: "clone", drag: function( event, ui) { + helperOffset = ui.helper.offset(); + } }); + + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); +}); + +test( "{ helper: 'clone' }, absolute with scroll offset on parent", function() { + expect( 3 ); + + TestHelpers.draggable.setScroll(); + var helperOffset = null, + origOffset = null, + element = $( "#draggable1" ).draggable({ + helper: "clone", + drag: function( event, ui) { + helperOffset = ui.helper.offset(); + } + }); + + $( "#main" ).css( "position", "relative" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + $( "#main" ).css( "position", "static" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + $( "#main" ).css( "position", "absolute" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + TestHelpers.draggable.restoreScroll(); +}); + +test( "{ helper: 'clone' }, absolute with scroll offset on root", function() { + expect( 3 ); + + TestHelpers.draggable.setScroll( "root" ); + var helperOffset = null, + origOffset = null, + element = $( "#draggable1" ).draggable({ + helper: "clone", + drag: function( event, ui) { + helperOffset = ui.helper.offset(); + } + }); + + $( "#main" ).css( "position", "relative" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + $( "#main" ).css( "position", "static" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + $( "#main" ).css( "position", "absolute" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + TestHelpers.draggable.restoreScroll( "root" ); +}); + +test( "{ helper: 'clone' }, absolute with scroll offset on root and parent", function() { + expect( 3 ); + + TestHelpers.draggable.setScroll( "root" ); + TestHelpers.draggable.setScroll(); + + var helperOffset = null, + origOffset = null, + element = $( "#draggable1" ).draggable({ + helper: "clone", + drag: function( event, ui) { + helperOffset = ui.helper.offset(); + } + }); + + $( "#main" ).css( "position", "relative" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + $( "#main" ).css( "position", "static" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + $( "#main" ).css( "position", "absolute" ); + origOffset = $( "#draggable1" ).offset(); + element.simulate( "drag", { + dx: 1, + dy: 1 + }); + deepEqual({ top: helperOffset.top - 1, left: helperOffset.left - 1 }, origOffset, "dragged[1, 1]" ); + + TestHelpers.draggable.restoreScroll( "root" ); + TestHelpers.draggable.restoreScroll(); +}); + +test( "{ opacity: 0.5 }", function() { + expect( 1 ); + + var opacity = null, + element = $( "#draggable2" ).draggable({ + opacity: 0.5, + start: function() { + opacity = $(this).css( "opacity" ); + } + }); + + element.simulate( "drag", { + dx: -1, + dy: -1 + }); + + equal( opacity, 0.5, "start callback: opacity is" ); +}); + +test( "opacity, default, switching after initialization", function() { + expect( 3 ); + + var opacity = null, + element = $( "#draggable2" ).draggable({ + start: function() { + opacity = $(this).css( "opacity" ); + } + }); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( opacity, 1 ); + + element.draggable( "option", "opacity", 0.5 ); + TestHelpers.draggable.move( element, 2, 1 ); + equal( opacity, 0.5 ); + + element.draggable( "option", "opacity", false ); + TestHelpers.draggable.move( element, 3, 1 ); + equal( opacity, 1 ); +}); + +asyncTest( "revert and revertDuration", function() { + expect( 4 ); + + var element = $( "#draggable2" ).draggable({ + revert: true, + revertDuration: 0 + }); + TestHelpers.draggable.shouldNotMove( element, "revert: true, revertDuration: 0 should revert immediately" ); + + $( "#draggable2" ).draggable( "option", "revert", "invalid" ); + TestHelpers.draggable.shouldNotMove( element, "revert: invalid, revertDuration: 0 should revert immediately" ); + + $( "#draggable2" ).draggable( "option", "revert", false ); + TestHelpers.draggable.shouldMove( element, "revert: false should allow movement" ); + + $( "#draggable2" ).draggable( "option", { + revert: true, + revertDuration: 200, + stop: function() { + start(); + } + }); + + // animation are async, so test for it asynchronously + TestHelpers.draggable.move( element, 50, 50 ); + setTimeout( function() { + ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" ); + }); +}); + +test( "revert: valid", function() { + expect( 1 ); + + var element = $( "#draggable2" ).draggable({ + revert: "valid", + revertDuration: 0 + }); + + $( "#droppable" ).droppable(); + + TestHelpers.draggable.testDrag( element, element, 100, 100, 0, 0, "revert: valid reverts when dropped on a droppable" ); +}); + +test( "scope", function() { + expect( 2 ); + + var element = $( "#draggable2" ).draggable({ + scope: "tasks", + revert: "valid", + revertDuration: 0 + }); + + $( "#droppable" ).droppable({ scope: "tasks" }); + + TestHelpers.draggable.testDrag( element, element, 100, 100, 0, 0, "revert: valid reverts when dropped on a droppable in scope" ); + + $( "#droppable" ).droppable( "destroy" ).droppable({ scope: "nottasks" }); + + TestHelpers.draggable.testDrag( element, element, 100, 100, 100, 100, "revert: valid reverts when dropped on a droppable out of scope" ); +}); + +test( "scroll, scrollSensitivity, and scrollSpeed", function() { + expect( 2 ); + + var viewportHeight = $( window ).height(), + element = $( "#draggable1" ).draggable({ scroll: true }), + scrollSensitivity = element.draggable( "option", "scrollSensitivity" ), + scrollSpeed = element.draggable( "option", "scrollSpeed" ); + + element.offset({ + top: viewportHeight - scrollSensitivity - 1, + left: 1 + }); + + element.simulate( "drag", { + dx: 1, + y: viewportHeight - scrollSensitivity - 1, + moves: 1 + }); + + ok( $( window ).scrollTop() === 0, "scroll: true doesn't scroll when the element is dragged outside of scrollSensitivity" ); + + element.draggable( "option", "scrollSensitivity", scrollSensitivity + 10 ); + + element.offset({ + top: viewportHeight - scrollSensitivity - 1, + left: 1 + }); + + element.simulate( "drag", { + dx: 1, + y: viewportHeight - scrollSensitivity - 1, + moves: 1 + }); + + ok( $( window ).scrollTop() === scrollSpeed, "scroll: true scrolls when the element is dragged within scrollSensitivity" ); + + TestHelpers.draggable.restoreScroll( document ); +}); + +test( "#6817: auto scroll goes double distance when dragging", function() { + expect( 2 ); + + var offsetBefore, + distance = 10, + viewportHeight = $( window ).height(), + element = $( "#draggable1" ).draggable({ + scroll: true, + stop: function( e, ui ) { + equal( ui.offset.top, newY, "offset of item matches pointer position after scroll" ); + // TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal + closeEnough( ui.offset.top - offsetBefore.top, distance, 1, "offset of item only moves expected distance after scroll" ); + } + }), + scrollSensitivity = element.draggable( "option", "scrollSensitivity" ), + oldY = viewportHeight - scrollSensitivity, + newY = oldY + distance; + + element.offset({ + top: oldY, + left: 1 + }); + + offsetBefore = element.offset(); + + element.simulate( "drag", { + handle: "corner", + dx: 1, + y: newY, + moves: 1 + }); + + TestHelpers.draggable.restoreScroll( document ); +}); + +test( "snap, snapMode, and snapTolerance", function() { + expect( 10 ); + + var newX, newY, + snapTolerance = 15, + element = $( "#draggable1" ).draggable({ + snap: true, + snapMode: "both", + snapTolerance: snapTolerance + }), + element2 = $( "#draggable2" ).draggable(); + + element.offset({ + top: 1, + left: 1 + }); + + newX = element2.offset().left - element.outerWidth() - snapTolerance - 2; + newY = element2.offset().top; + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + // TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal + closeEnough( element.offset().left, newX, 1, "doesn't snap outside the snapTolerance" ); + closeEnough( element.offset().top, newY, 1, "doesn't snap outside the snapTolerance" ); + + newX += 3; + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the snapTolerance" ); + + element.draggable( "option", "snap", "#draggable2" ); + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps based on selector" ); + + element.draggable( "option", "snap", "#draggable3" ); + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap based on invalid selector" ); + + element.draggable( "option", "snap", true ); + element.draggable( "option", "snapTolerance", snapTolerance - 2 ); + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap outside the modified snapTolerance" ); + + element.draggable( "option", "snapTolerance", snapTolerance ); + element.draggable( "option", "snapMode", "inner" ); + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap inside the outer snapTolerance area when snapMode is inner" ); + + newX = element2.offset().left - snapTolerance - 1; + newY = element2.offset().top; + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap inside the outer snapTolerance area when snapMode is inner" ); + + newX++; + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the inner snapTolerance area when snapMode is inner" ); + + element.draggable( "option", "snapMode", "outer" ); + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap on the inner snapTolerance area when snapMode is outer" ); +}); + +test( "#8459: element can snap to an element that was removed during drag", function() { + expect( 2 ); + + var newX, newY, + snapTolerance = 15, + element = $( "#draggable1" ).draggable({ + snap: true, + snapMode: "both", + snapTolerance: snapTolerance, + start: function() { + element2.remove(); + } + }), + element2 = $( "#draggable2" ).draggable(); + + element.offset({ + top: 1, + left: 1 + }); + + newX = element2.offset().left - element.outerWidth() - snapTolerance + 1; + newY = element2.offset().top; + + element.simulate( "drag", { + handle: "corner", + x: newX, + y: newY, + moves: 1 + }); + + // 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 { + // TODO: fix IE8 testswarm IFRAME positioning bug so closeEnough can be turned back to equal + closeEnough( element.offset().left, newX, 1, "doesn't snap to a removed element" ); + closeEnough( element.offset().top, newY, 1, "doesn't snap to a removed element" ); + } +}); + +test( "#8165: Snapping large rectangles to small rectangles doesn't snap properly", function() { + expect( 1 ); + + var snapTolerance = 20, + y = 1, + element = $( "#draggable1" ) + .css({ + width: "50px", + height: "200px" + }).offset({ + top: y, + left: 1 + }), + element2 = $( "#draggable2" ) + .css({ + width: "50px", + height: "50px" + }).offset({ + top: y + snapTolerance + 1, + left: 200 + }), + newX = element2.offset().left - element.outerWidth() - snapTolerance + 1; + + $( "#draggable1, #draggable2" ).draggable({ + snap: true, + snapTolerance: snapTolerance + }); + + element.simulate( "drag", { + handle: "corner", + x: newX, + moves: 1 + }); + + notDeepEqual( element.offset(), { top: y, left: newX }, "snaps even if only a side (not a corner) is inside the snapTolerance" ); +}); + +test( "stack", function() { + expect( 2 ); + + var element = $( "#draggable1" ).draggable({ + stack: "#draggable1, #draggable2" + }), + element2 = $( "#draggable2" ).draggable({ + stack: "#draggable1, #draggable2" + }); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" ); + + TestHelpers.draggable.move( element2, 1, 1 ); + equal( element2.css( "zIndex" ), "3", "stack increments zIndex correctly" ); +}); + +test( "{ zIndex: 10 }", function() { + expect( 1 ); + + var actual, + expected = 10, + element = $( "#draggable2" ).draggable({ + zIndex: expected, + start: function() { + actual = $(this).css( "zIndex" ); + } + }); + + element.simulate( "drag", { + dx: -1, + dy: -1 + }); + + equal( actual, expected, "start callback: zIndex is" ); + +}); + +test( "zIndex, default, switching after initialization", function() { + + expect( 3 ); + + var zindex = null, + element = $( "#draggable2" ).draggable({ + start: function() { + zindex = $(this).css( "z-index" ); + } + }); + + element.css( "z-index", 1 ); + + TestHelpers.draggable.move( element, 1, 1 ); + equal( zindex, 1 ); + + element.draggable( "option", "zIndex", 5 ); + TestHelpers.draggable.move( element, 2, 1 ); + equal( zindex, 5 ); + + element.draggable( "option", "zIndex", false ); + TestHelpers.draggable.move( element, 3, 1 ); + equal( zindex, 1 ); + +}); + +})( jQuery ); diff --git a/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_test_helpers.js b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_test_helpers.js new file mode 100644 index 0000000..b365055 --- /dev/null +++ b/97suifangqa/staticfiles/plugins/jquery-ui/tests/unit/draggable/draggable_test_helpers.js @@ -0,0 +1,79 @@ +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 ] ); + })(), + testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) { + var offsetAfter, actual, expected, + offsetBefore = el.offset(); + + $( handle ).simulate( "drag", { + dx: dx, + dy: dy + }); + offsetAfter = el.offset(); + + actual = { left: offsetAfter.left, top: offsetAfter.top }; + expected = { left: offsetBefore.left + expectedDX, top: offsetBefore.top + expectedDY }; + + msg = msg ? msg + "." : ""; + deepEqual( actual, expected, "dragged[" + dx + ", " + dy + "] " + msg ); + }, + shouldMove: function( el, why ) { + TestHelpers.draggable.testDrag( el, el, 50, 50, 50, 50, why ); + }, + shouldNotMove: function( el, why ) { + TestHelpers.draggable.testDrag( el, el, 50, 50, 0, 0, why ); + }, + testScroll: function( el, position ) { + var oldPosition = $( "#main" ).css( "position" ); + $( "#main" ).css( "position", position); + TestHelpers.draggable.shouldMove( el, position + " parent" ); + $( "#main" ).css( "position", oldPosition ); + }, + restoreScroll: function( what ) { + if( what ) { + $( document ).scrollTop( 0 ).scrollLeft( 0 ); + } else { + $( "#main" ).scrollTop( 0 ).scrollLeft( 0 ); + } + }, + setScroll: function( what ) { + if( what ) { + // TODO: currently, the draggable interaction doesn't properly account for scrolled pages, + // uncomment the line below to make the tests fail that should when the page is scrolled + // $( document ).scrollTop( 100 ).scrollLeft( 100 ); + } else { + $( "#main" ).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 ] ); + }); + } +};
\ No newline at end of file |