@@ -749,103 +749,115 @@ $.ui.plugin.add("draggable", "connectToSortable", {
749749 } ) ;
750750
751751 } ,
752- drag : function ( event , ui , inst ) {
753-
754- var that = this ;
755-
756- $ . each ( inst . sortables , function ( ) {
752+ drag : function ( event , ui , draggable ) {
753+ var dragElement = this ;
757754
755+ $ . each ( draggable . sortables , function ( ) {
758756 var innermostIntersecting = false ,
759- thisSortable = this ;
757+ thisSortable = this ,
758+ sortable = this . instance ;
760759
761- //Copy over some variables to allow calling the sortable's native _intersectsWith
762- this . instance . positionAbs = inst . positionAbs ;
763- this . instance . helperProportions = inst . helperProportions ;
764- this . instance . offset . click = inst . offset . click ;
760+ // Copy over variables that sortable's _intersectsWith uses
761+ sortable . positionAbs = draggable . positionAbs ;
762+ sortable . helperProportions = draggable . helperProportions ;
763+ sortable . offset . click = draggable . offset . click ;
765764
766- if ( this . instance . _intersectsWith ( this . instance . containerCache ) ) {
765+ if ( sortable . _intersectsWith ( sortable . containerCache ) ) {
767766 innermostIntersecting = true ;
768- $ . each ( inst . sortables , function ( ) {
769- this . instance . positionAbs = inst . positionAbs ;
770- this . instance . helperProportions = inst . helperProportions ;
771- this . instance . offset . click = inst . offset . click ;
772- if ( this !== thisSortable &&
773- this . instance . _intersectsWith ( this . instance . containerCache ) &&
774- $ . contains ( thisSortable . instance . element [ 0 ] , this . instance . element [ 0 ] )
775- ) {
767+
768+ $ . each ( draggable . sortables , function ( ) {
769+ // Copy over variables that sortable's _intersectsWith uses
770+ this . instance . positionAbs = draggable . positionAbs ;
771+ this . instance . helperProportions = draggable . helperProportions ;
772+ this . instance . offset . click = draggable . offset . click ;
773+
774+ if ( this !== thisSortable &&
775+ this . instance . _intersectsWith ( this . instance . containerCache ) &&
776+ $ . contains ( sortable . element [ 0 ] , this . instance . element [ 0 ] ) ) {
776777 innermostIntersecting = false ;
777778 }
778779 return innermostIntersecting ;
779780 } ) ;
780781 }
781782
782- if ( innermostIntersecting ) {
783- //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
784- if ( ! this . instance . isOver ) {
785-
786- this . instance . isOver = 1 ;
787- //Now we fake the start of dragging for the sortable instance,
788- //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
789- //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)
790- this . instance . currentItem = $ ( that ) . clone ( ) . removeAttr ( "id" ) . appendTo ( this . instance . element ) . data ( "ui-sortable-item" , true ) ;
791- this . instance . options . _helper = this . instance . options . helper ; //Store helper option to later restore it
792- this . instance . options . helper = function ( ) { return ui . helper [ 0 ] ; } ;
793-
794- event . target = this . instance . currentItem [ 0 ] ;
795- this . instance . _mouseCapture ( event , true ) ;
796- this . instance . _mouseStart ( event , true , true ) ;
797-
798- //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
799- this . instance . offset . click . top = inst . offset . click . top ;
800- this . instance . offset . click . left = inst . offset . click . left ;
801- this . instance . offset . parent . left -= inst . offset . parent . left - this . instance . offset . parent . left ;
802- this . instance . offset . parent . top -= inst . offset . parent . top - this . instance . offset . parent . top ;
803-
804- inst . _trigger ( "toSortable" , event ) ;
805- inst . dropped = this . instance . element ; //draggable revert needs that
806- //hack so receive/update callbacks work (mostly)
807- inst . currentItem = inst . element ;
808- this . instance . fromOutside = inst ;
809-
783+ if ( innermostIntersecting ) {
784+ // If it intersects, we use a little isOver variable and set it once,
785+ // so that the move-in stuff gets fired only once.
786+ if ( ! sortable . isOver ) {
787+
788+ sortable . isOver = 1 ;
789+
790+ sortable . currentItem = $ ( dragElement )
791+ . clone ( )
792+ . removeAttr ( "id" )
793+ . appendTo ( sortable . element )
794+ . data ( "ui-sortable-item" , true ) ;
795+
796+ // Store helper option to later restore it
797+ sortable . options . _helper = sortable . options . helper ;
798+
799+ sortable . options . helper = function ( ) {
800+ return ui . helper [ 0 ] ;
801+ } ;
802+
803+ // Fire the start event of the sortable with our passed browser event,
804+ // and our own helper (so it doesn't create a new one)
805+ event . target = sortable . currentItem [ 0 ] ;
806+ sortable . _mouseCapture ( event , true ) ;
807+ sortable . _mouseStart ( event , true , true ) ;
808+
809+ // Because the browser event is way off the new appended portlet,
810+ // modify necessary variables to reflect the changes
811+ sortable . offset . click . top = draggable . offset . click . top ;
812+ sortable . offset . click . left = draggable . offset . click . left ;
813+ sortable . offset . parent . left -= draggable . offset . parent . left -
814+ sortable . offset . parent . left ;
815+ sortable . offset . parent . top -= draggable . offset . parent . top -
816+ sortable . offset . parent . top ;
817+
818+ draggable . _trigger ( "toSortable" , event ) ;
819+
820+ // draggable revert needs this variable
821+ draggable . dropped = sortable . element ;
822+
823+ // hack so receive/update callbacks work (mostly)
824+ draggable . currentItem = draggable . element ;
825+ sortable . fromOutside = draggable ;
810826 }
811827
812- //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
813- if ( this . instance . currentItem ) {
814- this . instance . _mouseDrag ( event ) ;
828+ if ( sortable . currentItem ) {
829+ sortable . _mouseDrag ( event ) ;
815830 }
816831
817832 } else {
833+ // If it doesn't intersect with the sortable, and it intersected before,
834+ // we fake the drag stop of the sortable, but make sure it doesn't remove
835+ // the helper by using cancelHelperRemoval.
836+ if ( sortable . isOver ) {
818837
819- //If it doesn't intersect with the sortable, and it intersected before,
820- //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
821- if ( this . instance . isOver ) {
822-
823- this . instance . isOver = 0 ;
824- this . instance . cancelHelperRemoval = true ;
838+ sortable . isOver = 0 ;
839+ sortable . cancelHelperRemoval = true ;
825840
826- //Prevent reverting on this forced stop
827- this . instance . options . revert = false ;
841+ // Prevent reverting on this forced stop
842+ sortable . options . revert = false ;
828843
829- // The out event needs to be triggered independently
830- this . instance . _trigger ( "out" , event , this . instance . _uiHash ( this . instance ) ) ;
844+ sortable . _trigger ( "out" , event , sortable . _uiHash ( sortable ) ) ;
831845
832- this . instance . _mouseStop ( event , true ) ;
833- this . instance . options . helper = this . instance . options . _helper ;
846+ sortable . _mouseStop ( event , true ) ;
847+ sortable . options . helper = sortable . options . _helper ;
834848
835- //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
836- this . instance . currentItem . remove ( ) ;
837- if ( this . instance . placeholder ) {
838- this . instance . placeholder . remove ( ) ;
849+ sortable . currentItem . remove ( ) ;
850+ if ( sortable . placeholder ) {
851+ sortable . placeholder . remove ( ) ;
839852 }
840853
841- inst . _trigger ( "fromSortable" , event ) ;
842- inst . dropped = false ; //draggable revert needs that
843- }
854+ draggable . _trigger ( "fromSortable" , event ) ;
844855
856+ // draggable revert needs that
857+ draggable . dropped = false ;
858+ }
845859 }
846-
847860 } ) ;
848-
849861 }
850862} ) ;
851863
0 commit comments