mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Draggable: Clean spacing and names in connectToSortable drag callback
This commit is contained in:
parent
49c3fb7403
commit
a62612ce42
134
ui/draggable.js
134
ui/draggable.js
@ -749,30 +749,31 @@ $.ui.plugin.add("draggable", "connectToSortable", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
drag: function( event, ui, inst ) {
|
drag: function( event, ui, draggable ) {
|
||||||
|
var dragElement = this;
|
||||||
var that = this;
|
|
||||||
|
|
||||||
$.each(inst.sortables, function() {
|
|
||||||
|
|
||||||
|
$.each( draggable.sortables, function() {
|
||||||
var innermostIntersecting = false,
|
var innermostIntersecting = false,
|
||||||
thisSortable = this;
|
thisSortable = this,
|
||||||
|
sortable = this.instance;
|
||||||
|
|
||||||
//Copy over some variables to allow calling the sortable's native _intersectsWith
|
// Copy over variables that sortable's _intersectsWith uses
|
||||||
this.instance.positionAbs = inst.positionAbs;
|
sortable.positionAbs = draggable.positionAbs;
|
||||||
this.instance.helperProportions = inst.helperProportions;
|
sortable.helperProportions = draggable.helperProportions;
|
||||||
this.instance.offset.click = inst.offset.click;
|
sortable.offset.click = draggable.offset.click;
|
||||||
|
|
||||||
if (this.instance._intersectsWith(this.instance.containerCache)) {
|
if ( sortable._intersectsWith( sortable.containerCache ) ) {
|
||||||
innermostIntersecting = true;
|
innermostIntersecting = true;
|
||||||
$.each(inst.sortables, function() {
|
|
||||||
this.instance.positionAbs = inst.positionAbs;
|
$.each( draggable.sortables, function() {
|
||||||
this.instance.helperProportions = inst.helperProportions;
|
// Copy over variables that sortable's _intersectsWith uses
|
||||||
this.instance.offset.click = inst.offset.click;
|
this.instance.positionAbs = draggable.positionAbs;
|
||||||
|
this.instance.helperProportions = draggable.helperProportions;
|
||||||
|
this.instance.offset.click = draggable.offset.click;
|
||||||
|
|
||||||
if ( this !== thisSortable &&
|
if ( this !== thisSortable &&
|
||||||
this.instance._intersectsWith( this.instance.containerCache ) &&
|
this.instance._intersectsWith( this.instance.containerCache ) &&
|
||||||
$.contains(thisSortable.instance.element[0], this.instance.element[0])
|
$.contains( sortable.element[ 0 ], this.instance.element[ 0 ] ) ) {
|
||||||
) {
|
|
||||||
innermostIntersecting = false;
|
innermostIntersecting = false;
|
||||||
}
|
}
|
||||||
return innermostIntersecting;
|
return innermostIntersecting;
|
||||||
@ -780,72 +781,83 @@ $.ui.plugin.add("draggable", "connectToSortable", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( innermostIntersecting ) {
|
if ( innermostIntersecting ) {
|
||||||
//If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
|
// If it intersects, we use a little isOver variable and set it once,
|
||||||
if (!this.instance.isOver) {
|
// so that the move-in stuff gets fired only once.
|
||||||
|
if ( !sortable.isOver ) {
|
||||||
|
|
||||||
this.instance.isOver = 1;
|
sortable.isOver = 1;
|
||||||
//Now we fake the start of dragging for the sortable instance,
|
|
||||||
//by cloning the list group item, appending it to the sortable and using it as inst.currentItem
|
|
||||||
//We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
|
|
||||||
this.instance.currentItem = $(that).clone().removeAttr("id").appendTo(this.instance.element).data("ui-sortable-item", true);
|
|
||||||
this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
|
|
||||||
this.instance.options.helper = function() { return ui.helper[0]; };
|
|
||||||
|
|
||||||
event.target = this.instance.currentItem[0];
|
sortable.currentItem = $( dragElement )
|
||||||
this.instance._mouseCapture(event, true);
|
.clone()
|
||||||
this.instance._mouseStart(event, true, true);
|
.removeAttr( "id" )
|
||||||
|
.appendTo( sortable.element )
|
||||||
|
.data( "ui-sortable-item", true );
|
||||||
|
|
||||||
//Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
|
// Store helper option to later restore it
|
||||||
this.instance.offset.click.top = inst.offset.click.top;
|
sortable.options._helper = sortable.options.helper;
|
||||||
this.instance.offset.click.left = inst.offset.click.left;
|
|
||||||
this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
|
sortable.options.helper = function() {
|
||||||
this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
|
return ui.helper[ 0 ];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fire the start event of the sortable with our passed browser event,
|
||||||
|
// and our own helper (so it doesn't create a new one)
|
||||||
|
event.target = sortable.currentItem[ 0 ];
|
||||||
|
sortable._mouseCapture( event, true );
|
||||||
|
sortable._mouseStart( event, true, true );
|
||||||
|
|
||||||
|
// Because the browser event is way off the new appended portlet,
|
||||||
|
// modify necessary variables to reflect the changes
|
||||||
|
sortable.offset.click.top = draggable.offset.click.top;
|
||||||
|
sortable.offset.click.left = draggable.offset.click.left;
|
||||||
|
sortable.offset.parent.left -= draggable.offset.parent.left -
|
||||||
|
sortable.offset.parent.left;
|
||||||
|
sortable.offset.parent.top -= draggable.offset.parent.top -
|
||||||
|
sortable.offset.parent.top;
|
||||||
|
|
||||||
|
draggable._trigger( "toSortable", event );
|
||||||
|
|
||||||
|
// draggable revert needs this variable
|
||||||
|
draggable.dropped = sortable.element;
|
||||||
|
|
||||||
inst._trigger("toSortable", event);
|
|
||||||
inst.dropped = this.instance.element; //draggable revert needs that
|
|
||||||
// hack so receive/update callbacks work (mostly)
|
// hack so receive/update callbacks work (mostly)
|
||||||
inst.currentItem = inst.element;
|
draggable.currentItem = draggable.element;
|
||||||
this.instance.fromOutside = inst;
|
sortable.fromOutside = draggable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
|
if ( sortable.currentItem ) {
|
||||||
if (this.instance.currentItem) {
|
sortable._mouseDrag( event );
|
||||||
this.instance._mouseDrag(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// If it doesn't intersect with the sortable, and it intersected before,
|
// If it doesn't intersect with the sortable, and it intersected before,
|
||||||
//we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
|
// we fake the drag stop of the sortable, but make sure it doesn't remove
|
||||||
if (this.instance.isOver) {
|
// the helper by using cancelHelperRemoval.
|
||||||
|
if ( sortable.isOver ) {
|
||||||
|
|
||||||
this.instance.isOver = 0;
|
sortable.isOver = 0;
|
||||||
this.instance.cancelHelperRemoval = true;
|
sortable.cancelHelperRemoval = true;
|
||||||
|
|
||||||
// Prevent reverting on this forced stop
|
// Prevent reverting on this forced stop
|
||||||
this.instance.options.revert = false;
|
sortable.options.revert = false;
|
||||||
|
|
||||||
// The out event needs to be triggered independently
|
sortable._trigger( "out", event, sortable._uiHash( sortable ) );
|
||||||
this.instance._trigger("out", event, this.instance._uiHash(this.instance));
|
|
||||||
|
|
||||||
this.instance._mouseStop(event, true);
|
sortable._mouseStop( event, true );
|
||||||
this.instance.options.helper = this.instance.options._helper;
|
sortable.options.helper = sortable.options._helper;
|
||||||
|
|
||||||
//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
|
sortable.currentItem.remove();
|
||||||
this.instance.currentItem.remove();
|
if ( sortable.placeholder ) {
|
||||||
if (this.instance.placeholder) {
|
sortable.placeholder.remove();
|
||||||
this.instance.placeholder.remove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inst._trigger("fromSortable", event);
|
draggable._trigger( "fromSortable", event );
|
||||||
inst.dropped = false; //draggable revert needs that
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// draggable revert needs that
|
||||||
|
draggable.dropped = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user