") )
);
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( "
" ).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( "
" )
// 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 ) {
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( "
" );
$( "#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 = $( "
" ).appendTo( "#qunit-fixture" ),
iframeDoc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document;
iframeDoc.write( "" );
iframeDoc.close();
iframeBody = $( iframeDoc.body ).append( "
" );
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 = $( "
link" ).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 = $( "
" ).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( assert ) {
expect( 5 );
var p = $( "
" ).appendTo( "#qunit-fixture" ),
element = $( "
" ).appendTo( "#qunit-fixture" ).draggable();
assert.hasClasses( element, "ui-draggable-handle" );
element.draggable( "option", "handle", "p" );
assert.lacksClasses( element, "ui-draggable-handle" );
assert.hasClasses( element.find( "p" ), "ui-draggable-handle",
"ensure handle class name is constrained within the draggble (#10212)" );
assert.lacksClasses( p, "ui-draggable-handle" );
element.draggable( "destroy" );
assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" );
});
test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
expect( 4 );
var parent = $( "
" ).draggable().appendTo( "#qunit-fixture" ),
child = parent.find( "div" ).draggable();
assert.hasClasses( parent, "ui-draggable-handle", "parent has class name on init" );
assert.hasClasses( child, "ui-draggable-handle", "child has class name on init" );
parent.draggable( "destroy" );
assert.lacksClasses( parent, "ui-draggable-handle", "parent loses class name on destroy" );
assert.hasClasses( child, "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 );