aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Schmitz <arschmitz@gmail.com>2015-08-24 08:59:44 -0400
committerAlexander Schmitz <arschmitz@gmail.com>2015-09-11 08:29:09 -0400
commit8336ba7b694fbf85ec893ce79343a9f510a1e0b0 (patch)
tree19894ab900093e0291fecf27e1cfcadb8491e6b9
parent0cab9f0a2f1f91ae671d57dba5e5bdcde1f60622 (diff)
downloadjquery-ui-8336ba7b694fbf85ec893ce79343a9f510a1e0b0.tar.gz
jquery-ui-8336ba7b694fbf85ec893ce79343a9f510a1e0b0.zip
Draggable: Style updates
Ref #14246
-rw-r--r--tests/unit/draggable/common.js2
-rw-r--r--tests/unit/draggable/core.js114
-rw-r--r--tests/unit/draggable/events.js46
-rw-r--r--tests/unit/draggable/helper.js32
-rw-r--r--tests/unit/draggable/methods.js40
-rw-r--r--tests/unit/draggable/options.js511
-rw-r--r--ui/widgets/draggable.js394
7 files changed, 579 insertions, 560 deletions
diff --git a/tests/unit/draggable/common.js b/tests/unit/draggable/common.js
index c9a687ce3..228bba5dc 100644
--- a/tests/unit/draggable/common.js
+++ b/tests/unit/draggable/common.js
@@ -43,6 +43,6 @@ common.testWidget( "draggable", {
start: null,
stop: null
}
-});
+} );
} );
diff --git a/tests/unit/draggable/core.js b/tests/unit/draggable/core.js
index d6eaeb2aa..8bc751e0e 100644
--- a/tests/unit/draggable/core.js
+++ b/tests/unit/draggable/core.js
@@ -14,84 +14,84 @@ test( "element types", function( assert ) {
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
",acronym,code,samp,kbd,var,img,hr" +
",input,button,label,select,iframe"
- ).split(",");
+ ).split( "," );
expect( typeNames.length * 2 );
$.each( typeNames, function( i ) {
var offsetBefore, offsetAfter,
typeName = typeNames[ i ],
- el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
+ el = $( document.createElement( typeName ) ).appendTo( "#qunit-fixture" );
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();
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.draggable( "destroy" );
el.remove();
- });
-});
+ } );
+} );
test( "No options, relative", function() {
expect( 2 );
testHelper.shouldMove( $( "#draggable1" ).draggable(), "no options, relative" );
-});
+} );
test( "No options, absolute", function() {
expect( 2 );
testHelper.shouldMove( $( "#draggable2" ).draggable(), "no options, absolute" );
-});
+} );
test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 );
$( "#draggable1" )
.append(
- $("<div>")
- .addClass("ui-resizable-handle ui-resizable-w")
- .append( $("<div>") )
+ $( "<div>" )
+ .addClass( "ui-resizable-handle ui-resizable-w" )
+ .append( $( "<div>" ) )
);
- var handle = $(".ui-resizable-w div"),
- target = $( "#draggable1" ).draggable().resizable({ handles: "all" });
+ 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 } );
+ 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 } );
+ handle.simulate( "mouseover" ).simulate( "drag", { dx: 50 } );
equal( target.width(), 200, "compare width" );
-});
+} );
test( "#8269: Removing draggable element on drop", function() {
expect( 2 );
- var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
+ var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
stop: function() {
ok( true, "stop still called despite element being removed from DOM on drop" );
}
- }),
+ } ),
dropOffset = $( "#droppable" ).offset();
- $( "#droppable" ).droppable({
+ $( "#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 ( testHelper.unreliableContains ) {
@@ -102,31 +102,31 @@ test( "#8269: Removing draggable element on drop", function() {
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 });
+ 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 });
- });
+ $( document ).simulate( "mousemove", { button: -1 } );
+ } );
testHelper.shouldMove( element, "element is draggable" );
-});
+} );
test( "#6258: not following mouse when scrolled and using overflow-y: scroll", function() {
expect( 2 );
- var element = $( "#draggable1" ).draggable({
+ 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" );
@@ -136,7 +136,7 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
.scrollTop( 0 )
.scrollLeft( 0 );
}
- }),
+ } ),
oldOverflowY = $( "html" ).css( "overflow-y" ),
oldOverflowX = $( "html" ).css( "overflow-x" );
@@ -152,19 +152,19 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
dx: 1,
dy: 1,
moves: 1
- });
-});
+ } );
+} );
test( "#9315: jumps down with offset of scrollbar", function() {
expect( 2 );
- var element = $( "#draggable2" ).draggable({
+ 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 );
}
- });
+ } );
testHelper.forceScrollableWindow();
@@ -174,21 +174,23 @@ test( "#9315: jumps down with offset of scrollbar", function() {
dx: 1,
dy: 1,
moves: 1
- });
-});
+ } );
+} );
test( "scroll offset with fixed ancestors", function() {
expect( 2 );
var startValue = 300,
element = $( "#draggable1" )
+
// http://bugs.jqueryui.com/ticket/5009
// scroll not working with parent's position fixed
.wrap( "<div id='wrapper' />" )
+
// http://bugs.jqueryui.com/ticket/9612
// abspos elements inside of fixed elements moving away from the mouse when scrolling
.wrap( "<div id='wrapper2' />" )
- .draggable({
+ .draggable( {
drag: function() {
startValue += 100;
$( 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" );
$( document ).scrollTop( 0 ).scrollLeft( 0 );
}
- });
+ } );
testHelper.forceScrollableWindow();
@@ -209,10 +211,10 @@ test( "scroll offset with fixed ancestors", function() {
dx: 10,
dy: 10,
moves: 3
- });
-});
+ } );
+} );
-$( [ "hidden", "auto", "scroll" ] ).each(function() {
+$( [ "hidden", "auto", "scroll" ] ).each( function() {
var overflow = this;
// Http://bugs.jqueryui.com/ticket/9379 - position bug in scrollable div
@@ -221,9 +223,9 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
expect( 2 );
$( "#qunit-fixture" ).html( "<div id='outer'><div id='inner'></div><div id='dragged'>a</div></div>" );
- $( "#inner" ).css({ position: "absolute", width: "500px", height: "500px" });
- $( "#outer" ).css({ position: "absolute", width: "300px", height: "300px" });
- $( "#dragged" ).css({ width: "10px", height: "10px" });
+ $( "#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,
@@ -232,7 +234,7 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
// We scroll after each drag event, so subtract 1 from number of moves for expected
expected = delta + ( ( moves - 1 ) * dragDelta ),
- element = $( "#dragged" ).draggable({
+ element = $( "#dragged" ).draggable( {
drag: function() {
startValue += dragDelta;
$( "#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.top, expected, "top position is correct when grandparent is scrolled" );
}
- });
+ } );
$( "#outer" ).css( "overflow", overflow );
@@ -249,9 +251,9 @@ $( [ "hidden", "auto", "scroll" ] ).each(function() {
dy: delta,
dx: delta,
moves: moves
- });
- });
-});
+ } );
+ } );
+} );
test( "#5727: draggable from iframe", function() {
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
// and these testHelper.shouldMove relies on events for testing
//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() {
expect( 2 );
@@ -282,12 +284,12 @@ test( "#8399: A draggable should become the active element after you are finishe
$( document ).one( "mousemove", function() {
notStrictEqual( document.activeElement, element.get( 0 ), "moving a draggable anchor did not make it the active element" );
- });
+ } );
testHelper.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 );
@@ -310,8 +312,8 @@ asyncTest( "blur behavior", function() {
// 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 );
@@ -328,7 +330,7 @@ test( "ui-draggable-handle assigned to appropriate element", function( assert )
element.draggable( "destroy" );
assert.lacksClasses( element.find( "p" ), "ui-draggable-handle" );
-});
+} );
test( "ui-draggable-handle managed correctly in nested draggables", function( assert ) {
expect( 4 );
@@ -341,6 +343,6 @@ test( "ui-draggable-handle managed correctly in nested draggables", function( as
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" );
-});
+} );
} );
diff --git a/tests/unit/draggable/events.js b/tests/unit/draggable/events.js
index 7e276092b..36a5a8705 100644
--- a/tests/unit/draggable/events.js
+++ b/tests/unit/draggable/events.js
@@ -7,12 +7,12 @@ var element;
module( "draggable: events", {
setup: function() {
- element = $("<div>").appendTo("#qunit-fixture");
+ element = $( "<div>" ).appendTo( "#qunit-fixture" );
},
teardown: function() {
- element.draggable("destroy");
+ element.draggable( "destroy" );
}
-});
+} );
test( "callbacks occurrence count", function() {
expect( 3 );
@@ -21,7 +21,7 @@ test( "callbacks occurrence count", function() {
stop = 0,
dragc = 0;
- element.draggable({
+ element.draggable( {
start: function() {
start++;
},
@@ -31,17 +31,17 @@ test( "callbacks occurrence count", function() {
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 );
@@ -50,7 +50,7 @@ test( "stopping the start callback", function() {
stop = 0,
dragc = 0;
- element.draggable({
+ element.draggable( {
start: function() {
start++;
return false;
@@ -61,17 +61,17 @@ test( "stopping the start callback", function() {
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 );
@@ -80,7 +80,7 @@ test( "stopping the drag callback", function() {
stop = 0,
dragc = 0;
- element.draggable({
+ element.draggable( {
start: function() {
start++;
},
@@ -91,34 +91,34 @@ test( "stopping the drag callback", function() {
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({
+ element.draggable( {
helper: "clone",
stop: function() {
return false;
}
- });
+ } );
element.simulate( "drag", {
dx: 10,
dy: 10
- });
+ } );
ok( element.draggable( "instance" ).helper, "the clone should not be deleted if the stop callback is stopped" );
-});
+} );
// http://bugs.jqueryui.com/ticket/6884
// Draggable: ui.offset.left differs between the "start" and "drag" hooks
@@ -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.draggable({
+ element.draggable( {
start: function( event, ui ) {
startPos = ui.position;
startOffset = ui.offset;
@@ -142,13 +142,13 @@ test( "position and offset in hash is consistent between start, drag, and stop",
stopPos = ui.position;
stopOffset = ui.offset;
}
- });
+ } );
element.simulate( "drag", {
dx: 10,
dy: 10,
moves: 1
- });
+ } );
startPos.left += 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( startOffset, dragOffset, "start offset equals drag offset plus distance" );
deepEqual( dragOffset, stopOffset, "drag offset equals stop offset" );
-});
+} );
} );
diff --git a/tests/unit/draggable/helper.js b/tests/unit/draggable/helper.js
index 7aabe2a00..02a6ddaf5 100644
--- a/tests/unit/draggable/helper.js
+++ b/tests/unit/draggable/helper.js
@@ -8,12 +8,13 @@ return $.extend( helper, {
// 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() {
+ unreliableContains: ( function() {
var element = $( "<div>" );
return $.contains( element[ 0 ].ownerDocument, element[ 0 ] );
- })(),
+ } )(),
testDragPosition: function( el, dx, dy, expectedDX, expectedDY, msg ) {
msg = msg ? msg + "." : "";
@@ -21,7 +22,7 @@ return $.extend( helper, {
$( el ).one( "dragstop", function( event, ui ) {
var positionExpected = { left: ui.originalPosition.left + expectedDX, top: ui.originalPosition.top + expectedDY };
deepEqual( ui.position, positionExpected, "position dragged[" + dx + ", " + dy + "] " + msg );
- });
+ } );
},
testDragOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
@@ -32,7 +33,7 @@ return $.extend( helper, {
$( el ).one( "dragstop", function( event, ui ) {
deepEqual( ui.offset, offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
- });
+ } );
},
testDragHelperOffset: function( el, dx, dy, expectedDX, expectedDY, msg ) {
@@ -43,7 +44,7 @@ return $.extend( helper, {
$( el ).one( "dragstop", function( event, ui ) {
deepEqual( ui.helper.offset(), offsetExpected, "offset dragged[" + dx + ", " + dy + "] " + msg );
- });
+ } );
},
testDrag: function( el, handle, dx, dy, expectedDX, expectedDY, msg ) {
@@ -53,7 +54,7 @@ return $.extend( helper, {
$( handle ).simulate( "drag", {
dx: dx,
dy: dy
- });
+ } );
},
shouldMovePositionButNotOffset: function( el, msg, handle ) {
@@ -64,7 +65,7 @@ return $.extend( helper, {
$( handle ).simulate( "drag", {
dx: 100,
dy: 100
- });
+ } );
},
shouldMove: function( el, msg, handle ) {
@@ -86,12 +87,12 @@ return $.extend( helper, {
element.on( "dragstop", function() {
ok( false, "should not drag " + msg );
- });
+ } );
$( handle ).simulate( "drag", {
dx: 100,
dy: 100
- });
+ } );
newOffset = element.offset();
@@ -105,12 +106,12 @@ return $.extend( helper, {
setScrollable: function( what, isScrollable ) {
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 ) {
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" );
$( "#main" ).css( "position", oldPosition );
},
@@ -135,23 +136,24 @@ return $.extend( helper, {
$( el ).simulate( "drag", {
dx: x,
dy: y
- });
+ } );
},
trackMouseCss: function( el ) {
el.on( "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.on( "drag", function(e, ui) {
+ el.on( "drag", function( e, ui ) {
el.data( "last_dragged_parent", ui.helper.parent()[ 0 ] );
- });
+ } );
}
} );
diff --git a/tests/unit/draggable/methods.js b/tests/unit/draggable/methods.js
index 10a17efdb..77ba2434f 100644
--- a/tests/unit/draggable/methods.js
+++ b/tests/unit/draggable/methods.js
@@ -8,12 +8,12 @@ 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");
+ 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 );
@@ -21,10 +21,10 @@ test( "init", function() {
element.draggable();
ok( true, ".draggable() called on element" );
- $([]).draggable();
+ $( [] ).draggable();
ok( true, ".draggable() called on empty collection" );
- $("<div></div>").draggable();
+ $( "<div></div>" ).draggable();
ok( true, ".draggable() called on disconnected DOMElement" );
element.draggable( "option", "foo" );
@@ -32,52 +32,52 @@ test( "init", function() {
element.draggable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" );
-});
+} );
test( "destroy", function() {
expect( 4 );
- element.draggable().draggable("destroy");
+ element.draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on element" );
- $([]).draggable().draggable("destroy");
+ $( [] ).draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on empty collection" );
- element.draggable().draggable("destroy");
+ element.draggable().draggable( "destroy" );
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
var expected = element.draggable(),
- actual = expected.draggable("destroy");
+ actual = expected.draggable( "destroy" );
equal( actual, expected, "destroy is chainable" );
-});
+} );
test( "enable", function() {
expect( 11 );
- element.draggable({ disabled: true });
+ element.draggable( { disabled: true } );
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
- element.draggable("enable");
+ element.draggable( "enable" );
testHelper.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
- element.draggable("destroy");
- element.draggable({ disabled: true });
+ element.draggable( "destroy" );
+ element.draggable( { disabled: true } );
testHelper.shouldNotDrag( element, ".draggable({ disabled: true })" );
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)" );
var expected = element.draggable(),
- actual = expected.draggable("enable");
+ actual = expected.draggable( "enable" );
equal( actual, expected, "enable is chainable" );
-});
+} );
test( "disable", function( assert ) {
expect( 14 );
- element = $( "#draggable2" ).draggable({ disabled: false });
+ element = $( "#draggable2" ).draggable( { disabled: false } );
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "disable" );
@@ -85,7 +85,7 @@ test( "disable", function( assert ) {
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
element.draggable( "destroy" );
- element.draggable({ disabled: false });
+ element.draggable( { disabled: false } );
testHelper.shouldMove( element, ".draggable({ disabled: false })" );
element.draggable( "option", "disabled", true );
@@ -99,6 +99,6 @@ test( "disable", function( assert ) {
var expected = element.draggable(),
actual = expected.draggable( "disable" );
equal( actual, expected, "disable is chainable" );
-});
+} );
} );
diff --git a/tests/unit/draggable/options.js b/tests/unit/draggable/options.js
index bc7370e8b..2c8de5a0a 100644
--- a/tests/unit/draggable/options.js
+++ b/tests/unit/draggable/options.js
@@ -9,33 +9,33 @@ define( [
// TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: 'parent' }, default, no clone", function() {
expect( 4 );
- var element = $( "#draggable2" ).draggable({ appendTo: "parent" });
+ var element = $( "#draggable2" ).draggable( { appendTo: "parent" } );
testHelper.shouldMove( element, "absolute appendTo: parent" );
- element = $( "#draggable1" ).draggable({ appendTo: "parent" });
+ element = $( "#draggable1" ).draggable( { appendTo: "parent" } );
testHelper.shouldMove( element, "relative appendTo: parent" );
-});
+} );
// TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: Element }, no clone", function() {
expect( 4 );
- var element = $( "#draggable2" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
+ var element = $( "#draggable2" ).draggable( { appendTo: $( "#draggable2" ).parent()[ 0 ] } );
testHelper.shouldMove( element, "absolute appendTo: Element" );
- element = $( "#draggable1" ).draggable({ appendTo: $( "#draggable2" ).parent()[ 0 ] });
+ element = $( "#draggable1" ).draggable( { appendTo: $( "#draggable2" ).parent()[ 0 ] } );
testHelper.shouldMove( element, "relative appendTo: Element" );
-});
+} );
// TODO: This doesn't actually test whether append happened, possibly remove
test( "{ appendTo: Selector }, no clone", function() {
expect( 4 );
- var element = $( "#draggable2" ).draggable({ appendTo: "#main" });
+ var element = $( "#draggable2" ).draggable( { appendTo: "#main" } );
testHelper.shouldMove( element, "absolute appendTo: Selector" );
- element = $( "#draggable1" ).draggable({ appendTo: "#main" });
+ element = $( "#draggable1" ).draggable( { appendTo: "#main" } );
testHelper.shouldMove( element, "relative appendTo: Selector" );
-});
+} );
test( "{ appendTo: 'parent' }, default", function() {
expect( 2 );
@@ -48,48 +48,48 @@ test( "{ appendTo: 'parent' }, default", function() {
testHelper.move( element, 1, 1 );
equal( element.data( "last_dragged_parent" ), $( "#main" )[ 0 ] );
-});
+} );
test( "{ appendTo: Element }", function() {
expect( 1 );
var appendTo = $( "#draggable2" ).parent()[ 0 ],
- element = $( "#draggable1" ).draggable({ appendTo: appendTo });
+ element = $( "#draggable1" ).draggable( { appendTo: appendTo } );
testHelper.trackAppendedParent( element );
testHelper.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 });
+ element = $( "#draggable1" ).draggable( { appendTo: appendTo } );
testHelper.trackAppendedParent( element );
testHelper.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 });
+ element = $( "#draggable1" ).draggable( { appendTo: appendTo } );
testHelper.trackAppendedParent( element );
testHelper.move( element, 1, 1 );
- equal( element.data( "last_dragged_parent" ), $(appendTo)[ 0 ] );
-});
+ equal( element.data( "last_dragged_parent" ), $( appendTo )[ 0 ] );
+} );
test( "appendTo, default, switching after initialization", function() {
expect( 2 );
- var element = $( "#draggable1" ).draggable({ helper: "clone" });
+ var element = $( "#draggable1" ).draggable( { helper: "clone" } );
testHelper.trackAppendedParent( element );
@@ -101,25 +101,25 @@ test( "appendTo, default, switching after initialization", function() {
element.draggable( "option", "appendTo", $( "#qunit-fixture" ) );
testHelper.move( element, 2, 2 );
equal( element.data( "last_dragged_parent" ), $( "#qunit-fixture" )[ 0 ] );
-});
+} );
test( "{ axis: false }, default", function() {
expect( 2 );
- var element = $( "#draggable2" ).draggable({ axis: false });
+ var element = $( "#draggable2" ).draggable( { axis: false } );
testHelper.shouldMove( element, "axis: false" );
-});
+} );
test( "{ axis: 'x' }", function() {
expect( 2 );
- var element = $( "#draggable2" ).draggable({ axis: "x" });
+ var element = $( "#draggable2" ).draggable( { axis: "x" } );
testHelper.testDrag( element, element, 50, 50, 50, 0, "axis: x" );
-});
+} );
test( "{ axis: 'y' }", function() {
expect( 2 );
- var element = $( "#draggable2" ).draggable({ axis: "y" });
+ var element = $( "#draggable2" ).draggable( { axis: "y" } );
testHelper.testDrag( element, element, 50, 50, 0, 50, "axis: y" );
-});
+} );
test( "{ axis: ? }, unexpected", function() {
var element,
@@ -134,17 +134,17 @@ test( "{ axis: ? }, unexpected", function() {
expect( 12 );
- $.each(unexpected, function(key, val) {
- element = $( "#draggable2" ).draggable({ axis: val });
+ $.each( unexpected, function( key, val ) {
+ element = $( "#draggable2" ).draggable( { axis: val } );
testHelper.shouldMove( element, "axis: " + key );
element.draggable( "destroy" );
- });
-});
+ } );
+} );
test( "axis, default, switching after initialization", function() {
expect( 6 );
- var element = $( "#draggable1" ).draggable({ axis: false });
+ var element = $( "#draggable1" ).draggable( { axis: false } );
// Any Direction
testHelper.shouldMove( element, "axis: default" );
@@ -157,22 +157,22 @@ test( "axis, default, switching after initialization", function() {
element.draggable( "option", "axis", "y" );
testHelper.testDrag( element, element, 50, 50, 0, 50, "axis: y as option" );
-});
+} );
test( "{ cancel: 'input,textarea,button,select,option' }, default", function() {
expect( 4 );
$( "<div id='draggable-option-cancel-default'><input type='text'></div>" ).appendTo( "#qunit-fixture" );
- var element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
+ var element = $( "#draggable-option-cancel-default" ).draggable( { cancel: "input,textarea,button,select,option" } );
testHelper.shouldMove( element, "cancel: default, element dragged" );
element.draggable( "destroy" );
- element = $( "#draggable-option-cancel-default" ).draggable({ cancel: "input,textarea,button,select,option" });
+ element = $( "#draggable-option-cancel-default" ).draggable( { cancel: "input,textarea,button,select,option" } );
testHelper.shouldNotDrag( element, "cancel: default, input dragged", "#draggable-option-cancel-default input" );
element.draggable( "destroy" );
-});
+} );
test( "{ cancel: 'span' }", function() {
expect( 4 );
@@ -182,9 +182,9 @@ test( "{ cancel: 'span' }", function() {
element.draggable( "destroy" );
- element = $( "#draggable2" ).draggable({ cancel: "span" });
+ element = $( "#draggable2" ).draggable( { cancel: "span" } );
testHelper.shouldNotDrag( element, "cancel: span, span dragged", "#draggable2 span" );
-});
+} );
test( "{ cancel: ? }, unexpected", function() {
expect( 12 );
@@ -200,11 +200,11 @@ test( "{ cancel: ? }, unexpected", function() {
};
$.each( unexpected, function( key, val ) {
- element = $( "#draggable2" ).draggable({ cancel: val });
+ element = $( "#draggable2" ).draggable( { cancel: val } );
testHelper.shouldMove( element, "cancel: " + key );
element.draggable( "destroy" );
- });
-});
+ } );
+} );
/*
test( "{ cancel: Selectors }, matching parent selector", function() {
@@ -246,17 +246,17 @@ test( "cancelement, default, switching after initialization", function() {
element.draggable( "option", "cancel", "input" );
testHelper.shouldNotDrag( element, "cancel: input, input dragged", input );
-});
+} );
test( "connectToSortable, dragging out of a sortable", function() {
expect( 4 );
var sortItem, dragHelper,
- element = $( "#draggableSortable" ).draggable({
+ element = $( "#draggableSortable" ).draggable( {
scroll: false,
connectToSortable: "#sortable"
- }),
- sortable = $( "#sortable" ).sortable({ revert: 100 }),
+ } ),
+ sortable = $( "#sortable" ).sortable( { revert: 100 } ),
dx = 50,
dy = 50,
offsetBefore = element.offset(),
@@ -267,13 +267,14 @@ test( "connectToSortable, dragging out of a sortable", function() {
$( sortable ).one( "sortstart", function( event, ui ) {
sortItem = ui.item;
- });
+ } );
$( element ).one( "drag", function( event, ui ) {
dragHelper = ui.helper;
- });
+ } );
$( element ).one( "dragstop", function( event, ui ) {
+
// http://bugs.jqueryui.com/ticket/8809
// Position issue when connected to sortable
deepEqual( ui.helper.offset(), offsetExpected, "draggable offset is correct" );
@@ -286,61 +287,63 @@ test( "connectToSortable, dragging out of a sortable", function() {
// Http://bugs.jqueryui.com/ticket/9481
// connectToSortable causes sortable revert to fail on second attempt
equal( sortable.sortable( "option", "revert" ), 100, "sortable revert behavior is preserved" );
- });
+ } );
element.simulate( "drag", {
dx: dx,
dy: dy
- });
-});
+ } );
+} );
asyncTest( "connectToSortable, dragging clone into sortable", function() {
expect( 3 );
var offsetPlaceholder,
- element = $( "#draggableSortableClone" ).draggable({
+ element = $( "#draggableSortableClone" ).draggable( {
scroll: false,
connectToSortable: "#sortable",
helper: "clone"
- }),
- sortable = $( "#sortable" ).sortable({ revert: 100 }),
+ } ),
+ sortable = $( "#sortable" ).sortable( { revert: 100 } ),
offsetSortable = sortable.offset();
$( sortable ).one( "sort", function( event, ui ) {
offsetPlaceholder = ui.placeholder.offset();
+
// http://bugs.jqueryui.com/ticket/8809
// Position issue when connected to sortable
deepEqual( ui.helper.offset(), offsetSortable, "sortable offset is correct" );
notDeepEqual( ui.helper.offset(), offsetPlaceholder, "offset not equal to placeholder" );
- });
+ } );
$( sortable ).one( "sortstop", function( event, ui ) {
+
// http://bugs.jqueryui.com/ticket/9675
// Animation issue with revert and connectToSortable
deepEqual( ui.item.offset(), offsetPlaceholder, "offset eventually equals placeholder" );
start();
- });
+ } );
element.simulate( "drag", {
x: offsetSortable.left + 1,
y: offsetSortable.top + 1,
moves: 1
- });
-});
+ } );
+} );
test( "connectToSortable, dragging multiple elements in and out of sortable", function() {
expect( 1 );
- var element = $( "#draggableSortableClone" ).draggable({
+ var element = $( "#draggableSortableClone" ).draggable( {
scroll: false,
connectToSortable: "#sortable",
helper: "clone"
- }),
- element2 = $( "#draggableSortable" ).draggable({
+ } ),
+ element2 = $( "#draggableSortable" ).draggable( {
scroll: false,
connectToSortable: "#sortable"
- }),
- sortable = $( "#sortable" ).sortable({ revert: false }),
+ } ),
+ sortable = $( "#sortable" ).sortable( { revert: false } ),
sortableOffset = sortable.offset();
// Move element into sortable
@@ -348,40 +351,40 @@ test( "connectToSortable, dragging multiple elements in and out of sortable", fu
x: sortableOffset.left + 1,
y: sortableOffset.top + 1,
moves: 10
- });
+ } );
// Move element in sortable out
element2.simulate( "drag", {
dx: 200,
dy: 200,
moves: 10
- });
+ } );
// Http://bugs.jqueryui.com/ticket/9675
// Animation issue with revert and connectToSortable
sortable.one( "sortstop", function( event, ui ) {
ok( !$.contains( document, ui.placeholder[ 0 ] ), "placeholder was removed" );
- });
+ } );
// Move the clone of the first element back out
$( "#sortable .sortable2Item" ).simulate( "drag", {
dx: 200,
dy: 200,
moves: 10
- });
-});
+ } );
+} );
test( "connectToSortable, dragging through one sortable to a second", function() {
expect( 2 );
var overCount = 0,
- element = $( "#draggableSortable" ).draggable({
+ element = $( "#draggableSortable" ).draggable( {
scroll: false,
connectToSortable: ".sortable"
- }),
+ } ),
delta = 200,
- sortable = $( "#sortable" ).sortable({ revert: false }),
- sortable2 = $( "#sortable2" ).sortable({ revert: false }),
+ sortable = $( "#sortable" ).sortable( { revert: false } ),
+ sortable2 = $( "#sortable2" ).sortable( { revert: false } ),
sortable2Offset = sortable2.offset(),
dragParams = {
x: sortable2Offset.left + 25,
@@ -392,30 +395,30 @@ test( "connectToSortable, dragging through one sortable to a second", function()
$( sortable ).one( "sortover", function() {
overCount++;
sortable2.css( "top", "+=" + delta );
- });
+ } );
$( sortable2 ).on( "sortupdate", function() {
ok( true, "second sortable is updated" );
- });
+ } );
$( sortable2 ).one( "sortover", function() {
overCount++;
- });
+ } );
$( sortable2 ).one( "sortstop", function() {
equal( overCount, 2, "went over both sortables" );
- });
+ } );
element.simulate( "drag", dragParams );
-});
+} );
test( "connectToSortable, dragging through a sortable", function() {
expect( 1 );
- var draggable = $( "#draggableSortable" ).draggable({
+ var draggable = $( "#draggableSortable" ).draggable( {
scroll: false,
connectToSortable: "#sortable2"
- }),
+ } ),
sortable = $( "#sortable2" ).sortable(),
sortableOffset = sortable.offset();
@@ -423,20 +426,20 @@ test( "connectToSortable, dragging through a sortable", function() {
// Draggable: Position issue with connectToSortable
draggable.one( "dragstop", function() {
equal( draggable.parent().attr( "id" ), "sortable", "restored draggable to original parent" );
- });
+ } );
draggable.simulate( "drag", {
x: sortableOffset.left + 25,
y: sortableOffset.top + sortable.outerHeight() + 400,
moves: 20
- });
-});
+ } );
+} );
test( "{ containment: Element }", function() {
expect( 1 );
var offsetAfter,
- element = $( "#draggable1" ).draggable({ containment: $( "#draggable1" ).parent()[ 0 ] }),
+ element = $( "#draggable1" ).draggable( { containment: $( "#draggable1" ).parent()[ 0 ] } ),
p = element.parent(),
po = p.offset(),
expected = {
@@ -447,16 +450,16 @@ test( "{ containment: Element }", function() {
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" ) }),
+ element = $( "#draggable1" ).draggable( { containment: $( "#qunit-fixture" ) } ),
p = element.parent(),
po = p.offset(),
expected = {
@@ -467,10 +470,10 @@ test( "{ containment: Selector }", function() {
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( 2 );
@@ -481,13 +484,13 @@ test( "{ containment: [x1, y1, x2, y2] }", function() {
element.draggable( "option", "containment", [ eo.left, eo.top, eo.left + element.width() + 5, eo.top + element.height() + 5 ] );
testHelper.testDrag( element, element, -100, -100, 0, 0, "containment: [x1, y1, x2, y2]" );
-});
+} );
test( "{ containment: 'parent' }, relative", function() {
expect( 1 );
var offsetAfter,
- element = $( "#draggable1" ).draggable({ containment: "parent" }),
+ element = $( "#draggable1" ).draggable( { containment: "parent" } ),
p = element.parent(),
po = p.offset(),
expected = {
@@ -498,16 +501,16 @@ test( "{ containment: 'parent' }, relative", function() {
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" }),
+ element = $( "#draggable2" ).draggable( { containment: "parent" } ),
p = element.parent(),
po = p.offset(),
expected = {
@@ -518,41 +521,41 @@ test( "{ containment: 'parent' }, absolute", function() {
element.simulate( "drag", {
dx: -100,
dy: -100
- });
+ } );
offsetAfter = element.offset();
deepEqual( offsetAfter, expected, "compare offset to parent" );
-});
+} );
test( "containment, account for border", function( assert ) {
expect( 2 );
var el = $( "#draggable1" ).appendTo( "#scrollParent" ),
- parent = el.parent().css({
+ 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 = testHelper.border( parent, "bottom" ),
parentBorderRight = testHelper.border( parent, "right" );
- el.css({
+ el.css( {
height: "5px",
width: "5px"
- }).draggable({ containment: "parent", scroll: false });
+ } ).draggable( { containment: "parent", scroll: false } );
el.simulate( "drag", {
dx: 100,
dy: 100
- });
+ } );
assert.close( el.offset().top, parentBottom - parentBorderBottom - el.height(), 1,
"The draggable should be on top of its parent's bottom border" );
assert.close( el.offset().left, parentRight - parentBorderRight - el.width(), 1,
"The draggable should be to the right of its parent's right border" );
-});
+} );
// http://bugs.jqueryui.com/ticket/7016
// draggable can be pulled out of containment in Chrome and IE8
@@ -560,48 +563,48 @@ test( "containment, element cant be pulled out of container", function() {
expect( 1 );
var offsetBefore,
- parent = $( "<div>").css({ width: 200, height: 200 }).appendTo( "#qunit-fixture" ),
+ parent = $( "<div>" ).css( { width: 200, height: 200 } ).appendTo( "#qunit-fixture" ),
element = $( "#draggable1" ).appendTo( parent );
element
- .css({
+ .css( {
height: "5px",
width: "5px"
- })
- .draggable({ containment: "parent" })
+ } )
+ .draggable( { containment: "parent" } )
.simulate( "drag", {
dx: 500,
dy: 500
- });
+ } );
offsetBefore = element.offset();
element.simulate( "drag", {
dx: 200,
dy: 200
- });
+ } );
deepEqual( element.offset(), offsetBefore, "The draggable should not move past bottom right edge" );
-});
+} );
test( "containment, default, switching after initialization", function() {
expect( 8 );
- var element = $( "#draggable1" ).draggable({ containment: false, scroll: false }),
+ var element = $( "#draggable1" ).draggable( { containment: false, scroll: false } ),
po = element.parent().offset(),
containment = [ po.left - 100, po.top - 100, po.left + 500, po.top + 500 ];
testHelper.testDrag( element, element, -100, -100, -100, -100, "containment: default" );
- element.draggable( "option", "containment", "parent" ).css({ top: 0, left: 0 });
+ element.draggable( "option", "containment", "parent" ).css( { top: 0, left: 0 } );
testHelper.testDrag( element, element, -100, -100, 0, 0, "containment: parent as option" );
- element.draggable( "option", "containment", containment ).css({ top: 0, left: 0 });
+ element.draggable( "option", "containment", containment ).css( { top: 0, left: 0 } );
testHelper.testDrag( element, element, -100, -100, -100, -100, "containment: array as option" );
element.draggable( "option", "containment", false );
testHelper.testDrag( element, element, -100, -100, -100, -100, "containment: false as option" );
-});
+} );
test( "{ cursor: 'auto' }, default", function() {
function getCursor() {
@@ -612,23 +615,23 @@ test( "{ cursor: 'auto' }, default", function() {
var actual, after,
expected = "auto",
- element = $( "#draggable2" ).draggable({
+ 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() {
@@ -639,23 +642,23 @@ test( "{ cursor: 'move' }", function() {
var actual, after,
expected = "move",
- element = $( "#draggable2" ).draggable({
+ 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( "#6889: Cursor doesn't revert to pre-dragging state after revert action when original element is removed", function() {
function getCursor() {
@@ -664,7 +667,7 @@ test( "#6889: Cursor doesn't revert to pre-dragging state after revert action wh
expect( 2 );
- var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
+ var element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable( {
cursor: "move",
revert: true,
revertDuration: 0,
@@ -675,7 +678,7 @@ test( "#6889: Cursor doesn't revert to pre-dragging state after revert action wh
stop: function() {
equal( getCursor(), expected, "after drag: cursor restored" );
}
- }),
+ } ),
expected = getCursor();
if ( testHelper.unreliableContains ) {
@@ -685,9 +688,9 @@ test( "#6889: Cursor doesn't revert to pre-dragging state after revert action wh
element.simulate( "drag", {
dx: -1,
dy: -1
- });
+ } );
}
-});
+} );
test( "cursor, default, switching after initialization", function() {
expect( 3 );
@@ -706,7 +709,7 @@ test( "cursor, default, switching after initialization", function() {
element.draggable( "option", "cursor", "ns-resize" );
testHelper.move( element, 1, 1 );
equal( element.data( "last_dragged_cursor" ), "ns-resize" );
-});
+} );
test( "cursorAt", function() {
expect( 24 );
@@ -724,7 +727,7 @@ test( "cursorAt", function() {
$.each( tests, function( testName, testData ) {
$.each( [ "relative", "absolute" ], function( i, position ) {
- var element = $( "#draggable" + ( i + 1 ) ).draggable({
+ var element = $( "#draggable" + ( i + 1 ) ).draggable( {
cursorAt: testData.cursorAt,
drag: function( event, ui ) {
if ( !testData.cursorAt ) {
@@ -738,16 +741,16 @@ test( "cursorAt", function() {
equal( event.clientY - ui.offset.top, testData.y + testHelper.unreliableOffset, testName + " " + position + " top" );
}
}
- });
+ } );
element.simulate( "drag", {
moves: 1,
dx: deltaX,
dy: deltaY
- });
- });
- });
-});
+ } );
+ } );
+ } );
+} );
test( "cursorAt, switching after initialization", function() {
expect( 24 );
@@ -767,7 +770,7 @@ test( "cursorAt, switching after initialization", function() {
$.each( [ "relative", "absolute" ], function( i, position ) {
var element = $( "#draggable" + ( i + 1 ) );
- element.draggable({
+ element.draggable( {
drag: function( event, ui ) {
if ( !testData.cursorAt ) {
equal( ui.position.left - ui.originalPosition.left, deltaX, testName + " " + position + " left" );
@@ -780,7 +783,7 @@ test( "cursorAt, switching after initialization", function() {
equal( event.clientY - ui.offset.top, testData.y + testHelper.unreliableOffset, testName + " " + position + " top" );
}
}
- });
+ } );
element.draggable( "option", "cursorAt", false );
element.draggable( "option", "cursorAt", testData.cursorAt );
@@ -789,10 +792,10 @@ test( "cursorAt, switching after initialization", function() {
moves: 1,
dx: deltaX,
dy: deltaY
- });
- });
- });
-});
+ } );
+ } );
+ } );
+} );
test( "disabled", function() {
expect( 6 );
@@ -806,23 +809,23 @@ test( "disabled", function() {
element.draggable( "option", "disabled", false );
testHelper.shouldMove( element, "option: disabled false" );
-});
+} );
test( "{ grid: [50, 50] }, relative", function() {
expect( 4 );
- var element = $( "#draggable1" ).draggable({ grid: [ 50, 50 ] });
+ var element = $( "#draggable1" ).draggable( { grid: [ 50, 50 ] } );
testHelper.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] relative" );
testHelper.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] relative" );
-});
+} );
test( "{ grid: [50, 50] }, absolute", function() {
expect( 4 );
- var element = $( "#draggable2" ).draggable({ grid: [ 50, 50 ] });
+ var element = $( "#draggable2" ).draggable( { grid: [ 50, 50 ] } );
testHelper.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] absolute" );
testHelper.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] absolute" );
-});
+} );
test( "grid, switching after initialization", function() {
expect( 8 );
@@ -837,17 +840,17 @@ test( "grid, switching after initialization", function() {
testHelper.testDrag( element, element, 24, 24, 0, 0, "grid: [50, 50] as option" );
testHelper.testDrag( element, element, 26, 25, 50, 50, "grid: [50, 50] as option" );
-});
+} );
test( "{ handle: 'span' }", function() {
expect( 6 );
- var element = $( "#draggable2" ).draggable({ handle: "span" });
+ var element = $( "#draggable2" ).draggable( { handle: "span" } );
- testHelper.shouldMove( element, "handle: span", "#draggable2 span");
+ testHelper.shouldMove( element, "handle: span", "#draggable2 span" );
testHelper.shouldMove( element, "handle: span child", "#draggable2 span em" );
testHelper.shouldNotDrag( element, "handle: span element" );
-});
+} );
test( "handle, default, switching after initialization", function() {
expect( 12 );
@@ -866,7 +869,7 @@ test( "handle, default, switching after initialization", function() {
element.draggable( "option", "handle", false );
testHelper.shouldMove( element, "handle: false as option, element dragged" );
testHelper.shouldMove( element, "handle: false as option, span dragged", "#draggable2 span" );
-});
+} );
test( "helper, default, switching after initialization", function() {
expect( 6 );
@@ -879,36 +882,36 @@ test( "helper, default, switching after initialization", function() {
element.draggable( "option", "helper", "original" );
testHelper.shouldMove( element, "helper: original" );
-});
+} );
// http://bugs.jqueryui.com/ticket/9446
// Draggable: helper function cannot emulate default behavior
test( "helper, function returning original element", function() {
expect( 1 );
- var element = $( "#draggable1" ).css( "position", "static" ).draggable({
+ var element = $( "#draggable1" ).css( "position", "static" ).draggable( {
helper: function() {
return this;
}
- });
+ } );
testHelper.testDragHelperOffset( element, 100, 100, 100, 100, "original element is draggable" );
element.simulate( "drag", {
dx: 100,
dy: 100
- });
-});
+ } );
+} );
function testHelperPosition( scrollPositions, position, helper, scrollElements, scrollElementsTitle ) {
test( "{ helper: '" + helper + "' }, " + position + ", with scroll offset on " + scrollElementsTitle, function() {
expect( scrollPositions.length * 2 );
var i, j,
- element = $( "#draggable1" ).css({ position: position, top: 0, left: 0 }).draggable({
+ element = $( "#draggable1" ).css( { position: position, top: 0, left: 0 } ).draggable( {
helper: helper,
scroll: false
- });
+ } );
if ( scrollElements.length === 1 && scrollElements[ 0 ] === "#scrollParent" ) {
testHelper.setScrollable( "#main", false );
@@ -931,10 +934,10 @@ function testHelperPosition( scrollPositions, position, helper, scrollElements,
testHelper.setScrollable( "#main", true );
testHelper.setScrollable( "#scrollParent", false );
}
- });
+ } );
}
-(function() {
+( function() {
var scrollElementsMap = {
"no elements": [],
"parent": [ "#main" ],
@@ -944,6 +947,7 @@ function testHelperPosition( scrollPositions, position, helper, scrollElements,
},
positions = [ "absolute", "fixed", "relative", "static" ],
helpers = [ "original", "clone" ],
+
// static is not an option here since the fixture is in an absolute container
scrollPositions = [ "relative", "absolute", "fixed" ];
@@ -953,39 +957,39 @@ function testHelperPosition( scrollPositions, position, helper, scrollElements,
var position = this;
$.each( scrollElementsMap, function( scrollElementsTitle, scrollElements ) {
testHelperPosition( scrollPositions, position, helper, scrollElements, scrollElementsTitle );
- });
- });
- });
-})();
+ } );
+ } );
+ } );
+} )();
test( "{ opacity: 0.5 }", function() {
expect( 1 );
var opacity = null,
- element = $( "#draggable2" ).draggable({
+ element = $( "#draggable2" ).draggable( {
opacity: 0.5,
start: function() {
- opacity = $(this).css( "opacity" );
+ 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({
+ element = $( "#draggable2" ).draggable( {
start: function() {
- opacity = $(this).css( "opacity" );
+ opacity = $( this ).css( "opacity" );
}
- });
+ } );
testHelper.move( element, 1, 1 );
equal( opacity, 1 );
@@ -997,15 +1001,15 @@ test( "opacity, default, switching after initialization", function() {
element.draggable( "option", "opacity", false );
testHelper.move( element, 3, 1 );
equal( opacity, 1 );
-});
+} );
asyncTest( "revert and revertDuration", function() {
expect( 7 );
- var element = $( "#draggable2" ).draggable({
+ var element = $( "#draggable2" ).draggable( {
revert: true,
revertDuration: 0
- });
+ } );
testHelper.shouldMovePositionButNotOffset( element, "revert: true, revertDuration: 0 should revert immediately" );
$( "#draggable2" ).draggable( "option", "revert", "invalid" );
@@ -1020,45 +1024,45 @@ asyncTest( "revert and revertDuration", function() {
stop: function() {
start();
}
- });
+ } );
// Animation are async, so test for it asynchronously
testHelper.move( element, 50, 50 );
setTimeout( function() {
ok( $( "#draggable2" ).is( ":animated" ), "revert: true with revertDuration should animate" );
- });
-});
+ } );
+} );
test( "revert: valid", function() {
expect( 2 );
- var element = $( "#draggable2" ).draggable({
+ var element = $( "#draggable2" ).draggable( {
revert: "valid",
revertDuration: 0
- });
+ } );
$( "#droppable" ).droppable();
testHelper.shouldMovePositionButNotOffset( element, "revert: valid reverts when dropped on a droppable" );
-});
+} );
test( "scope", function() {
expect( 4 );
- var element = $( "#draggable2" ).draggable({
+ var element = $( "#draggable2" ).draggable( {
scope: "tasks",
revert: "valid",
revertDuration: 0
- });
+ } );
- $( "#droppable" ).droppable({ scope: "tasks" });
+ $( "#droppable" ).droppable( { scope: "tasks" } );
testHelper.shouldMovePositionButNotOffset( element, "revert: valid reverts when dropped on a droppable in scope" );
- $( "#droppable" ).droppable( "destroy" ).droppable({ scope: "nottasks" });
+ $( "#droppable" ).droppable( "destroy" ).droppable( { scope: "nottasks" } );
testHelper.shouldMove( element, "revert: valid reverts when dropped on a droppable out of scope" );
-});
+} );
test( "scroll, scrollSensitivity, and scrollSpeed", function() {
expect( 2 );
@@ -1067,46 +1071,46 @@ test( "scroll, scrollSensitivity, and scrollSpeed", function() {
var currentScrollTop,
viewportHeight = $( window ).height(),
- element = $( "#draggable1" ).draggable({ scroll: true }).appendTo( "#qunit-fixture" ),
+ element = $( "#draggable1" ).draggable( { scroll: true } ).appendTo( "#qunit-fixture" ),
scrollSensitivity = element.draggable( "option", "scrollSensitivity" ),
scrollSpeed = element.draggable( "option", "scrollSpeed" );
- element.offset({
+ element.offset( {
top: viewportHeight - scrollSensitivity - 1,
left: 1
- });
+ } );
$( element ).one( "drag", function() {
equal( $( window ).scrollTop(), 0, "scroll: true doesn't scroll when the element is dragged outside of scrollSensitivity" );
- });
+ } );
element.simulate( "drag", {
dx: 1,
y: viewportHeight - scrollSensitivity - 1,
moves: 1
- });
+ } );
element.draggable( "option", "scrollSensitivity", scrollSensitivity + 10 );
- element.offset({
+ element.offset( {
top: viewportHeight - scrollSensitivity - 1,
left: 1
- });
+ } );
currentScrollTop = $( window ).scrollTop();
$( element ).one( "drag", function() {
ok( $( window ).scrollTop() - currentScrollTop, scrollSpeed, "scroll: true scrolls when the element is dragged within scrollSensitivity" );
- });
+ } );
element.simulate( "drag", {
dx: 1,
y: viewportHeight - scrollSensitivity - 1,
moves: 1
- });
+ } );
testHelper.restoreScroll( document );
-});
+} );
test( "scroll ignores containers that are overflow: hidden", function() {
expect( 2 );
@@ -1119,7 +1123,7 @@ test( "scroll ignores containers that are overflow: hidden", function() {
element.simulate( "drag", {
dx: 1300,
dy: 1300
- });
+ } );
// IE8 natively scrolls when dragging an element inside a overflow:hidden
// container, so skip this test if native scroll occurs.
@@ -1130,16 +1134,16 @@ test( "scroll ignores containers that are overflow: hidden", function() {
return;
}
- element.css({ top: 0, left: 0 }).draggable( "option", "scroll", true );
+ element.css( { top: 0, left: 0 } ).draggable( "option", "scroll", true );
element.simulate( "drag", {
dx: 1300,
dy: 1300
- });
+ } );
equal( scrollParent.scrollTop(), 0, "container doesn't scroll vertically" );
equal( scrollParent.scrollLeft(), 0, "container doesn't scroll horizontally" );
-});
+} );
test( "#6817: auto scroll goes double distance when dragging", function( assert ) {
expect( 2 );
@@ -1149,22 +1153,23 @@ test( "#6817: auto scroll goes double distance when dragging", function( assert
var offsetBefore,
distance = 10,
viewportHeight = $( window ).height(),
- element = $( "#draggable1" ).draggable({
+ 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 assert.close can be turned back to equal
assert.close( 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({
+ element.offset( {
top: oldY,
left: 1
- });
+ } );
offsetBefore = element.offset();
@@ -1173,32 +1178,32 @@ test( "#6817: auto scroll goes double distance when dragging", function( assert
dx: 1,
y: newY,
moves: 1
- });
+ } );
testHelper.restoreScroll( document );
-});
+} );
test( "snap, snapMode, and snapTolerance", function( assert ) {
expect( 10 );
var newX, newY,
snapTolerance = 15,
- element = $( "#draggable1" ).draggable({
+ element = $( "#draggable1" ).draggable( {
snap: true,
scroll: false,
snapMode: "both",
snapTolerance: snapTolerance
- }),
+ } ),
element2 = $( "#draggable2" ).draggable();
// Http://bugs.jqueryui.com/ticket/9724
// Draggable: Snapping coordinates thrown off by margin on draggable
element.css( "margin", "3px" );
- element.offset({
+ element.offset( {
top: 1,
left: 1
- });
+ } );
newX = element2.offset().left - element.outerWidth() - snapTolerance - 2;
newY = element2.offset().top;
@@ -1208,7 +1213,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
x: newX,
y: newY,
moves: 1
- });
+ } );
// TODO: fix IE8 testswarm IFRAME positioning bug so assert.close can be turned back to equal
assert.close( element.offset().left, newX, 1, "doesn't snap outside the snapTolerance" );
@@ -1221,7 +1226,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
x: newX,
y: newY,
moves: 1
- });
+ } );
notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the snapTolerance" );
@@ -1232,7 +1237,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
x: newX,
y: newY,
moves: 1
- });
+ } );
notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps based on selector" );
@@ -1243,7 +1248,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
x: newX,
y: newY,
moves: 1
- });
+ } );
deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap based on invalid selector" );
@@ -1254,7 +1259,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
x: newX,
y: newY,
moves: 1
- });
+ } );
deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap outside the modified snapTolerance" );
@@ -1266,7 +1271,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
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" );
@@ -1278,7 +1283,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
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" );
@@ -1289,7 +1294,7 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
x: newX,
y: newY,
moves: 1
- });
+ } );
notDeepEqual( element.offset(), { top: newY, left: newX }, "snaps inside the inner snapTolerance area when snapMode is inner" );
@@ -1300,17 +1305,17 @@ test( "snap, snapMode, and snapTolerance", function( assert ) {
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( assert ) {
expect( 2 );
var newX, newY,
snapTolerance = 15,
- element = $( "#draggable1" ).draggable({
+ element = $( "#draggable1" ).draggable( {
snap: true,
scroll: false,
snapMode: "both",
@@ -1318,13 +1323,13 @@ test( "#8459: element can snap to an element that was removed during drag", func
start: function() {
element2.remove();
}
- }),
+ } ),
element2 = $( "#draggable2" ).draggable();
- element.offset({
+ element.offset( {
top: 1,
left: 1
- });
+ } );
newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
newY = element2.offset().top;
@@ -1334,18 +1339,19 @@ test( "#8459: element can snap to an element that was removed during drag", func
x: newX,
y: newY,
moves: 1
- });
+ } );
// Support: Opera 12.10, Safari 5.1, jQuery <1.8
if ( testHelper.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 assert.close can be turned back to equal
assert.close( element.offset().left, newX, 1, "doesn't snap to a removed element" );
assert.close( 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 );
@@ -1353,85 +1359,85 @@ test( "#8165: Snapping large rectangles to small rectangles doesn't snap properl
var snapTolerance = 20,
y = 1,
element = $( "#draggable1" )
- .css({
+ .css( {
width: "50px",
height: "200px"
- }).offset({
+ } ).offset( {
top: y,
left: 1
- }),
+ } ),
element2 = $( "#draggable2" )
- .css({
+ .css( {
width: "50px",
height: "50px"
- }).offset({
+ } ).offset( {
top: y + snapTolerance + 1,
left: 200
- }),
+ } ),
newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
- $( "#draggable1, #draggable2" ).draggable({
+ $( "#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({
+ var element = $( "#draggable1" ).draggable( {
stack: "#draggable1, #draggable2"
- }),
- element2 = $( "#draggable2" ).draggable({
+ } ),
+ element2 = $( "#draggable2" ).draggable( {
stack: "#draggable1, #draggable2"
- });
+ } );
testHelper.move( element, 1, 1 );
equal( element.css( "zIndex" ), "2", "stack increments zIndex correctly" );
testHelper.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({
+ element = $( "#draggable2" ).draggable( {
zIndex: expected,
start: function() {
- actual = $(this).css( "zIndex" );
+ 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({
+ element = $( "#draggable2" ).draggable( {
start: function() {
- zindex = $(this).css( "z-index" );
+ zindex = $( this ).css( "z-index" );
}
- });
+ } );
element.css( "z-index", 1 );
@@ -1446,48 +1452,49 @@ test( "zIndex, default, switching after initialization", function() {
testHelper.move( element, 3, 1 );
equal( zindex, 1 );
-});
+} );
test( "iframeFix", function() {
expect( 5 );
- var element = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable({ iframeFix: true }),
- element2 = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable({ iframeFix: ".iframe" }),
+ var element = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable( { iframeFix: true } ),
+ element2 = $( "<div>" ).appendTo( "#qunit-fixture" ).draggable( { iframeFix: ".iframe" } ),
iframe = $( "<iframe>" ).appendTo( element );
element2
.append( "<iframe class='iframe'></iframe>" )
.append( "<iframe>" );
- iframe.css({
+ iframe.css( {
width: 1,
height: 1
- });
+ } );
element.one( "drag", function() {
var div = $( this ).children().not( "iframe" );
+
// http://bugs.jqueryui.com/ticket/9671
// iframeFix doesn't handle iframes that move
equal( div.length, 1, "blocking div added as sibling" );
equal( div.outerWidth(), iframe.outerWidth(), "blocking div is wide enough" );
equal( div.outerHeight(), iframe.outerHeight(), "blocking div is tall enough" );
deepEqual( div.offset(), iframe.offset(), "blocking div is tall enough" );
- });
+ } );
element.simulate( "drag", {
dx: 1,
dy: 1
- });
+ } );
element2.one( "drag", function() {
var div = $( this ).children().not( "iframe" );
equal( div.length, 1, "blocking div added as sibling only to matching selector" );
- });
+ } );
element2.simulate( "drag", {
dx: 1,
dy: 1
- });
-});
+ } );
+} );
} );
diff --git a/ui/widgets/draggable.js b/ui/widgets/draggable.js
index b2c56509f..fc340626e 100644
--- a/ui/widgets/draggable.js
+++ b/ui/widgets/draggable.js
@@ -14,11 +14,11 @@
//>>demos: http://jqueryui.com/draggable/
//>>css.structure: ../themes/base/draggable.css
-(function( factory ) {
+( function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
- define([
+ define( [
"jquery",
"./mouse",
"../data",
@@ -34,9 +34,9 @@
// Browser globals
factory( jQuery );
}
-}(function( $ ) {
+}( function( $ ) {
-$.widget("ui.draggable", $.ui.mouse, {
+$.widget( "ui.draggable", $.ui.mouse, {
version: "@VERSION",
widgetEventPrefix: "drag",
options: {
@@ -75,10 +75,10 @@ $.widget("ui.draggable", $.ui.mouse, {
if ( this.options.helper === "original" ) {
this._setPositionRelative();
}
- if (this.options.addClasses){
+ if ( this.options.addClasses ) {
this._addClass( "ui-draggable" );
}
- if (this.options.disabled){
+ if ( this.options.disabled ) {
this._addClass( "ui-draggable-disabled" );
}
this._setHandleClassName();
@@ -103,19 +103,19 @@ $.widget("ui.draggable", $.ui.mouse, {
this._mouseDestroy();
},
- _mouseCapture: function(event) {
+ _mouseCapture: function( event ) {
var o = this.options;
this._blurActiveElement( event );
// 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;
}
//Quit if we're not on a valid handle
- this.handle = this._getHandle(event);
- if (!this.handle) {
+ this.handle = this._getHandle( event );
+ if ( !this.handle ) {
return false;
}
@@ -126,7 +126,7 @@ $.widget("ui.draggable", $.ui.mouse, {
},
_blockFrames: function( selector ) {
- this.iframeBlocks = this.document.find( selector ).map(function() {
+ this.iframeBlocks = this.document.find( selector ).map( function() {
var iframe = $( this );
return $( "<div>" )
@@ -135,7 +135,7 @@ $.widget("ui.draggable", $.ui.mouse, {
.outerWidth( iframe.outerWidth() )
.outerHeight( iframe.outerHeight() )
.offset( iframe.offset() )[ 0 ];
- });
+ } );
},
_unblockFrames: function() {
@@ -156,12 +156,12 @@ $.widget("ui.draggable", $.ui.mouse, {
$.ui.safeBlur( $.ui.safeActiveElement( this.document[ 0 ] ) );
},
- _mouseStart: function(event) {
+ _mouseStart: function( event ) {
var o = this.options;
//Create and append the visible helper
- this.helper = this._createHelper(event);
+ this.helper = this._createHelper( event );
this._addClass( this.helper, "ui-draggable-dragging" );
@@ -169,7 +169,7 @@ $.widget("ui.draggable", $.ui.mouse, {
this._cacheHelperProportions();
//If ddmanager is used for droppables, set the global draggable
- if ($.ui.ddmanager) {
+ if ( $.ui.ddmanager ) {
$.ui.ddmanager.current = this;
}
@@ -185,9 +185,9 @@ $.widget("ui.draggable", $.ui.mouse, {
this.cssPosition = this.helper.css( "position" );
this.scrollParent = this.helper.scrollParent( true );
this.offsetParent = this.helper.offsetParent();
- this.hasFixedAncestor = this.helper.parents().filter(function() {
+ this.hasFixedAncestor = this.helper.parents().filter( function() {
return $( this ).css( "position" ) === "fixed";
- }).length > 0;
+ } ).length > 0;
//The element's absolute position on the page minus margins
this.positionAbs = this.element.offset();
@@ -199,13 +199,13 @@ $.widget("ui.draggable", $.ui.mouse, {
this.originalPageY = event.pageY;
//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
this._setContainment();
//Trigger event + callbacks
- if (this._trigger("start", event) === false) {
+ if ( this._trigger( "start", event ) === false ) {
this._clear();
return false;
}
@@ -214,15 +214,15 @@ $.widget("ui.draggable", $.ui.mouse, {
this._cacheHelperProportions();
//Prepare the droppable offsets
- if ($.ui.ddmanager && !o.dropBehaviour) {
- $.ui.ddmanager.prepareOffsets(this, event);
+ if ( $.ui.ddmanager && !o.dropBehaviour ) {
+ $.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 ( $.ui.ddmanager ) {
- $.ui.ddmanager.dragStart(this, event);
+ $.ui.ddmanager.dragStart( this, event );
}
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)
if ( this.hasFixedAncestor ) {
this.offset.parent = this._getParentOffset();
@@ -251,13 +252,13 @@ $.widget("ui.draggable", $.ui.mouse, {
//Compute the helpers position
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
- if (!noPropagation) {
+ if ( !noPropagation ) {
var ui = this._uiHash();
- if (this._trigger("drag", event, ui) === false) {
- this._mouseUp({});
+ if ( this._trigger( "drag", event, ui ) === false ) {
+ this._mouseUp( {} );
return false;
}
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.top = this.position.top + "px";
- if ($.ui.ddmanager) {
- $.ui.ddmanager.drag(this, event);
+ if ( $.ui.ddmanager ) {
+ $.ui.ddmanager.drag( this, event );
}
return false;
},
- _mouseStop: function(event) {
+ _mouseStop: function( event ) {
//If we are using droppables, inform the manager about the drop
var that = this,
dropped = false;
- if ($.ui.ddmanager && !this.options.dropBehaviour) {
- dropped = $.ui.ddmanager.drop(this, event);
+ if ( $.ui.ddmanager && !this.options.dropBehaviour ) {
+ dropped = $.ui.ddmanager.drop( this, event );
}
//if a drop comes from outside (a sortable)
- if (this.dropped) {
+ if ( this.dropped ) {
dropped = this.dropped;
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))) {
- $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
- if (that._trigger("stop", event) !== 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 ) ) ) {
+ $( this.helper ).animate( this.originalPosition, parseInt( this.options.revertDuration, 10 ), function() {
+ if ( that._trigger( "stop", event ) !== false ) {
that._clear();
}
- });
+ } );
} else {
- if (this._trigger("stop", event) !== false) {
+ if ( this._trigger( "stop", event ) !== false ) {
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 ( $.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
if ( this.handleElement.is( event.target ) ) {
+
// The interaction is over; whether or not the click resulted in a drag, focus the element
this.element.trigger( "focus" );
}
- return $.ui.mouse.prototype._mouseUp.call(this, event);
+ return $.ui.mouse.prototype._mouseUp.call( this, event );
},
cancel: function() {
- if (this.helper.is(".ui-draggable-dragging")) {
- this._mouseUp({});
+ if ( this.helper.is( ".ui-draggable-dragging" ) ) {
+ this._mouseUp( {} );
} else {
this._clear();
}
@@ -332,7 +334,7 @@ $.widget("ui.draggable", $.ui.mouse, {
},
- _getHandle: function(event) {
+ _getHandle: function( event ) {
return this.options.handle ?
!!$( event.target ).closest( this.element.find( this.options.handle ) ).length :
true;
@@ -348,7 +350,7 @@ $.widget("ui.draggable", $.ui.mouse, {
this._removeClass( this.handleElement, "ui-draggable-handle" );
},
- _createHelper: function(event) {
+ _createHelper: function( event ) {
var o = this.options,
helperIsFunction = $.isFunction( o.helper ),
@@ -358,8 +360,8 @@ $.widget("ui.draggable", $.ui.mouse, {
this.element.clone().removeAttr( "id" ) :
this.element );
- if (!helper.parents("body").length) {
- helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo));
+ if ( !helper.parents( "body" ).length ) {
+ helper.appendTo( ( o.appendTo === "parent" ? this.element[ 0 ].parentNode : o.appendTo ) );
}
// Http://bugs.jqueryui.com/ticket/9446
@@ -369,8 +371,8 @@ $.widget("ui.draggable", $.ui.mouse, {
this._setPositionRelative();
}
- if (helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) {
- helper.css("position", "absolute");
+ if ( helper[ 0 ] !== this.element[ 0 ] && !( /(fixed|absolute)/ ).test( helper.css( "position" ) ) ) {
+ helper.css( "position", "absolute" );
}
return helper;
@@ -383,23 +385,23 @@ $.widget("ui.draggable", $.ui.mouse, {
}
},
- _adjustOffsetFromHelper: function(obj) {
- if (typeof obj === "string") {
- obj = obj.split(" ");
+ _adjustOffsetFromHelper: function( obj ) {
+ if ( typeof obj === "string" ) {
+ obj = obj.split( " " );
}
- if ($.isArray(obj)) {
- obj = { left: +obj[0], top: +obj[1] || 0 };
+ if ( $.isArray( obj ) ) {
+ 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;
}
- if ("right" in obj) {
+ if ( "right" in obj ) {
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;
}
- if ("bottom" in obj) {
+ if ( "bottom" in obj ) {
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
// 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
- 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.top += this.scrollParent.scrollTop();
}
@@ -428,8 +430,8 @@ $.widget("ui.draggable", $.ui.mouse, {
}
return {
- top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"), 10) || 0),
- left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"), 10) || 0)
+ top: po.top + ( parseInt( this.offsetParent.css( "borderTopWidth" ), 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 ] );
return {
- 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 )
+ 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 )
};
},
_cacheMargins: function() {
this.margins = {
- left: (parseInt(this.element.css("marginLeft"), 10) || 0),
- top: (parseInt(this.element.css("marginTop"), 10) || 0),
- right: (parseInt(this.element.css("marginRight"), 10) || 0),
- bottom: (parseInt(this.element.css("marginBottom"), 10) || 0)
+ left: ( parseInt( this.element.css( "marginLeft" ), 10 ) || 0 ),
+ top: ( parseInt( this.element.css( "marginTop" ), 10 ) || 0 ),
+ right: ( parseInt( this.element.css( "marginRight" ), 10 ) || 0 ),
+ bottom: ( parseInt( this.element.css( "marginBottom" ), 10 ) || 0 )
};
},
@@ -488,7 +490,7 @@ $.widget("ui.draggable", $.ui.mouse, {
return;
}
- if ( o.containment === "document") {
+ if ( o.containment === "document" ) {
this.containment = [
0,
0,
@@ -535,9 +537,9 @@ $.widget("ui.draggable", $.ui.mouse, {
this.relativeContainer = c;
},
- _convertPositionTo: function(d, pos) {
+ _convertPositionTo: function( d, pos ) {
- if (!pos) {
+ if ( !pos ) {
pos = this.position;
}
@@ -549,13 +551,13 @@ $.widget("ui.draggable", $.ui.mouse, {
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.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: (
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.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 ( constrainPosition ) {
if ( this.containment ) {
- if ( this.relativeContainer ){
+ if ( this.relativeContainer ) {
co = this.relativeContainer.offset();
containment = [
this.containment[ 0 ] + co.left,
@@ -597,27 +599,28 @@ $.widget("ui.draggable", $.ui.mouse, {
containment = this.containment;
}
- if (event.pageX - this.offset.click.left < containment[0]) {
- pageX = containment[0] + this.offset.click.left;
+ if ( event.pageX - this.offset.click.left < containment[ 0 ] ) {
+ pageX = containment[ 0 ] + this.offset.click.left;
}
- if (event.pageY - this.offset.click.top < containment[1]) {
- pageY = containment[1] + this.offset.click.top;
+ if ( event.pageY - this.offset.click.top < containment[ 1 ] ) {
+ pageY = containment[ 1 ] + this.offset.click.top;
}
- if (event.pageX - this.offset.click.left > containment[2]) {
- pageX = containment[2] + this.offset.click.left;
+ if ( event.pageX - this.offset.click.left > containment[ 2 ] ) {
+ pageX = containment[ 2 ] + this.offset.click.left;
}
- if (event.pageY - this.offset.click.top > containment[3]) {
- pageY = containment[3] + this.offset.click.top;
+ if ( event.pageY - this.offset.click.top > containment[ 3 ] ) {
+ 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;
+ 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;
+ 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" ) {
@@ -650,7 +653,7 @@ $.widget("ui.draggable", $.ui.mouse, {
_clear: function() {
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 = null;
@@ -685,16 +688,16 @@ $.widget("ui.draggable", $.ui.mouse, {
};
}
-});
+} );
$.ui.plugin.add( "draggable", "connectToSortable", {
start: function( event, ui, draggable ) {
var uiSortable = $.extend( {}, ui, {
item: draggable.element
- });
+ } );
draggable.sortables = [];
- $( draggable.options.connectToSortable ).each(function() {
+ $( draggable.options.connectToSortable ).each( function() {
var sortable = $( this ).sortable( "instance" );
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
// with any changes that might have happened on the page since initialization.
sortable.refreshPositions();
- sortable._trigger("activate", event, uiSortable);
+ sortable._trigger( "activate", event, uiSortable );
}
- });
+ } );
},
stop: function( event, ui, draggable ) {
var uiSortable = $.extend( {}, ui, {
item: draggable.element
- });
+ } );
draggable.cancelHelperRemoval = false;
@@ -734,12 +737,13 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
left: sortable.placeholder.css( "left" )
};
- sortable._mouseStop(event);
+ sortable._mouseStop( event );
// Once drag has ended, the sortable should return to using
// its original helper, not the shared helper from draggable
sortable.options.helper = sortable.options._helper;
} else {
+
// Prevent this Sortable from removing the helper.
// However, don't set the draggable to remove the helper
// either as another connected Sortable may yet handle the removal.
@@ -747,7 +751,7 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
sortable._trigger( "deactivate", event, uiSortable );
}
- });
+ } );
},
drag: function( event, ui, draggable ) {
$.each( draggable.sortables, function() {
@@ -763,6 +767,7 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
innermostIntersecting = true;
$.each( draggable.sortables, function() {
+
// Copy over variables that sortable's _intersectsWith uses
this.positionAbs = draggable.positionAbs;
this.helperProportions = draggable.helperProportions;
@@ -775,10 +780,11 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
}
return innermostIntersecting;
- });
+ } );
}
if ( innermostIntersecting ) {
+
// If it intersects, we use a little isOver variable and set it once,
// so that the move-in stuff gets fired only once.
if ( !sortable.isOver ) {
@@ -823,7 +829,7 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
// adding to one sortable changes the location of the other sortables (#9675)
$.each( draggable.sortables, function() {
this.refreshPositions();
- });
+ } );
// Hack so receive/update callbacks work (mostly)
draggable.currentItem = draggable.element;
@@ -832,12 +838,14 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
if ( sortable.currentItem ) {
sortable._mouseDrag( event );
+
// Copy the sortable's position because the draggable's can potentially reflect
// a relative position, while sortable is always absolute, which the dragged
// element has now become. (#8809)
ui.position = sortable.position;
}
} else {
+
// 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
// the helper by using cancelHelperRemoval.
@@ -878,49 +886,49 @@ $.ui.plugin.add( "draggable", "connectToSortable", {
// from one sortable changes the location of other sortables (#9675)
$.each( draggable.sortables, function() {
this.refreshPositions();
- });
+ } );
}
}
- });
+ } );
}
-});
+} );
-$.ui.plugin.add("draggable", "cursor", {
+$.ui.plugin.add( "draggable", "cursor", {
start: function( event, ui, instance ) {
var t = $( "body" ),
o = instance.options;
- if (t.css("cursor")) {
- o._cursor = t.css("cursor");
+ if ( t.css( "cursor" ) ) {
+ o._cursor = t.css( "cursor" );
}
- t.css("cursor", o.cursor);
+ t.css( "cursor", o.cursor );
},
stop: function( event, ui, instance ) {
var o = instance.options;
- if (o._cursor) {
- $("body").css("cursor", o._cursor);
+ if ( o._cursor ) {
+ $( "body" ).css( "cursor", o._cursor );
}
}
-});
+} );
-$.ui.plugin.add("draggable", "opacity", {
+$.ui.plugin.add( "draggable", "opacity", {
start: function( event, ui, instance ) {
var t = $( ui.helper ),
o = instance.options;
- if (t.css("opacity")) {
- o._opacity = t.css("opacity");
+ if ( t.css( "opacity" ) ) {
+ o._opacity = t.css( "opacity" );
}
- t.css("opacity", o.opacity);
+ t.css( "opacity", o.opacity );
},
stop: function( event, ui, instance ) {
var o = instance.options;
- if (o._opacity) {
- $(ui.helper).css("opacity", o._opacity);
+ if ( o._opacity ) {
+ $( ui.helper ).css( "opacity", o._opacity );
}
}
-});
+} );
-$.ui.plugin.add("draggable", "scroll", {
+$.ui.plugin.add( "draggable", "scroll", {
start: function( event, ui, i ) {
if ( !i.scrollParentNotHidden ) {
i.scrollParentNotHidden = i.helper.scrollParent( false );
@@ -956,49 +964,49 @@ $.ui.plugin.add("draggable", "scroll", {
} else {
- if (!o.axis || o.axis !== "x") {
- if (event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
- scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
- } else if ($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
- scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
+ if ( !o.axis || o.axis !== "x" ) {
+ if ( event.pageY - $( document ).scrollTop() < o.scrollSensitivity ) {
+ scrolled = $( document ).scrollTop( $( document ).scrollTop() - o.scrollSpeed );
+ } else if ( $( window ).height() - ( event.pageY - $( document ).scrollTop() ) < o.scrollSensitivity ) {
+ scrolled = $( document ).scrollTop( $( document ).scrollTop() + o.scrollSpeed );
}
}
- if (!o.axis || o.axis !== "y") {
- if (event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
- scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
- } else if ($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
- scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
+ if ( !o.axis || o.axis !== "y" ) {
+ if ( event.pageX - $( document ).scrollLeft() < o.scrollSensitivity ) {
+ scrolled = $( document ).scrollLeft( $( document ).scrollLeft() - o.scrollSpeed );
+ } else if ( $( window ).width() - ( event.pageX - $( document ).scrollLeft() ) < o.scrollSensitivity ) {
+ scrolled = $( document ).scrollLeft( $( document ).scrollLeft() + o.scrollSpeed );
}
}
}
- if (scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
- $.ui.ddmanager.prepareOffsets(i, event);
+ if ( scrolled !== false && $.ui.ddmanager && !o.dropBehaviour ) {
+ $.ui.ddmanager.prepareOffsets( i, event );
}
}
-});
+} );
-$.ui.plugin.add("draggable", "snap", {
+$.ui.plugin.add( "draggable", "snap", {
start: function( event, ui, i ) {
var o = i.options;
i.snapElements = [];
- $(o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap).each(function() {
- var $t = $(this),
+ $( o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap ).each( function() {
+ var $t = $( this ),
$o = $t.offset();
- if (this !== i.element[0]) {
- i.snapElements.push({
+ if ( this !== i.element[ 0 ] ) {
+ i.snapElements.push( {
item: this,
width: $t.outerWidth(), height: $t.outerHeight(),
top: $o.top, left: $o.left
- });
+ } );
}
- });
+ } );
},
drag: function( event, ui, inst ) {
@@ -1009,108 +1017,108 @@ $.ui.plugin.add("draggable", "snap", {
x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
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;
- r = l + inst.snapElements[i].width;
- t = inst.snapElements[i].top - inst.margins.top;
- b = t + inst.snapElements[i].height;
+ l = inst.snapElements[ i ].left - inst.margins.left;
+ r = l + inst.snapElements[ i ].width;
+ t = inst.snapElements[ i ].top - inst.margins.top;
+ 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 (inst.snapElements[i].snapping) {
- (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
+ 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.snapElements[i].snapping = false;
+ inst.snapElements[ i ].snapping = false;
continue;
}
- if (o.snapMode !== "inner") {
- ts = Math.abs(t - y2) <= d;
- bs = Math.abs(b - y1) <= d;
- ls = Math.abs(l - x2) <= d;
- rs = Math.abs(r - x1) <= d;
- if (ts) {
- ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top;
+ if ( o.snapMode !== "inner" ) {
+ ts = Math.abs( t - y2 ) <= d;
+ bs = Math.abs( b - y1 ) <= d;
+ ls = Math.abs( l - x2 ) <= d;
+ rs = Math.abs( r - x1 ) <= d;
+ if ( ts ) {
+ ui.position.top = inst._convertPositionTo( "relative", { top: t - inst.helperProportions.height, left: 0 } ).top;
}
- if (bs) {
- ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top;
+ if ( bs ) {
+ ui.position.top = inst._convertPositionTo( "relative", { top: b, left: 0 } ).top;
}
- if (ls) {
- ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left;
+ if ( ls ) {
+ ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: l - inst.helperProportions.width } ).left;
}
- if (rs) {
- ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left;
+ if ( rs ) {
+ 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") {
- ts = Math.abs(t - y1) <= d;
- bs = Math.abs(b - y2) <= d;
- ls = Math.abs(l - x1) <= d;
- rs = Math.abs(r - x2) <= d;
- if (ts) {
- ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top;
+ if ( o.snapMode !== "outer" ) {
+ ts = Math.abs( t - y1 ) <= d;
+ bs = Math.abs( b - y2 ) <= d;
+ ls = Math.abs( l - x1 ) <= d;
+ rs = Math.abs( r - x2 ) <= d;
+ if ( ts ) {
+ ui.position.top = inst._convertPositionTo( "relative", { top: t, left: 0 } ).top;
}
- if (bs) {
- ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top;
+ if ( bs ) {
+ ui.position.top = inst._convertPositionTo( "relative", { top: b - inst.helperProportions.height, left: 0 } ).top;
}
- if (ls) {
- ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left;
+ if ( ls ) {
+ ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: l } ).left;
}
- if (rs) {
- ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left;
+ if ( rs ) {
+ ui.position.left = inst._convertPositionTo( "relative", { top: 0, left: r - inst.helperProportions.width } ).left;
}
}
- 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 })));
+ 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.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 ) {
var min,
o = instance.options,
- group = $.makeArray($(o.stack)).sort(function(a, b) {
- return (parseInt($(a).css("zIndex"), 10) || 0) - (parseInt($(b).css("zIndex"), 10) || 0);
- });
+ group = $.makeArray( $( o.stack ) ).sort( function( a, b ) {
+ 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;
- $(group).each(function(i) {
- $(this).css("zIndex", min + i);
- });
- this.css("zIndex", (min + group.length));
+ min = parseInt( $( group[ 0 ] ).css( "zIndex" ), 10 ) || 0;
+ $( group ).each( function( i ) {
+ $( this ).css( "zIndex", min + i );
+ } );
+ this.css( "zIndex", ( min + group.length ) );
}
-});
+} );
-$.ui.plugin.add("draggable", "zIndex", {
+$.ui.plugin.add( "draggable", "zIndex", {
start: function( event, ui, instance ) {
var t = $( ui.helper ),
o = instance.options;
- if (t.css("zIndex")) {
- o._zIndex = t.css("zIndex");
+ if ( t.css( "zIndex" ) ) {
+ o._zIndex = t.css( "zIndex" );
}
- t.css("zIndex", o.zIndex);
+ t.css( "zIndex", o.zIndex );
},
stop: function( event, ui, instance ) {
var o = instance.options;
- if (o._zIndex) {
- $(ui.helper).css("zIndex", o._zIndex);
+ if ( o._zIndex ) {
+ $( ui.helper ).css( "zIndex", o._zIndex );
}
}
-});
+} );
return $.ui.draggable;
-}));
+} ) );