@@ -749,103 +749,115 @@ $.ui.plugin.add("draggable", "connectToSortable", {
749
749
} ) ;
750
750
751
751
} ,
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 ;
757
754
755
+ $ . each ( draggable . sortables , function ( ) {
758
756
var innermostIntersecting = false ,
759
- thisSortable = this ;
757
+ thisSortable = this ,
758
+ sortable = this . instance ;
760
759
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 ;
765
764
766
- if ( this . instance . _intersectsWith ( this . instance . containerCache ) ) {
765
+ if ( sortable . _intersectsWith ( sortable . containerCache ) ) {
767
766
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 ] ) ) {
776
777
innermostIntersecting = false ;
777
778
}
778
779
return innermostIntersecting ;
779
780
} ) ;
780
781
}
781
782
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 ;
810
826
}
811
827
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 ) ;
815
830
}
816
831
817
832
} 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 ) {
818
837
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 ;
825
840
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 ;
828
843
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 ) ) ;
831
845
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 ;
834
848
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 ( ) ;
839
852
}
840
853
841
- inst . _trigger ( "fromSortable" , event ) ;
842
- inst . dropped = false ; //draggable revert needs that
843
- }
854
+ draggable . _trigger ( "fromSortable" , event ) ;
844
855
856
+ // draggable revert needs that
857
+ draggable . dropped = false ;
858
+ }
845
859
}
846
-
847
860
} ) ;
848
-
849
861
}
850
862
} ) ;
851
863
0 commit comments