Draggable: Style updates

Ref #14246
This commit is contained in:
Alexander Schmitz 2015-08-24 08:59:44 -04:00
parent 0cab9f0a2f
commit 8336ba7b69
7 changed files with 580 additions and 561 deletions

View File

@ -43,6 +43,6 @@ common.testWidget( "draggable", {
start: null, start: null,
stop: null stop: null
} }
}); } );
} ); } );

View File

@ -14,84 +14,84 @@ test( "element types", function( assert ) {
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" + ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
",acronym,code,samp,kbd,var,img,hr" + ",acronym,code,samp,kbd,var,img,hr" +
",input,button,label,select,iframe" ",input,button,label,select,iframe"
).split(","); ).split( "," );
expect( typeNames.length * 2 ); expect( typeNames.length * 2 );
$.each( typeNames, function( i ) { $.each( typeNames, function( i ) {
var offsetBefore, offsetAfter, var offsetBefore, offsetAfter,
typeName = typeNames[ i ], typeName = typeNames[ i ],
el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture"); el = $( document.createElement( typeName ) ).appendTo( "#qunit-fixture" );
if ( typeName === "table" ) { if ( typeName === "table" ) {
el.append("<tr><td>content</td></tr>"); el.append( "<tr><td>content</td></tr>" );
} }
el.draggable({ cancel: "" }); el.draggable( { cancel: "" } );
offsetBefore = el.offset(); offsetBefore = el.offset();
el.simulate( "drag", { el.simulate( "drag", {
dx: 50, dx: 50,
dy: 50 dy: 50
}); } );
offsetAfter = el.offset(); offsetAfter = el.offset();
// Support: FF, Chrome, and IE9, // Support: FF, Chrome, and IE9,
// there are some rounding errors in so we can't say equal, we have to settle for close enough // 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.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + "> left" );
assert.close( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + "> top" ); assert.close( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + "> top" );
el.draggable("destroy"); el.draggable( "destroy" );
el.remove(); el.remove();
}); } );
}); } );
test( "No options, relative", function() { test( "No options, relative", function() {
expect( 2 ); expect( 2 );
testHelper.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" ); testHelper.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" );
}); } );
test( "No options, absolute", function() { test( "No options, absolute", function() {
expect( 2 ); expect( 2 );
testHelper.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" ); testHelper.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" );
}); } );
test( "resizable handle with complex markup (#8756 / #8757)", function() { test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 ); expect( 2 );
$( "#draggable1" ) $( "#draggable1" )
.append( .append(
$("<div>") $( "<div>" )
.addClass("ui-resizable-handle ui-resizable-w") .addClass( "ui-resizable-handle ui-resizable-w" )
.append( $("<div>") ) .append( $( "<div>" ) )
); );
var handle = $(".ui-resizable-w div"), var handle = $( ".ui-resizable-w div" ),
target = $( "#draggable1" ).draggable().resizable({ handles: "all" }); target = $( "#draggable1" ).draggable().resizable( { handles: "all" } );
// Todo: fix resizable so it doesn't require a mouseover // Todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: -50 } ); handle.simulate( "mouseover" ).simulate( "drag", { dx: -50 } );
equal( target.width(), 250, "compare width" ); equal( target.width(), 250, "compare width" );
// Todo: fix resizable so it doesn't require a mouseover // Todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: 50 } ); handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } );
equal( target.width(), 200, "compare width" ); equal( target.width(), 200, "compare width" );
}); } );
test( "#8269: Removing draggable element on drop", function() { test( "#8269: Removing draggable element on drop", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({ var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
stop: function() { stop: function() {
ok( true, "stop still called despite element being removed from DOM on drop" ); ok( true, "stop still called despite element being removed from DOM on drop" );
} }
}), } ),
dropOffset = $( "#droppable" ).offset(); dropOffset = $( "#droppable" ).offset();
$( "#droppable" ).droppable({ $( "#droppable" ).droppable( {
drop: function() { drop: function() {
$( "#wrapper" ).remove(); $( "#wrapper" ).remove();
ok( true, "element removed from DOM on drop" ); ok( true, "element removed from DOM on drop" );
} }
}); } );
// Support: Opera 12.10, Safari 5.1, jQuery <1.8 // Support: Opera 12.10, Safari 5.1, jQuery <1.8
if ( testHelper.unreliableContains ) { if ( testHelper.unreliableContains ) {
@ -102,31 +102,31 @@ test( "#8269: Removing draggable element on drop", function() {
handle: "corner", handle: "corner",
x: dropOffset.left, x: dropOffset.left,
y: dropOffset.top y: dropOffset.top
}); } );
} }
}); } );
// http://bugs.jqueryui.com/ticket/7778 // http://bugs.jqueryui.com/ticket/7778
// drag element breaks in IE8 when its content is replaced onmousedown // drag element breaks in IE8 when its content is replaced onmousedown
test( "Stray mousemove after mousedown still drags", function() { test( "Stray mousemove after mousedown still drags", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable1" ).draggable({ scroll: false }); var element = $( "#draggable1" ).draggable( { scroll: false } );
// In IE8, when content is placed under the mouse (e.g. when draggable content is replaced // 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. // on mousedown), mousemove is triggered on those elements even though the mouse hasn't moved.
// Support: IE <9 // Support: IE <9
element.on( "mousedown", function() { element.on( "mousedown", function() {
$( document ).simulate( "mousemove", { button: -1 }); $( document ).simulate( "mousemove", { button: -1 } );
}); } );
testHelper.shouldMove( element, "element is draggable" ); testHelper.shouldMove( element, "element is draggable" );
}); } );
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() { test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable1" ).draggable({ var element = $( "#draggable1" ).draggable( {
stop: function( event, ui ) { stop: function( event, ui ) {
equal( ui.position.left, 1, "left position is correct despite overflow on HTML" ); 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" ); equal( ui.position.top, 1, "top position is correct despite overflow on HTML" );
@ -136,7 +136,7 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
.scrollTop( 0 ) .scrollTop( 0 )
.scrollLeft( 0 ); .scrollLeft( 0 );
} }
}), } ),
oldOverflowY = $( "html" ).css( "overflow-y" ), oldOverflowY = $( "html" ).css( "overflow-y" ),
oldOverflowX = $( "html" ).css( "overflow-x" ); oldOverflowX = $( "html" ).css( "overflow-x" );
@ -152,19 +152,19 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
dx: 1, dx: 1,
dy: 1, dy: 1,
moves: 1 moves: 1
}); } );
}); } );
test( "#9315: jumps down with offset of scrollbar", function() { test( "#9315: jumps down with offset of scrollbar", function() {
expect( 2 ); expect( 2 );
var element = $( "#draggable2" ).draggable({ var element = $( "#draggable2" ).draggable( {
stop: function( event, ui ) { stop: function( event, ui ) {
equal( ui.position.left, 11, "left position is correct when position is absolute" ); 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" ); equal( ui.position.top, 11, "top position is correct when position is absolute" );
$( "html" ).scrollTop( 0 ).scrollLeft( 0 ); $( "html" ).scrollTop( 0 ).scrollLeft( 0 );
} }
}); } );
testHelper.forceScrollableWindow(); testHelper.forceScrollableWindow();
@ -174,21 +174,23 @@ test( "#9315: jumps down with offset of scrollbar", function() {
dx: 1, dx: 1,
dy: 1, dy: 1,
moves: 1 moves: 1
}); } );
}); } );
test( "scroll offset with fixed ancestors", function() { test( "scroll offset with fixed ancestors", function() {
expect( 2 ); expect( 2 );
var startValue = 300, var startValue = 300,
element = $( "#draggable1" ) element = $( "#draggable1" )
// http://bugs.jqueryui.com/ticket/5009 // http://bugs.jqueryui.com/ticket/5009
// scroll not working with parent's position fixed // scroll not working with parent's position fixed
.wrap( "<div id='wrapper' />" ) .wrap( "<div id='wrapper' />" )
// http://bugs.jqueryui.com/ticket/9612 // http://bugs.jqueryui.com/ticket/9612
// abspos elements inside of fixed elements moving away from the mouse when scrolling // abspos elements inside of fixed elements moving away from the mouse when scrolling
.wrap( "<div id='wrapper2' />" ) .wrap( "<div id='wrapper2' />" )
.draggable({ .draggable( {
drag: function() { drag: function() {
startValue += 100; startValue += 100;
$( document ).scrollTop( startValue ).scrollLeft( startValue ); $( document ).scrollTop( startValue ).scrollLeft( startValue );
@ -198,7 +200,7 @@ test( "scroll offset with fixed ancestors", function() {
equal( ui.position.top, 10, "top 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 ); $( document ).scrollTop( 0 ).scrollLeft( 0 );
} }
}); } );
testHelper.forceScrollableWindow(); testHelper.forceScrollableWindow();
@ -209,10 +211,10 @@ test( "scroll offset with fixed ancestors", function() {
dx: 10, dx: 10,
dy: 10, dy: 10,
moves: 3 moves: 3
}); } );
}); } );
$( [ "hidden", "auto", "scroll" ] ).each(function() { $( [ "hidden", "auto", "scroll" ] ).each( function() {
var overflow = this; var overflow = this;
// Http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div // Http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div
@ -221,9 +223,9 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
expect( 2 ); expect( 2 );
$( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" ); $( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
$( "#inner" ).css({ position: "absolute", width: "500px", height: "500px" }); $( "#inner" ).css( { position: "absolute", width: "500px", height: "500px" } );
$( "#outer" ).css({ position: "absolute", width: "300px", height: "300px" }); $( "#outer" ).css( { position: "absolute", width: "300px", height: "300px" } );
$( "#dragged" ).css({ width: "10px", height: "10px" }); $( "#dragged" ).css( { width: "10px", height: "10px" } );
var moves = 3, var moves = 3,
startValue = 0, startValue = 0,
@ -232,7 +234,7 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
// We scroll after each drag event, so subtract 1 from number of moves for expected // We scroll after each drag event, so subtract 1 from number of moves for expected
expected = delta + ( ( moves - 1 ) * dragDelta ), expected = delta + ( ( moves - 1 ) * dragDelta ),
element = $( "#dragged" ).draggable({ element = $( "#dragged" ).draggable( {
drag: function() { drag: function() {
startValue += dragDelta; startValue += dragDelta;
$( "#outer" ).scrollTop( startValue ).scrollLeft( startValue ); $( "#outer" ).scrollTop( startValue ).scrollLeft( startValue );
@ -241,7 +243,7 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
equal( ui.position.left, expected, "left position is correct when grandparent is scrolled" ); 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" ); equal( ui.position.top, expected, "top position is correct when grandparent is scrolled" );
} }
}); } );
$( "#outer" ).css( "overflow", overflow ); $( "#outer" ).css( "overflow", overflow );
@ -249,9 +251,9 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
dy: delta, dy: delta,
dx: delta, dx: delta,
moves: moves moves: moves
}); } );
}); } );
}); } );
test( "#5727: draggable from iframe", function() { test( "#5727: draggable from iframe", function() {
expect( 1 ); expect( 1 );
@ -273,7 +275,7 @@ test( "#5727: draggable from iframe", function() {
// TODO: fix draggable within an IFRAME to fire events on the element properly // TODO: fix draggable within an IFRAME to fire events on the element properly
// and these testHelper.shouldMove relies on events for testing // and these testHelper.shouldMove relies on events for testing
//testHelper.shouldMove( draggable1, "draggable from an iframe" ); //testHelper.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() { test( "#8399: A draggable should become the active element after you are finished interacting with it, but not before.", function() {
expect( 2 ); expect( 2 );
@ -282,12 +284,12 @@ test( "#8399: A draggable should become the active element after you are finishe
$( document ).one( "mousemove", function() { $( document ).one( "mousemove", function() {
notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" ); notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
}); } );
testHelper.move( element, 50, 50 ); testHelper.move( element, 50, 50 );
strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" ); strictEqual( document.activeElement, element.get( 0 ), "finishing moving a draggable anchor made it the active element" );
}); } );
asyncTest( "blur behavior", function() { asyncTest( "blur behavior", function() {
expect( 3 ); expect( 3 );
@ -310,8 +312,8 @@ asyncTest( "blur behavior", function() {
// active element should blur when mousing down on a draggable // 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" ); notStrictEqual( document.activeElement, focusElement.get( 0 ), "test element is no longer focused after mousing down on a draggable" );
start(); start();
}); } );
}); } );
test( "ui-draggable-handle assigned to appropriate element", function( assert ) { test( "ui-draggable-handle assigned to appropriate element", function( assert ) {
expect( 5 ); expect( 5 );
@ -328,7 +330,7 @@ test( "ui-draggable-handle assigned to appropriate element", function( assert )
element.draggable( "destroy" ); element.draggable( "destroy" );
assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" ); assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" );
}); } );
test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) { test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
expect( 4 ); expect( 4 );
@ -341,6 +343,6 @@ test( "ui-draggable-handle managed correctly in nested draggables", function( as
parent.draggable( "destroy" ); parent.draggable( "destroy" );
assert.lacksClasses( parent, "ui-draggable-handle", "parent loses class name on 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" ); assert.hasClasses( child, "ui-draggable-handle", "child retains class name on destroy" );
}); } );
} ); } );

