});
*/
+test( "connectToSortable, dragging out of a sortable", function() {
+ expect( 3 );
+
+ var sortItem, dragHelper,
+ element = $( "#draggableSortable" ).draggable({
+ scroll: false,
+ connectToSortable: "#sortable"
+ }),
+ sortable = $( "#sortable" ).sortable(),
+ dx = 50,
+ dy = 50,
+ offsetBefore = element.offset(),
+ offsetExpected = {
+ left: offsetBefore.left + dx,
+ top: offsetBefore.top + dy
+ };
+
+ $( 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" );
+
+ // http://bugs.jqueryui.com/ticket/7734
+ // HTML IDs are removed when dragging to a Sortable
+ equal( sortItem[ 0 ], dragHelper[ 0 ], "both have the same helper" );
+ equal( sortItem.attr( "id" ), dragHelper.attr( "id" ), "both have the same id" );
+ });
+
+ element.simulate( "drag", {
+ dx: dx,
+ dy: dy
+ });
+});
+
+test( "connectToSortable, dragging clone into sortable", function() {
+ expect( 1 );
+
+ var element = $( "#draggableSortableClone" ).draggable({
+ scroll: false,
+ connectToSortable: "#sortable",
+ helper: "clone"
+ }),
+ sortable = $( "#sortable" ).sortable(),
+ offsetSortable = sortable.offset();
+
+ $( sortable ).one( "sortbeforestop", function( event, ui ) {
+ // http://bugs.jqueryui.com/ticket/8809
+ // Position issue when connected to sortable
+ deepEqual( ui.helper.offset(), offsetSortable, "sortable offset is correct" );
+ });
+
+ element.simulate( "drag", {
+ x: offsetSortable.left + 1,
+ y: offsetSortable.top + 1,
+ moves: 1
+ });
+});
+
test( "{ containment: Element }", function() {
expect( 1 );
this.offsetParentCssPosition = this.offsetParent.css( "position" );
//The element's absolute position on the page minus margins
- this.offset = this.positionAbs = this.element.offset();
- this.offset = {
- top: this.offset.top - this.margins.top,
- left: this.offset.left - this.margins.left
- };
-
- //Reset scroll cache
- this.offset.scroll = false;
-
- $.extend(this.offset, {
- click: { //Where the click happened, relative to the element
- left: event.pageX - this.offset.left,
- top: event.pageY - this.offset.top
- },
- parent: this._getParentOffset(),
- relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
- });
+ this.positionAbs = this.element.offset();
+ this._refreshOffsets( event );
//Generate the original position
this.originalPosition = this.position = this._generatePosition( event, false );
return true;
},
+ _refreshOffsets: function( event ) {
+ this.offset = {
+ top: this.positionAbs.top - this.margins.top,
+ left: this.positionAbs.left - this.margins.left,
+ scroll: false,
+ parent: this._getParentOffset(),
+ relative: this._getRelativeOffset()
+ };
+
+ this.offset.click = {
+ left: event.pageX - this.offset.left,
+ top: event.pageY - this.offset.top
+ };
+ },
+
_mouseDrag: function(event, noPropagation) {
// reset any necessary cached properties (see #5009)
if ( this.offsetParentCssPosition === "fixed" ) {
this.instance.options.helper = this.instance.options._helper;
- //If the helper has been the original item, restore properties in the sortable
- if (inst.options.helper === "original") {
- this.instance.currentItem.css({ top: "auto", left: "auto" });
- }
-
+ // restore properties in the sortable, since the draggable may have
+ // modified them in unexpected ways (#8809)
+ this.instance.currentItem.css({
+ position: this.instance.placeholder.css( "position" ),
+ top: "",
+ left: ""
+ });
} else {
this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
this.instance._trigger("deactivate", event, uiSortable);
},
drag: function( event, ui, draggable ) {
- var dragElement = this;
-
$.each( draggable.sortables, function() {
var innermostIntersecting = false,
thisSortable = this,
sortable.isOver = 1;
- sortable.currentItem = $( dragElement )
- .clone()
- .removeAttr( "id" )
+ sortable.currentItem = ui.helper
.appendTo( sortable.element )
.data( "ui-sortable-item", true );
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 {
sortable._mouseStop( event, true );
sortable.options.helper = sortable.options._helper;
- sortable.currentItem.remove();
if ( sortable.placeholder ) {
sortable.placeholder.remove();
}
+ // Recalculate the draggable's offset considering the sortable
+ // may have modified them in unexpected ways (#8809)
+ draggable._refreshOffsets( event );
+ ui.position = draggable._generatePosition( event, true );
+
draggable._trigger( "fromSortable", event );
// draggable revert needs that