define( [ "qunit", "jquery", "lib/helper", "./helper", "ui/widgets/draggable", "ui/widgets/droppable", "ui/widgets/resizable" ], function( QUnit, $, helper, testHelper ) { QUnit.module( "draggable: core", { afterEach: helper.moduleAfterEach } ); 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" + ",acronym,code,samp,kbd,var,img,hr" + ",input,button,label,select,iframe" ).split( "," ); assert.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( "content" ); } 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 assert.close( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + "> left" ); assert.close( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + "> top" ); el.draggable( "destroy" ); el.remove(); } ); } ); QUnit.test( "No options, relative", function( assert ) { assert.expect( 2 ); testHelper.shouldMove( assert, $( "#draggable1" ).draggable(), "no options, relative" ); } ); QUnit.test( "No options, absolute", function( assert ) { assert.expect( 2 ); testHelper.shouldMove( assert, $( "#draggable2" ).draggable(), "no options, absolute" ); } ); QUnit.test( "resizable handle with complex markup (#8756 / #8757)", function( assert ) { assert.expect( 2 ); $( "#draggable1" ) .append( $( "
" ) .addClass( "ui-resizable-handle ui-resizable-w" ) .append( $( "
" ) ) ); 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 } ); assert.equal( target.width(), 250, "compare width" ); // Todo: fix resizable so it doesn't require a mouseover handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } ); assert.equal( target.width(), 200, "compare width" ); } ); QUnit.test( "#8269: Removing draggable element on drop", function( assert ) { assert.expect( 2 ); var element = $( "#draggable1" ).wrap( "
" ).draggable( { stop: function() { assert.ok( true, "stop still called despite element being removed from DOM on drop" ); } } ), dropOffset = $( "#droppable" ).offset(); $( "#droppable" ).droppable( { drop: function() { $( "#wrapper" ).remove(); assert.ok( true, "element removed from DOM on drop" ); } } ); // Support: Opera 12.10, Safari 5.1, jQuery <1.8 if ( testHelper.unreliableContains ) { 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", x: dropOffset.left, y: dropOffset.top } ); } } ); // http://bugs.jqueryui.com/ticket/7778 // drag element breaks in IE8 when its content is replaced onmousedown QUnit.test( "Stray mousemove after mousedown still drags", function( assert ) { assert.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.on( "mousedown", function() { $( document ).simulate( "mousemove", { button: -1 } ); } ); testHelper.shouldMove( assert, element, "element is draggable" ); } ); 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 ) { 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 ) .scrollTop( 0 ) .scrollLeft( 0 ); } } ), oldOverflowY = $( "html" ).css( "overflow-y" ), oldOverflowX = $( "html" ).css( "overflow-x" ); testHelper.forceScrollableWindow(); $( "html" ) .css( "overflow-y", "scroll" ) .css( "overflow-x", "scroll" ) .scrollTop( 300 ) .scrollLeft( 300 ); element.simulate( "drag", { dx: 1, dy: 1, moves: 1 } ); } ); QUnit.test( "#9315: jumps down with offset of scrollbar", function( assert ) { assert.expect( 2 ); var element = $( "#draggable2" ).draggable( { stop: function( event, ui ) { 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 ); } } ); testHelper.forceScrollableWindow(); $( "html" ).scrollTop( 300 ).scrollLeft( 300 ); element.simulate( "drag", { dx: 1, dy: 1, moves: 1 } ); } ); QUnit.test( "scroll offset with fixed ancestors", function( assert ) { assert.expect( 2 ); var startValue = 300, element = $( "#draggable1" ) // http://bugs.jqueryui.com/ticket/5009 // scroll not working with parent's position fixed .wrap( "
" ) // http://bugs.jqueryui.com/ticket/9612 // abspos elements inside of fixed elements moving away from the mouse when scrolling .wrap( "
" ) .draggable( { drag: function() { startValue += 100; $( document ).scrollTop( startValue ).scrollLeft( startValue ); }, stop: function( event, ui ) { 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 ); } } ); testHelper.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" QUnit.test( "position in scrollable parent with overflow: " + overflow, function( assert ) { assert.expect( 2 ); $( "#qunit-fixture" ).html( "
a
" ); $( "#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 ) { 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" ); } } ); $( "#outer" ).css( "overflow", overflow ); element.simulate( "drag", { dy: delta, dx: delta, moves: moves } ); } ); } ); QUnit.test( "#5727: draggable from iframe", function( assert ) { assert.expect( 1 ); var iframeBody, draggable1, iframe = $( "