View File

@ -7,12 +7,12 @@ var element;
module( "draggable: events", { module( "draggable: events", {
setup: function() { setup: function() {
element = $("<div>").appendTo("#qunit-fixture"); element = $( "<div>" ).appendTo( "#qunit-fixture" );
}, },
teardown: function() { teardown: function() {
element.draggable("destroy"); element.draggable( "destroy" );
} }
}); } );
test( "callbacks occurrence count", function() { test( "callbacks occurrence count", function() {
expect( 3 ); expect( 3 );
@ -21,7 +21,7 @@ test( "callbacks occurrence count", function() {
stop = 0, stop = 0,
dragc = 0; dragc = 0;
element.draggable({ element.draggable( {
start: function() { start: function() {
start++; start++;
}, },
@ -31,17 +31,17 @@ test( "callbacks occurrence count", function() {
stop: function() { stop: function() {
stop++; stop++;
} }
}); } );
element.simulate( "drag", { element.simulate( "drag", {
dx: 10, dx: 10,
dy: 10 dy: 10
}); } );
equal( start, 1, "start callback should happen exactly once" ); equal( start, 1, "start callback should happen exactly once" );
equal( dragc, 3, "drag callback should happen exactly once per mousemove" ); equal( dragc, 3, "drag callback should happen exactly once per mousemove" );
equal( stop, 1, "stop callback should happen exactly once" ); equal( stop, 1, "stop callback should happen exactly once" );
}); } );
test( "stopping the start callback", function() { test( "stopping the start callback", function() {
expect( 3 ); expect( 3 );
@ -50,7 +50,7 @@ test( "stopping the start callback", function() {
stop = 0, stop = 0,
dragc = 0; dragc = 0;
element.draggable({ element.draggable( {
start: function() { start: function() {
start++; start++;
return false; return false;
@ -61,17 +61,17 @@ test( "stopping the start callback", function() {
stop: function() { stop: function() {
stop++; stop++;
} }
}); } );
element.simulate( "drag", { element.simulate( "drag", {
dx: 10, dx: 10,
dy: 10 dy: 10
}); } );
equal( start, 1, "start callback should happen exactly once" ); equal( start, 1, "start callback should happen exactly once" );
equal( dragc, 0, "drag callback should not happen at all" ); equal( dragc, 0, "drag callback should not happen at all" );
equal( stop, 0, "stop callback should not happen if there wasnt even a start" ); equal( stop, 0, "stop callback should not happen if there wasnt even a start" );
}); } );
test( "stopping the drag callback", function() { test( "stopping the drag callback", function() {
expect( 2 ); expect( 2 );
@ -80,7 +80,7 @@ test( "stopping the drag callback", function() {
stop = 0, stop = 0,
dragc = 0; dragc = 0;
element.draggable({ element.draggable( {
start: function() { start: function() {
start++; start++;
}, },
@ -91,34 +91,34 @@ test( "stopping the drag callback", function() {
stop: function() { stop: function() {
stop++; stop++;
} }
}); } );
element.simulate( "drag", { element.simulate( "drag", {
dx: 10, dx: 10,
dy: 10 dy: 10
}); } );
equal( start, 1, "start callback should happen exactly once" ); equal( start, 1, "start callback should happen exactly once" );
equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" ); equal( stop, 1, "stop callback should happen, as we need to actively stop the drag" );
}); } );
test( "stopping the stop callback", function() { test( "stopping the stop callback", function() {
expect( 1 ); expect( 1 );
element.draggable({ element.draggable( {
helper: "clone", helper: "clone",
stop: function() { stop: function() {
return false; return false;
} }
}); } );
element.simulate( "drag", { element.simulate( "drag", {
dx: 10, dx: 10,
dy: 10 dy: 10
}); } );
ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" ); ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
}); } );
// http://bugs.jqueryui.com/ticket/6884 // http://bugs.jqueryui.com/ticket/6884
// Draggable: ui.offset.left differs between the "start" and "drag" hooks // Draggable: ui.offset.left differs between the "start" and "drag" hooks
@ -129,7 +129,7 @@ test( "position and offset in hash is consistent between start, drag, and stop",
element = $( "<div style='margin: 2px;'></div>" ).appendTo( "#qunit-fixture" ); element = $( "<div style='margin: 2px;'></div>" ).appendTo( "#qunit-fixture" );
element.draggable({ element.draggable( {
start: function( event, ui ) { start: function( event, ui ) {
startPos = ui.position; startPos = ui.position;
startOffset = ui.offset; startOffset = ui.offset;
@ -142,13 +142,13 @@ test( "position and offset in hash is consistent between start, drag, and stop",
stopPos = ui.position; stopPos = ui.position;
stopOffset = ui.offset; stopOffset = ui.offset;
} }
}); } );
element.simulate( "drag", { element.simulate( "drag", {
dx: 10, dx: 10,
dy: 10, dy: 10,
moves: 1 moves: 1
}); } );
startPos.left += 10; startPos.left += 10;
startPos.top += 10; startPos.top += 10;
@ -159,6 +159,6 @@ test( "position and offset in hash is consistent between start, drag, and stop",
deepEqual( dragPos, stopPos, "drag position equals stop position" ); deepEqual( dragPos, stopPos, "drag position equals stop position" );
deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" ); deepEqual( startOffset, dragOffset, "start offset equals drag offset plus distance" );
deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" ); deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
}); } );
} ); } );

View File

@ -8,12 +8,13 @@ return $.extend( helper, {
// TODO: remove the unreliable offset hacks // TODO: remove the unreliable offset hacks
unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0, unreliableOffset: $.ui.ie && ( !document.documentMode || document.documentMode < 8 ) ? 2 : 0,
// Support: Opera 12.10, Safari 5.1, jQuery <1.8 // Support: Opera 12.10, Safari 5.1, jQuery <1.8
unreliableContains: (function() { unreliableContains: ( function() {
var element = $( "<div>" ); var element = $( "<div>" );
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] ); return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
})(), } )(),
testDragPosition: function( el, dx, dy, expectedDX, expectedDY, msg ) { testDragPosition: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : ""; msg = msg ? msg + "." : "";
@ -21,7 +22,7 @@ return $.extend( helper, {
$( el ).one( "dragstop", function( event, ui ) { $( el ).one( "dragstop", function( event, ui ) {
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY }; var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg ); deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
}); } );
}, },
testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) { testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
@ -32,7 +33,7 @@ return $.extend( helper, {
$( el ).one( "dragstop", function( event, ui ) { $( el ).one( "dragstop", function( event, ui ) {
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg ); deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
}); } );
}, },
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) { testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
@ -43,7 +44,7 @@ return $.extend( helper, {
$( el ).one( "dragstop", function( event, ui ) { $( el ).one( "dragstop", function( event, ui ) {
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg ); deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
}); } );
}, },
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) { testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
@ -53,7 +54,7 @@ return $.extend( helper, {
$( handle ).simulate( "drag", { $( handle ).simulate( "drag", {
dx: dx, dx: dx,
dy: dy dy: dy
}); } );
}, },
shouldMovePositionButNotOffset: function( el, msg, handle ) { shouldMovePositionButNotOffset: function( el, msg, handle ) {
@ -64,7 +65,7 @@ return $.extend( helper, {
$( handle ).simulate( "drag", { $( handle ).simulate( "drag", {
dx: 100, dx: 100,
dy: 100 dy: 100
}); } );
}, },
shouldMove: function( el, msg, handle ) { shouldMove: function( el, msg, handle ) {
@ -86,12 +87,12 @@ return $.extend( helper, {
element.on( "dragstop", function() { element.on( "dragstop", function() {
ok( false, "should not drag " + msg ); ok( false, "should not drag " + msg );
}); } );
$( handle ).simulate( "drag", { $( handle ).simulate( "drag", {
dx: 100, dx: 100,
dy: 100 dy: 100
}); } );
newOffset = element.offset(); newOffset = element.offset();
@ -105,12 +106,12 @@ return $.extend( helper, {
setScrollable: function( what, isScrollable ) { setScrollable: function( what, isScrollable ) {
var overflow = isScrollable ? "scroll" : "hidden"; var overflow = isScrollable ? "scroll" : "hidden";
$( what ).css({ overflow: overflow, overflowX: overflow, overflowY: overflow }); $( what ).css( { overflow: overflow, overflowX: overflow, overflowY: overflow } );
}, },
testScroll: function( el, position ) { testScroll: function( el, position ) {
var oldPosition = $( "#main" ).css( "position" ); var oldPosition = $( "#main" ).css( "position" );
$( "#main" ).css({ position: position, top: "0px", left: "0px" }); $( "#main" ).css( { position: position, top: "0px", left: "0px" } );
this.shouldMove( el, position + " parent" ); this.shouldMove( el, position + " parent" );
$( "#main" ).css( "position", oldPosition ); $( "#main" ).css( "position", oldPosition );
}, },
@ -135,23 +136,24 @@ return $.extend( helper, {
$( el ).simulate( "drag", { $( el ).simulate( "drag", {
dx: x, dx: x,
dy: y dy: y
}); } );
}, },
trackMouseCss: function( el ) { trackMouseCss: function( el ) {
el.on( "drag", function() { el.on( "drag", function() {
el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) ); el.data( "last_dragged_cursor", $( "body" ).css( "cursor" ) );
}); } );
}, },
trackAppendedParent: function( el ) { trackAppendedParent: function( el ) {
// TODO: appendTo is currently ignored if helper is original (see #7044) // TODO: appendTo is currently ignored if helper is original (see #7044)
el.draggable( "option", "helper", "clone" ); el.draggable( "option", "helper", "clone" );
// Get what parent is at time of drag // Get what parent is at time of drag
el.on( "drag", function(e, ui) { el.on( "drag", function( e, ui ) {
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] ); el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
}); } );
} }
} ); } );

View File

@ -8,12 +8,12 @@ var element;
module( "draggable: methods", { module( "draggable: methods", {
setup: function() { setup: function() {
element = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture"); element = $( "<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>" ).appendTo( "#qunit-fixture" );
}, },
teardown: function() { teardown: function() {
element.remove(); element.remove();
} }
}); } );
test( "init", function() { test( "init", function() {
expect( 5 ); expect( 5 );
@ -21,10 +21,10 @@ test( "init", function() {
element.draggable(); element.draggable();
ok( true, ".draggable() called on element" ); ok( true, ".draggable() called on element" );
$([]).draggable(); $( [] ).draggable();
ok( true, ".draggable() called on empty collection" ); ok( true, ".draggable() called on empty collection" );
$("<div></div>").draggable(); $( "<div></div>" ).draggable();
ok( true, ".draggable() called on disconnected DOMElement" ); ok( true, ".draggable() called on disconnected DOMElement" );
element.draggable( "option", "foo" ); element.draggable( "option", "foo" );
@ -32,52 +32,52 @@ test( "init", function() {
element.draggable( "option", "foo", "bar" ); element.draggable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" ); ok( true, "arbitrary option setter after init" );
}); } );
test( "destroy", function() { test( "destroy", function() {
expect( 4 ); expect( 4 );
element.draggable().draggable("destroy"); element.draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on element" ); ok( true, ".draggable('destroy') called on element" );
$([]).draggable().draggable("destroy"); $( [] ).draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on empty collection" ); ok( true, ".draggable('destroy') called on empty collection" );
element.draggable().draggable("destroy"); element.draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on disconnected DOMElement" ); ok( true, ".draggable('destroy') called on disconnected DOMElement" );
var expected = element.draggable(), var expected = element.draggable(),
actual = expected.draggable("destroy"); actual = expected.draggable( "destroy" );
equal( actual, expected, "destroy is chainable" ); equal( actual, expected, "destroy is chainable" );
}); } );
test( "enable", function() { test( "enable", function() {
expect( 11 ); expect( 11 );
element.draggable({ disabled: true }); element.draggable( { disabled: true } );
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" ); testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable("enable"); element.draggable( "enable" );
testHelper.shouldMove( element, ".draggable('enable')" ); testHelper.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" ); equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
element.draggable("destroy"); element.draggable( "destroy" );
element.draggable({ disabled: true }); element.draggable( { disabled: true } );
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" ); testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
element.draggable( "option", "disabled", false ); element.draggable( "option", "disabled", false );
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" ); equal( element.draggable( "option", "disabled" ), false, "disabled option setter" );
testHelper.shouldMove( element, ".draggable('option', 'disabled', false)" ); testHelper.shouldMove( element, ".draggable('option', 'disabled', false)" );
var expected = element.draggable(), var expected = element.draggable(),
actual = expected.draggable("enable"); actual = expected.draggable( "enable" );
equal( actual, expected, "enable is chainable" ); equal( actual, expected, "enable is chainable" );
}); } );
test( "disable", function( assert ) { test( "disable", function( assert ) {
expect( 14 ); expect( 14 );
element = $( "#draggable2" ).draggable({ disabled: false }); element = $( "#draggable2" ).draggable( { disabled: false } );
testHelper.shouldMove( element, ".draggable({ disabled: false })" ); testHelper.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "disable" ); element.draggable( "disable" );
@ -85,7 +85,7 @@ test( "disable", function( assert ) {
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" ); equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
element.draggable( "destroy" ); element.draggable( "destroy" );
element.draggable({ disabled: false }); element.draggable( { disabled: false } );
testHelper.shouldMove( element, ".draggable({ disabled: false })" ); testHelper.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "option", "disabled", true ); element.draggable( "option", "disabled", true );
@ -99,6 +99,6 @@ test( "disable", function( assert ) {
var expected = element.draggable(), var expected = element.draggable(),
actual = expected.draggable( "disable" ); actual = expected.draggable( "disable" );
equal( actual, expected, "disable is chainable" ); equal( actual, expected, "disable is chainable" );
}); } );
} ); } );

File diff suppressed because it is too large Load Diff

View File

@ -14,11 +14,11 @@
//>>demos: http://jqueryui.com/draggable/ //>>demos: http://jqueryui.com/draggable/
//>>css.structure: ../themes/base/draggable.css //>>css.structure: ../themes/base/draggable.css
(function( factory ) { ( function( factory ) {
if ( typeof define === "function" && define.amd ) { if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define([ define( [
"jquery", "jquery",
"./mouse", "./mouse",
"../data", "../data",
@ -34,9 +34,9 @@
// Browser globals // Browser globals
factory( jQuery ); factory( jQuery );
} }
}(function( $ ) { }( function( $ ) {
$.widget("ui.draggable", $.ui.mouse, { $.widget( "ui.draggable", $.ui.mouse, {
version: "@VERSION", version: "@VERSION",
widgetEventPrefix: "drag", widgetEventPrefix: "drag",
options: { options: {
@ -75,10 +75,10 @@ $.widget("ui.draggable", $.ui.mouse, {
if ( this.options.helper === "original" ) { if ( this.options.helper === "original" ) {
this._setPositionRelative(); this._setPositionRelative();
} }
if (this.options.addClasses){ if ( this.options.addClasses ) {
this._addClass( "ui-draggable" ); this._addClass( "ui-draggable" );
} }
if (this.options.disabled){ if ( this.options.disabled ) {
this._addClass( "ui-draggable-disabled" ); this._addClass( "ui-draggable-disabled" );
} }
this._setHandleClassName(); this._setHandleClassName();
@ -103,19 +103,19 @@ $.widget("ui.draggable", $.ui.mouse, {
this._mouseDestroy(); this._mouseDestroy();
}, },
_mouseCapture: function(event) { _mouseCapture: function( event ) {
var o = this.options; var o = this.options;
this._blurActiveElement( event ); this._blurActiveElement( event );
// Among others, prevent a drag on a resizable-handle // Among others, prevent a drag on a resizable-handle
if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) { if ( this.helper || o.disabled || $( event.target ).closest( ".ui-resizable-handle" ).length > 0 ) {
return false; return false;
} }
//Quit if we're not on a valid handle //Quit if we're not on a valid handle
this.handle = this._getHandle(event); this.handle = this._getHandle( event );
if (!this.handle) { if ( !this.handle ) {
return false; return false;
} }
@ -126,7 +126,7 @@ $.widget("ui.draggable", $.ui.mouse, {
}, },
_blockFrames: function( selector ) { _blockFrames: function( selector ) {
this.iframeBlocks = this.document.find( selector ).map(function() { this.iframeBlocks = this.document.find( selector ).map( function() {
var iframe = $( this ); var iframe = $( this );
return $( "<div>" ) return $( "<div>" )
@ -135,7 +135,7 @@ $.widget("ui.draggable", $.ui.mouse, {
.outerWidth( iframe.outerWidth() ) .outerWidth( iframe.outerWidth() )
.outerHeight( iframe.outerHeight() ) .outerHeight( iframe.outerHeight() )
.offset( iframe.offset() )[ 0 ]; .offset( iframe.offset() )[ 0 ];
}); } );
}, },
_unblockFrames: function() { _unblockFrames: function() {
@ -156,12 +156,12 @@ $.widget("ui.draggable", $.ui.mouse, {
$.ui.safeBlur( $.ui.safeActiveElement( this.document[ 0 ] ) ); $.ui.safeBlur( $.ui.safeActiveElement( this.document[ 0 ] ) );
}, },
_mouseStart: function(event) { _mouseStart: function( event ) {
var o = this.options; var o = this.options;
//Create and append the visible helper //Create and append the visible helper
this.helper = this._createHelper(event); this.helper = this._createHelper( event );
this._addClass( this.helper, "ui-draggable-dragging" ); this._addClass( this.helper, "ui-draggable-dragging" );
@ -169,7 +169,7 @@ $.widget("ui.draggable", $.ui.mouse, {
this._cacheHelperProportions(); this._cacheHelperProportions();
//If ddmanager is used for droppables, set the global draggable //If ddmanager is used for droppables, set the global draggable
if ($.ui.ddmanager) { if ( $.ui.ddmanager ) {
$.ui.ddmanager.current = this; $.ui.ddmanager.current = this;
} }
@ -185,9 +185,9 @@ $.widget("ui.draggable", $.ui.mouse, {
this.cssPosition = this.helper.css( "position" ); this.cssPosition = this.helper.css( "position" );
this.scrollParent = this.helper.scrollParent( true ); this.scrollParent = this.helper.scrollParent( true );
this.offsetParent = this.helper.offsetParent(); this.offsetParent = this.helper.offsetParent();
this.hasFixedAncestor = this.helper.parents().filter(function() { this.hasFixedAncestor = this.helper.parents().filter( function() {
return $( this ).css( "position" ) === "fixed"; return $( this ).css( "position" ) === "fixed";
}).length > 0; } ).length > 0;
//The element's absolute position on the page minus margins //The element's absolute position on the page minus margins
this.positionAbs = this.element.offset(); this.positionAbs = this.element.offset();
@ -199,13 +199,13 @@ $.widget("ui.draggable", $.ui.mouse, {
this.originalPageY = event.pageY; this.originalPageY = event.pageY;
//Adjust the mouse offset relative to the helper if "cursorAt" is supplied //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); ( o.cursorAt && this._adjustOffsetFromHelper( o.cursorAt ) );
//Set a containment if given in the options //Set a containment if given in the options
this._setContainment(); this._setContainment();
//Trigger event + callbacks //Trigger event + callbacks
if (this._trigger("start", event) === false) { if ( this._trigger( "start", event ) === false ) {
this._clear(); this._clear();
return false; return false;
} }
@ -214,15 +214,15 @@ $.widget("ui.draggable", $.ui.mouse, {
this._cacheHelperProportions(); this._cacheHelperProportions();
//Prepare the droppable offsets //Prepare the droppable offsets
if ($.ui.ddmanager && !o.dropBehaviour) { if ( $.ui.ddmanager && !o.dropBehaviour ) {
$.ui.ddmanager.prepareOffsets(this, event); $.ui.ddmanager.prepareOffsets( this, event );
} }
this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position this._mouseDrag( event, true ); //Execute the drag once - this causes the helper not to be visible before getting its correct position
//If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003) //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
if ( $.ui.ddmanager ) { if ( $.ui.ddmanager ) {
$.ui.ddmanager.dragStart(this, event); $.ui.ddmanager.dragStart( this, event );
} }
return true; return true;
@ -243,7 +243,8 @@ $.widget("ui.draggable", $.ui.mouse, {
}; };
}, },
_mouseDrag: function(event, noPropagation) { _mouseDrag: function( event, noPropagation ) {
// reset any necessary cached properties (see #5009) // reset any necessary cached properties (see #5009)
if ( this.hasFixedAncestor ) { if ( this.hasFixedAncestor ) {
this.offset.parent = this._getParentOffset(); this.offset.parent = this._getParentOffset();
@ -251,13 +252,13 @@ $.widget("ui.draggable", $.ui.mouse, {
//Compute the helpers position //Compute the helpers position
this.position = this._generatePosition( event, true ); this.position = this._generatePosition( event, true );
this.positionAbs = this._convertPositionTo("absolute"); this.positionAbs = this._convertPositionTo( "absolute" );
//Call plugins and callbacks and use the resulting position if something is returned //Call plugins and callbacks and use the resulting position if something is returned
if (!noPropagation) { if ( !noPropagation ) {
var ui = this._uiHash(); var ui = this._uiHash();
if (this._trigger("drag", event, ui) === false) { if ( this._trigger( "drag", event, ui ) === false ) {
this._mouseUp({}); this._mouseUp( {} );
return false; return false;
} }
this.position = ui.position; this.position = ui.position;
@ -266,36 +267,36 @@ $.widget("ui.draggable", $.ui.mouse, {
this.helper[ 0 ].style.left = this.position.left + "px"; this.helper[ 0 ].style.left = this.position.left + "px";
this.helper[ 0 ].style.top = this.position.top + "px"; this.helper[ 0 ].style.top = this.position.top + "px";
if ($.ui.ddmanager) { if ( $.ui.ddmanager ) {
$.ui.ddmanager.drag(this, event); $.ui.ddmanager.drag( this, event );
} }
return false; return false;
}, },
_mouseStop: function(event) { _mouseStop: function( event ) {
//If we are using droppables, inform the manager about the drop //If we are using droppables, inform the manager about the drop
var that = this, var that = this,
dropped = false; dropped = false;
if ($.ui.ddmanager && !this.options.dropBehaviour) { if ( $.ui.ddmanager && !this.options.dropBehaviour ) {
dropped = $.ui.ddmanager.drop(this, event); dropped = $.ui.ddmanager.drop( this, event );
} }
//if a drop comes from outside (a sortable) //if a drop comes from outside (a sortable)
if (this.dropped) { if ( this.dropped ) {
dropped = this.dropped; dropped = this.dropped;
this.dropped = false; this.dropped = false;
} }
if ((this.options.revert === "invalid" && !dropped) || (this.options.revert === "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) { if ( ( this.options.revert === "invalid" && !dropped ) || ( this.options.revert === "valid" && dropped ) || this.options.revert === true || ( $.isFunction( this.options.revert ) && this.options.revert.call( this.element, dropped ) ) ) {
$(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { $( this.helper ).animate( this.originalPosition, parseInt( this.options.revertDuration, 10 ), function() {
if (that._trigger("stop", event) !== false) { if ( that._trigger( "stop", event ) !== false ) {
that._clear(); that._clear();
} }
}); } );
} else { } else {
if (this._trigger("stop", event) !== false) { if ( this._trigger( "stop", event ) !== false ) {
this._clear(); this._clear();
} }
} }
@ -308,22 +309,23 @@ $.widget("ui.draggable", $.ui.mouse, {
//If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003) //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
if ( $.ui.ddmanager ) { if ( $.ui.ddmanager ) {
$.ui.ddmanager.dragStop(this, event); $.ui.ddmanager.dragStop( this, event );
} }
// Only need to focus if the event occurred on the draggable itself, see #10527 // Only need to focus if the event occurred on the draggable itself, see #10527
if ( this.handleElement.is( event.target ) ) { if ( this.handleElement.is( event.target ) ) {
// The interaction is over; whether or not the click resulted in a drag, focus the element // The interaction is over; whether or not the click resulted in a drag, focus the element
this.element.trigger( "focus" ); this.element.trigger( "focus" );
} }
return $.ui.mouse.prototype._mouseUp.call(this, event); return $.ui.mouse.prototype._mouseUp.call( this, event );
}, },
cancel: function() { cancel: function() {
if (this.helper.is(".ui-draggable-dragging")) { if ( this.helper.is( ".ui-draggable-dragging" ) ) {
this._mouseUp({}); this._mouseUp( {} );
} else { } else {
this._clear(); this._clear();
} }
@ -332,7 +334,7 @@ $.widget("ui.draggable", $.ui.mouse, {
}, },
_getHandle: function(event) { _getHandle: function( event ) {
return this.options.handle ? return this.options.handle ?
!!$( event.target ).closest( this.element.find( this.options.handle ) ).length : !!$( event.target ).closest( this.element.find( this.options.handle ) ).length :
true; true;
@ -348,7 +350,7 @@ $.widget("ui.draggable", $.ui.mouse, {
this._removeClass( this.handleElement, "ui-draggable-handle" ); this._removeClass( this.handleElement, "ui-draggable-handle" );
}, },
_createHelper: function(event) { _createHelper: function( event ) {
var o = this.options, var o = this.options,
helperIsFunction = $.isFunction( o.helper ), helperIsFunction = $.isFunction( o.helper ),
@ -358,8 +360,8 @@ $.widget("ui.draggable", $.ui.mouse, {
this.element.clone().removeAttr( "id" ) : this.element.clone().removeAttr( "id" ) :
this.element ); this.element );
if (!helper.parents("body").length) { if ( !helper.parents( "body" ).length ) {
helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo)); helper.appendTo( ( o.appendTo === "parent" ? this.element[ 0 ].parentNode : o.appendTo ) );
} }
// Http://bugs.jqueryui.com/ticket/9446 // Http://bugs.jqueryui.com/ticket/9446
@ -369,8 +371,8 @@ $.widget("ui.draggable", $.ui.mouse, {
this._setPositionRelative(); this._setPositionRelative();
} }
if (helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) { if ( helper[ 0 ] !== this.element[ 0 ] && !( /(fixed|absolute)/ ).test( helper.css( "position" ) ) ) {
helper.css("position", "absolute"); helper.css( "position", "absolute" );
} }
return helper; return helper;
@ -383,23 +385,23 @@ $.widget("ui.draggable", $.ui.mouse, {
} }
}, },
_adjustOffsetFromHelper: function(obj) { _adjustOffsetFromHelper: function( obj ) {
if (typeof obj === "string") { if ( typeof obj === "string" ) {
obj = obj.split(" "); obj = obj.split( " " );
} }
if ($.isArray(obj)) { if ( $.isArray( obj ) ) {
obj = { left: +obj[0], top: +obj[1] || 0 }; obj = { left: +obj[ 0 ], top: +obj[ 1 ] || 0 };
} }
if ("left" in obj) { if ( "left" in obj ) {
this.offset.click.left = obj.left + this.margins.left; this.offset.click.left = obj.left + this.margins.left;
} }
if ("right" in obj) { if ( "right" in obj ) {
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
} }
if ("top" in obj) { if ( "top" in obj ) {
this.offset.click.top = obj.top + this.margins.top; this.offset.click.top = obj.top + this.margins.top;
} }
if ("bottom" in obj) { if ( "bottom" in obj ) {
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
} }
}, },
@ -418,7 +420,7 @@ $.widget("ui.draggable", $.ui.mouse, {
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
if (this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) { if ( this.cssPosition === "absolute" && this.scrollParent[ 0 ] !== document && $.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {
po.left += this.scrollParent.scrollLeft(); po.left += this.scrollParent.scrollLeft();
po.top += this.scrollParent.scrollTop(); po.top += this.scrollParent.scrollTop();
} }
@ -428,8 +430,8 @@ $.widget("ui.draggable", $.ui.mouse, {
} }
return { return {
top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"), 10) || 0), top: po.top + ( parseInt( this.offsetParent.css( "borderTopWidth" ), 10 ) || 0 ),
left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"), 10) || 0) left: po.left + ( parseInt( this.offsetParent.css( "borderLeftWidth" ), 10 ) || 0 )
}; };
}, },
@ -443,18 +445,18 @@ $.widget("ui.draggable", $.ui.mouse, {
scrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] ); scrollIsRootNode = this._isRootNode( this.scrollParent[ 0 ] );
return { return {
top: p.top - ( parseInt(this.helper.css( "top" ), 10) || 0 ) + ( !scrollIsRootNode ? this.scrollParent.scrollTop() : 0 ), top: p.top - ( parseInt( this.helper.css( "top" ), 10 ) || 0 ) + ( !scrollIsRootNode ? this.scrollParent.scrollTop() : 0 ),
left: p.left - ( parseInt(this.helper.css( "left" ), 10) || 0 ) + ( !scrollIsRootNode ? this.scrollParent.scrollLeft() : 0 ) left: p.left - ( parseInt( this.helper.css( "left" ), 10 ) || 0 ) + ( !scrollIsRootNode ? this.scrollParent.scrollLeft() : 0 )
}; };
}, },
_cacheMargins: function() { _cacheMargins: function() {
this.margins = { this.margins = {
left: (parseInt(this.element.css("marginLeft"), 10) || 0), left: ( parseInt( this.element.css( "marginLeft" ), 10 ) || 0 ),
top: (parseInt(this.element.css("marginTop"), 10) || 0), top: ( parseInt( this.element.css( "marginTop" ), 10 ) || 0 ),
right: (parseInt(this.element.css("marginRight"), 10) || 0), right: ( parseInt( this.element.css( "marginRight" ), 10 ) || 0 ),
bottom: (parseInt(this.element.css("marginBottom"), 10) || 0) bottom: ( parseInt( this.element.css( "marginBottom" ), 10 ) || 0 )
}; };
}, },
@ -488,7 +490,7 @@ $.widget("ui.draggable", $.ui.mouse, {
return; return;
} }
if ( o.containment === "document") { if ( o.containment === "document" ) {
this.containment = [ this.containment = [
0, 0,
0, 0,
@ -535,9 +537,9 @@ $.widget("ui.draggable", $.ui.mouse, {
this.relativeContainer = c; this.relativeContainer = c;
}, },
_convertPositionTo: function(d, pos) { _convertPositionTo: function( d, pos ) {
if (!pos) { if ( !pos ) {
pos = this.position; pos = this.position;
} }
@ -549,13 +551,13 @@ $.widget("ui.draggable", $.ui.mouse, {
pos.top + // The absolute mouse position pos.top + // The absolute mouse position
this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border) this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
( ( this.cssPosition === "fixed" ? -this.offset.scroll.top : ( scrollIsRootNode ? 0 : this.offset.scroll.top ) ) * mod) ( ( this.cssPosition === "fixed" ? -this.offset.scroll.top : ( scrollIsRootNode ? 0 : this.offset.scroll.top ) ) * mod )
), ),
left: ( left: (
pos.left + // The absolute mouse position pos.left + // The absolute mouse position
this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border) this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
( ( this.cssPosition === "fixed" ? -this.offset.scroll.left : ( scrollIsRootNode ? 0 : this.offset.scroll.left ) ) * mod) ( ( this.cssPosition === "fixed" ? -this.offset.scroll.left : ( scrollIsRootNode ? 0 : this.offset.scroll.left ) ) * mod )
) )
}; };
@ -585,7 +587,7 @@ $.widget("ui.draggable", $.ui.mouse, {
// If we are not dragging yet, we won't check for options // If we are not dragging yet, we won't check for options
if ( constrainPosition ) { if ( constrainPosition ) {
if ( this.containment ) { if ( this.containment ) {
if ( this.relativeContainer ){ if ( this.relativeContainer ) {
co = this.relativeContainer.offset(); co = this.relativeContainer.offset();
containment = [ containment = [
this.containment[ 0 ] + co.left, this.containment[ 0 ] + co.left,
@ -597,27 +599,28 @@ $.widget("ui.draggable", $.ui.mouse, {
containment = this.containment; containment = this.containment;
} }
if (event.pageX - this.offset.click.left < containment[0]) { if ( event.pageX - this.offset.click.left < containment[ 0 ] ) {
pageX = containment[0] + this.offset.click.left; pageX = containment[ 0 ] + this.offset.click.left;
} }
if (event.pageY - this.offset.click.top < containment[1]) { if ( event.pageY - this.offset.click.top < containment[ 1 ] ) {
pageY = containment[1] + this.offset.click.top; pageY = containment[ 1 ] + this.offset.click.top;
} }
if (event.pageX - this.offset.click.left > containment[2]) { if ( event.pageX - this.offset.click.left > containment[ 2 ] ) {
pageX = containment[2] + this.offset.click.left; pageX = containment[ 2 ] + this.offset.click.left;
} }
if (event.pageY - this.offset.click.top > containment[3]) { if ( event.pageY - this.offset.click.top > containment[ 3 ] ) {
pageY = containment[3] + this.offset.click.top; pageY = containment[ 3 ] + this.offset.click.top;
} }
} }
if (o.grid) { if ( o.grid ) {
//Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
pageY = containment ? ((top - this.offset.click.top >= containment[1] || top - this.offset.click.top > containment[3]) ? top : ((top - this.offset.click.top >= containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX; //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
pageX = containment ? ((left - this.offset.click.left >= containment[0] || left - this.offset.click.left > containment[2]) ? left : ((left - this.offset.click.left >= containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; top = o.grid[ 1 ] ? this.originalPageY + Math.round( ( pageY - this.originalPageY ) / o.grid[ 1 ] ) * o.grid[ 1 ] : this.originalPageY;
pageY = containment ? ( ( top - this.offset.click.top >= containment[ 1 ] || top - this.offset.click.top > containment[ 3 ] ) ? top : ( ( top - this.offset.click.top >= containment[ 1 ] ) ? top - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) : top;
left = o.grid[ 0 ] ? this.originalPageX + Math.round( ( pageX - this.originalPageX ) / o.grid[ 0 ] ) * o.grid[ 0 ] : this.originalPageX;
pageX = containment ? ( ( left - this.offset.click.left >= containment[ 0 ] || left - this.offset.click.left > containment[ 2 ] ) ? left : ( ( left - this.offset.click.left >= containment[ 0 ] ) ? left - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) : left;
} }
if ( o.axis === "y" ) { if ( o.axis === "y" ) {
@ -650,7 +653,7 @@ $.widget("ui.draggable", $.ui.mouse, {
_clear: function() { _clear: function() {
this._removeClass( this.helper, "ui-draggable-dragging" ); this._removeClass( this.helper, "ui-draggable-dragging" );
if (this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) { if ( this.helper[ 0 ] !== this.element[ 0 ] && !this.cancelHelperRemoval ) {
this.helper.remove(); this.helper.remove();
} }
this.helper = null; this.helper = null;
@ -685,16 +688,16 @@ $.widget("ui.draggable", $.ui.mouse, {
}; };
} }
}); } );
$.ui.plugin.add( "draggable", "connectToSortable", { $.ui.plugin.add( "draggable", "connectToSortable", {
start: function( event, ui, draggable ) { start: function( event, ui, draggable ) {
var uiSortable = $.extend( {}, ui, { var uiSortable = $.extend( {}, ui, {
item: draggable.element item: draggable.element
}); } );
draggable.sortables = []; draggable.sortables = [];
$( draggable.options.connectToSortable ).each(function() { $( draggable.options.connectToSortable ).each( function() {
var sortable = $( this ).sortable( "instance" ); var sortable = $( this ).sortable( "instance" );
if ( sortable && !sortable.options.disabled ) { if ( sortable && !sortable.options.disabled ) {
@ -704,14 +707,14 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
// which is used in drag. This ensures it's initialized and synchronized // which is used in drag. This ensures it's initialized and synchronized
// with any changes that might have happened on the page since initialization. // with any changes that might have happened on the page since initialization.
sortable.refreshPositions(); sortable.refreshPositions();
sortable._trigger("activate", event, uiSortable); sortable._trigger( "activate", event, uiSortable );
} }
}); } );
}, },
stop: function( event, ui, draggable ) { stop: function( event, ui, draggable ) {
var uiSortable = $.extend( {}, ui, { var uiSortable = $.extend( {}, ui, {
item: draggable.element item: draggable.element
}); } );
draggable.cancelHelperRemoval = false; draggable.cancelHelperRemoval = false;
@ -734,12 +737,13 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
left: sortable.placeholder.css( "left" ) left: sortable.placeholder.css( "left" )
}; };
sortable._mouseStop(event); sortable._mouseStop( event );
// Once drag has ended, the sortable should return to using // Once drag has ended, the sortable should return to using
// its original helper, not the shared helper from draggable // its original helper, not the shared helper from draggable
sortable.options.helper = sortable.options._helper; sortable.options.helper = sortable.options._helper;
} else { } else {
// Prevent this Sortable from removing the helper. // Prevent this Sortable from removing the helper.
// However, don't set the draggable to remove the helper // However, don't set the draggable to remove the helper
// either as another connected Sortable may yet handle the removal. // either as another connected Sortable may yet handle the removal.
@ -747,7 +751,7 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
sortable._trigger( "deactivate", event, uiSortable ); sortable._trigger( "deactivate", event, uiSortable );
} }
}); } );
}, },
drag: function( event, ui, draggable ) { drag: function( event, ui, draggable ) {
$.each( draggable.sortables, function() { $.each( draggable.sortables, function() {
@ -763,6 +767,7 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
innermostIntersecting = true; innermostIntersecting = true;
$.each( draggable.sortables, function() { $.each( draggable.sortables, function() {
// Copy over variables that sortable's _intersectsWith uses // Copy over variables that sortable's _intersectsWith uses
this.positionAbs = draggable.positionAbs; this.positionAbs = draggable.positionAbs;
this.helperProportions = draggable.helperProportions; this.helperProportions = draggable.helperProportions;
@ -775,10 +780,11 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
} }
return innermostIntersecting; return innermostIntersecting;
}); } );
} }
if ( innermostIntersecting ) { if ( innermostIntersecting ) {
// If it intersects, we use a little isOver variable and set it once, // If it intersects, we use a little isOver variable and set it once,
// so that the move-in stuff gets fired only once. // so that the move-in stuff gets fired only once.
if ( !sortable.isOver ) { if ( !sortable.isOver ) {
@ -823,7 +829,7 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
// adding to one sortable changes the location of the other sortables (#9675) // adding to one sortable changes the location of the other sortables (#9675)
$.each( draggable.sortables, function() { $.each( draggable.sortables, function() {
this.refreshPositions(); this.refreshPositions();
}); } );
// Hack so receive/update callbacks work (mostly) // Hack so receive/update callbacks work (mostly)
draggable.currentItem = draggable.element; draggable.currentItem = draggable.element;
@ -832,12 +838,14 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
if ( sortable.currentItem ) { if ( sortable.currentItem ) {
sortable._mouseDrag( event ); sortable._mouseDrag( event );
// Copy the sortable's position because the draggable's can potentially reflect // Copy the sortable's position because the draggable's can potentially reflect
// a relative position, while sortable is always absolute, which the dragged // a relative position, while sortable is always absolute, which the dragged
// element has now become. (#8809) // element has now become. (#8809)
ui.position = sortable.position; ui.position = sortable.position;
} }
} else { } else {
// If it doesn't intersect with the sortable, and it intersected before, // If it doesn't intersect with the sortable, and it intersected before,
// we fake the drag stop of the sortable, but make sure it doesn't remove // we fake the drag stop of the sortable, but make sure it doesn't remove
// the helper by using cancelHelperRemoval. // the helper by using cancelHelperRemoval.
@ -878,49 +886,49 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
// from one sortable changes the location of other sortables (#9675) // from one sortable changes the location of other sortables (#9675)
$.each( draggable.sortables, function() { $.each( draggable.sortables, function() {
this.refreshPositions(); this.refreshPositions();
}); } );
} }
} }
}); } );
} }
}); } );
$.ui.plugin.add("draggable", "cursor", { $.ui.plugin.add( "draggable", "cursor", {
start: function( event, ui, instance ) { start: function( event, ui, instance ) {
var t = $( "body" ), var t = $( "body" ),
o = instance.options; o = instance.options;
if (t.css("cursor")) { if ( t.css( "cursor" ) ) {
o._cursor = t.css("cursor"); o._cursor = t.css( "cursor" );
} }
t.css("cursor", o.cursor); t.css( "cursor", o.cursor );
}, },
stop: function( event, ui, instance ) { stop: function( event, ui, instance ) {
var o = instance.options; var o = instance.options;
if (o._cursor) { if ( o._cursor ) {
$("body").css("cursor", o._cursor); $( "body" ).css( "cursor", o._cursor );
} }
} }
}); } );
$.ui.plugin.add("draggable", "opacity", { $.ui.plugin.add( "draggable", "opacity", {
start: function( event, ui, instance ) { start: function( event, ui, instance ) {
var t = $( ui.helper ), var t = $( ui.helper ),
o = instance.options; o = instance.options;
if (t.css("opacity")) { if ( t.css( "opacity" ) ) {
o._opacity = t.css("opacity"); o._opacity = t.css( "opacity" );
} }
t.css("opacity", o.opacity); t.css( "opacity", o.opacity );
}, },
stop: function( event, ui, instance ) { stop: function( event, ui, instance ) {
var o = instance.options; var o = instance.options;
if (o._opacity) { if ( o._opacity ) {
$(ui.helper).css("opacity", o._opacity); $( ui.helper ).css( "opacity", o._opacity );
} }
} }
}); } );
$.ui.plugin.add("draggable", "scroll", { $.ui.plugin.add( "draggable", "scroll", {
start: function( event, ui, i ) { start: function( event, ui, i ) {
if ( !i.scrollParentNotHidden ) { if ( !i.scrollParentNotHidden ) {
i.scrollParentNotHidden = i.helper.scrollParent( false ); i.scrollParentNotHidden = i.helper.scrollParent( false );
@ -956,49 +964,49 @@ $.ui.plugin.add("draggable", "scroll", {
} else { } else {
if (!o.axis || o.axis !== "x") { if ( !o.axis || o.axis !== "x" ) {
if (event.pageY - $(document).scrollTop() < o.scrollSensitivity) { if ( event.pageY - $( document ).scrollTop() < o.scrollSensitivity ) {
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); scrolled = $( document ).scrollTop( $( document ).scrollTop() - o.scrollSpeed );
} else if ($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) { } else if ( $( window ).height() - ( event.pageY - $( document ).scrollTop() ) < o.scrollSensitivity ) {
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); scrolled = $( document ).scrollTop( $( document ).scrollTop() + o.scrollSpeed );
} }
} }
if (!o.axis || o.axis !== "y") { if ( !o.axis || o.axis !== "y" ) {
if (event.pageX - $(document).scrollLeft() < o.scrollSensitivity) { if ( event.pageX - $( document ).scrollLeft() < o.scrollSensitivity ) {
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); scrolled = $( document ).scrollLeft( $( document ).scrollLeft() - o.scrollSpeed );
} else if ($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) { } else if ( $( window ).width() - ( event.pageX - $( document ).scrollLeft() ) < o.scrollSensitivity ) {
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); scrolled = $( document ).scrollLeft( $( document ).scrollLeft() + o.scrollSpeed );
} }
} }
} }
if (scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) { if ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) {
$.ui.ddmanager.prepareOffsets(i, event); $.ui.ddmanager.prepareOffsets( i, event );
} }
} }
}); } );
$.ui.plugin.add("draggable", "snap", { $.ui.plugin.add( "draggable", "snap", {
start: function( event, ui, i ) { start: function( event, ui, i ) {
var o = i.options; var o = i.options;
i.snapElements = []; i.snapElements = [];
$(o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap).each(function() { $( o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap ).each( function() {
var $t = $(this), var $t = $( this ),
$o = $t.offset(); $o = $t.offset();
if (this !== i.element[0]) { if ( this !== i.element[ 0 ] ) {
i.snapElements.push({ i.snapElements.push( {
item: this, item: this,
width: $t.outerWidth(), height: $t.outerHeight(), width: $t.outerWidth(), height: $t.outerHeight(),
top: $o.top, left: $o.left top: $o.top, left: $o.left
}); } );
} }
}); } );
}, },
drag: function( event, ui, inst ) { drag: function( event, ui, inst ) {
@ -1009,108 +1017,108 @@ $.ui.plugin.add("draggable", "snap", {
x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width, x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height; y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
for (i = inst.snapElements.length - 1; i >= 0; i--){ for ( i = inst.snapElements.length - 1; i >= 0; i-- ) {
l = inst.snapElements[i].left - inst.margins.left; l = inst.snapElements[ i ].left - inst.margins.left;
r = l + inst.snapElements[i].width; r = l + inst.snapElements[ i ].width;
t = inst.snapElements[i].top - inst.margins.top; t = inst.snapElements[ i ].top - inst.margins.top;
b = t + inst.snapElements[i].height; b = t + inst.snapElements[ i ].height;
if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d || !$.contains( inst.snapElements[ i ].item.ownerDocument, inst.snapElements[ i ].item ) ) { if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d || !$.contains( inst.snapElements[ i ].item.ownerDocument, inst.snapElements[ i ].item ) ) {
if (inst.snapElements[i].snapping) { if ( inst.snapElements[ i ].snapping ) {
(inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); ( inst.options.snap.release && inst.options.snap.release.call( inst.element, event, $.extend( inst._uiHash(), { snapItem: inst.snapElements[ i ].item } ) ) );
} }
inst.snapElements[i].snapping = false; inst.snapElements[ i ].snapping = false;
continue; continue;
} }
if (o.snapMode !== "inner") { if ( o.snapMode !== "inner" ) {
ts = Math.abs(t - y2) <= d; ts = Math.abs( t - y2 ) <= d;
bs = Math.abs(b - y1) <= d; bs = Math.abs( b - y1 ) <= d;
ls = Math.abs(l - x2) <= d; ls = Math.abs( l - x2 ) <= d;
rs = Math.abs(r - x1) <= d; rs = Math.abs( r - x1 ) <= d;
if (ts) { if ( ts ) {
ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top; ui.position.top = inst._convertPositionTo( "relative", { top: t - inst.helperProportions.height, left: 0 } ).top;
} }
if (bs) { if ( bs ) {
ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top; ui.position.top = inst._convertPositionTo( "relative", { top: b, left: 0 } ).top;
} }
if (ls) { if ( ls ) {
ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left; ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: l - inst.helperProportions.width } ).left;
} }
if (rs) { if ( rs ) {
ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left; ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: r } ).left;
} }
} }
first = (ts || bs || ls || rs); first = ( ts || bs || ls || rs );
if (o.snapMode !== "outer") { if ( o.snapMode !== "outer" ) {
ts = Math.abs(t - y1) <= d; ts = Math.abs( t - y1 ) <= d;
bs = Math.abs(b - y2) <= d; bs = Math.abs( b - y2 ) <= d;
ls = Math.abs(l - x1) <= d; ls = Math.abs( l - x1 ) <= d;
rs = Math.abs(r - x2) <= d; rs = Math.abs( r - x2 ) <= d;
if (ts) { if ( ts ) {
ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top; ui.position.top = inst._convertPositionTo( "relative", { top: t, left: 0 } ).top;
} }
if (bs) { if ( bs ) {
ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top; ui.position.top = inst._convertPositionTo( "relative", { top: b - inst.helperProportions.height, left: 0 } ).top;
} }
if (ls) { if ( ls ) {
ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left; ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: l } ).left;
} }
if (rs) { if ( rs ) {
ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left; ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: r - inst.helperProportions.width } ).left;
} }
} }
if (!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) { if ( !inst.snapElements[ i ].snapping && ( ts || bs || ls || rs || first ) ) {
(inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); ( inst.options.snap.snap && inst.options.snap.snap.call( inst.element, event, $.extend( inst._uiHash(), { snapItem: inst.snapElements[ i ].item } ) ) );
} }
inst.snapElements[i].snapping = (ts || bs || ls || rs || first); inst.snapElements[ i ].snapping = ( ts || bs || ls || rs || first );
} }
} }
}); } );
$.ui.plugin.add("draggable", "stack", { $.ui.plugin.add( "draggable", "stack", {
start: function( event, ui, instance ) { start: function( event, ui, instance ) {
var min, var min,
o = instance.options, o = instance.options,
group = $.makeArray($(o.stack)).sort(function(a, b) { group = $.makeArray( $( o.stack ) ).sort( function( a, b ) {
return (parseInt($(a).css("zIndex"), 10) || 0) - (parseInt($(b).css("zIndex"), 10) || 0); return ( parseInt( $( a ).css( "zIndex" ), 10 ) || 0 ) - ( parseInt( $( b ).css( "zIndex" ), 10 ) || 0 );
}); } );
if (!group.length) { return; } if ( !group.length ) { return; }
min = parseInt($(group[0]).css("zIndex"), 10) || 0; min = parseInt( $( group[ 0 ] ).css( "zIndex" ), 10 ) || 0;
$(group).each(function(i) { $( group ).each( function( i ) {
$(this).css("zIndex", min + i); $( this ).css( "zIndex", min + i );
}); } );
this.css("zIndex", (min + group.length)); this.css( "zIndex", ( min + group.length ) );
} }
}); } );
$.ui.plugin.add("draggable", "zIndex", { $.ui.plugin.add( "draggable", "zIndex", {
start: function( event, ui, instance ) { start: function( event, ui, instance ) {
var t = $( ui.helper ), var t = $( ui.helper ),
o = instance.options; o = instance.options;
if (t.css("zIndex")) { if ( t.css( "zIndex" ) ) {
o._zIndex = t.css("zIndex"); o._zIndex = t.css( "zIndex" );
} }
t.css("zIndex", o.zIndex); t.css( "zIndex", o.zIndex );
}, },
stop: function( event, ui, instance ) { stop: function( event, ui, instance ) {
var o = instance.options; var o = instance.options;
if (o._zIndex) { if ( o._zIndex ) {
$(ui.helper).css("zIndex", o._zIndex); $( ui.helper ).css( "zIndex", o._zIndex );
} }
} }
}); } );
return $.ui.draggable; return $.ui.draggable;
})); } ) );