Skip to content

Commit aada9d5

Browse files
committed
Draggable: Whitespace and naming cleanup of connectToSortable
1 parent a611dd8 commit aada9d5

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

ui/draggable.js

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -703,74 +703,72 @@ $.widget("ui.draggable", $.ui.mouse, {
703703

704704
});
705705

706-
$.ui.plugin.add("draggable", "connectToSortable", {
707-
start: function( event, ui, inst ) {
706+
$.ui.plugin.add( "draggable", "connectToSortable", {
707+
start: function( event, ui, draggable ) {
708+
var uiSortable = $.extend( {}, ui, {
709+
item: draggable.element
710+
});
708711

709-
var o = inst.options,
710-
uiSortable = $.extend({}, ui, { item: inst.element });
711-
inst.sortables = [];
712-
$(o.connectToSortable).each(function() {
712+
draggable.sortables = [];
713+
$( draggable.options.connectToSortable ).each(function() {
713714
var sortable = $( this ).sortable( "instance" );
714-
if (sortable && !sortable.options.disabled) {
715-
inst.sortables.push({
716-
instance: sortable
717-
});
718-
sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
715+
716+
if ( sortable && !sortable.options.disabled ) {
717+
draggable.sortables.push( sortable );
718+
719+
// refreshPositions is called at drag start to refresh the containerCache
720+
// which is used in drag. This ensures it's initialized and synchronized
721+
// with any changes that might have happened on the page since initialization.
722+
sortable.refreshPositions();
719723
sortable._trigger("activate", event, uiSortable);
720724
}
721725
});
722-
723726
},
724-
stop: function( event, ui, inst ) {
725-
726-
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
727+
stop: function( event, ui, draggable ) {
727728
var uiSortable = $.extend( {}, ui, {
728-
item: inst.element
729+
item: draggable.element
729730
});
730731

731-
inst.cancelHelperRemoval = false;
732+
draggable.cancelHelperRemoval = false;
732733

733-
$.each(inst.sortables, function() {
734-
if (this.instance.isOver) {
735-
this.instance.isOver = 0;
734+
$.each( draggable.sortables, function() {
735+
var sortable = this;
736+
737+
if ( sortable.isOver ) {
738+
sortable.isOver = 0;
736739

737740
// Allow this sortable to handle removing the helper
738-
inst.cancelHelperRemoval = true;
739-
this.instance.cancelHelperRemoval = false;
741+
draggable.cancelHelperRemoval = true;
742+
sortable.cancelHelperRemoval = false;
740743

741744
// Use _storedCSS To restore properties in the sortable,
742745
// as this also handles revert (#9675) since the draggable
743746
// may have modified them in unexpected ways (#8809)
744-
this.instance._storedCSS = {
745-
position: this.instance.placeholder.css( "position" ),
746-
top: this.instance.placeholder.css( "top" ),
747-
left: this.instance.placeholder.css( "left" )
747+
sortable._storedCSS = {
748+
position: sortable.placeholder.css( "position" ),
749+
top: sortable.placeholder.css( "top" ),
750+
left: sortable.placeholder.css( "left" )
748751
};
749752

750-
//Trigger the stop of the sortable
751-
this.instance._mouseStop(event);
753+
sortable._mouseStop(event);
752754

753755
// Once drag has ended, the sortable should return to using
754756
// its original helper, not the shared helper from draggable
755-
this.instance.options.helper = this.instance.options._helper;
756-
757+
sortable.options.helper = sortable.options._helper;
757758
} else {
758759
// Prevent this Sortable from removing the helper.
759760
// However, don't set the draggable to remove the helper
760761
// either as another connected Sortable may yet handle the removal.
761-
this.instance.cancelHelperRemoval = true;
762+
sortable.cancelHelperRemoval = true;
762763

763-
this.instance._trigger("deactivate", event, uiSortable);
764+
sortable._trigger( "deactivate", event, uiSortable );
764765
}
765-
766766
});
767-
768767
},
769768
drag: function( event, ui, draggable ) {
770769
$.each( draggable.sortables, function() {
771770
var innermostIntersecting = false,
772-
thisSortable = this,
773-
sortable = this.instance;
771+
sortable = this;
774772

775773
// Copy over variables that sortable's _intersectsWith uses
776774
sortable.positionAbs = draggable.positionAbs;
@@ -782,15 +780,16 @@ $.ui.plugin.add("draggable", "connectToSortable", {
782780

783781
$.each( draggable.sortables, function() {
784782
// Copy over variables that sortable's _intersectsWith uses
785-
this.instance.positionAbs = draggable.positionAbs;
786-
this.instance.helperProportions = draggable.helperProportions;
787-
this.instance.offset.click = draggable.offset.click;
783+
this.positionAbs = draggable.positionAbs;
784+
this.helperProportions = draggable.helperProportions;
785+
this.offset.click = draggable.offset.click;
788786

789-
if ( this !== thisSortable &&
790-
this.instance._intersectsWith( this.instance.containerCache ) &&
791-
$.contains( sortable.element[ 0 ], this.instance.element[ 0 ] ) ) {
787+
if ( this !== sortable &&
788+
this._intersectsWith( this.containerCache ) &&
789+
$.contains( sortable.element[ 0 ], this.element[ 0 ] ) ) {
792790
innermostIntersecting = false;
793791
}
792+
794793
return innermostIntersecting;
795794
});
796795
}
@@ -799,7 +798,6 @@ $.ui.plugin.add("draggable", "connectToSortable", {
799798
// If it intersects, we use a little isOver variable and set it once,
800799
// so that the move-in stuff gets fired only once.
801800
if ( !sortable.isOver ) {
802-
803801
sortable.isOver = 1;
804802

805803
sortable.currentItem = ui.helper
@@ -852,7 +850,6 @@ $.ui.plugin.add("draggable", "connectToSortable", {
852850
// element has now become. (#8809)
853851
ui.position = sortable.position;
854852
}
855-
856853
} else {
857854
// If it doesn't intersect with the sortable, and it intersected before,
858855
// we fake the drag stop of the sortable, but make sure it doesn't remove

0 commit comments

Comments
 (0)