@@ -66,6 +66,10 @@ $.widget("ui.draggable", $.ui.mouse, {
66
66
} ,
67
67
68
68
_destroy : function ( ) {
69
+ if ( ( this . helper || this . element ) . is ( ".ui-draggable-dragging" ) ) {
70
+ this . destroyOnClear = true ;
71
+ return ;
72
+ }
69
73
this . element . removeClass ( "ui-draggable ui-draggable-dragging ui-draggable-disabled" ) ;
70
74
this . _mouseDestroy ( ) ;
71
75
} ,
@@ -233,11 +237,6 @@ $.widget("ui.draggable", $.ui.mouse, {
233
237
this . dropped = false ;
234
238
}
235
239
236
- //if the original element is no longer in the DOM don't bother to continue (see #8269)
237
- if ( this . options . helper === "original" && ! $ . contains ( this . element [ 0 ] . ownerDocument , this . element [ 0 ] ) ) {
238
- return false ;
239
- }
240
-
241
240
if ( ( this . options . revert === "invalid" && ! dropped ) || ( this . options . revert === "valid" && dropped ) || this . options . revert === true || ( $ . isFunction ( this . options . revert ) && this . options . revert . call ( this . element , dropped ) ) ) {
242
241
$ ( this . helper ) . animate ( this . originalPosition , parseInt ( this . options . revertDuration , 10 ) , function ( ) {
243
242
if ( that . _trigger ( "stop" , event ) !== false ) {
@@ -554,13 +553,16 @@ $.widget("ui.draggable", $.ui.mouse, {
554
553
}
555
554
this . helper = null ;
556
555
this . cancelHelperRemoval = false ;
556
+ if ( this . destroyOnClear ) {
557
+ this . destroy ( ) ;
558
+ }
557
559
} ,
558
560
559
561
// From now on bulk stuff - mainly helpers
560
562
561
563
_trigger : function ( type , event , ui ) {
562
564
ui = ui || this . _uiHash ( ) ;
563
- $ . ui . plugin . call ( this , type , [ event , ui ] ) ;
565
+ $ . ui . plugin . call ( this , type , [ event , ui , this ] , true ) ;
564
566
//The absolute position has to be recalculated after plugins
565
567
if ( type === "drag" ) {
566
568
this . positionAbs = this . _convertPositionTo ( "absolute" ) ;
@@ -582,9 +584,9 @@ $.widget("ui.draggable", $.ui.mouse, {
582
584
} ) ;
583
585
584
586
$ . ui . plugin . add ( "draggable" , "connectToSortable" , {
585
- start : function ( event , ui ) {
587
+ start : function ( event , ui , inst ) {
586
588
587
- var inst = $ ( this ) . draggable ( "instance" ) , o = inst . options ,
589
+ var o = inst . options ,
588
590
uiSortable = $ . extend ( { } , ui , { item : inst . element } ) ;
589
591
inst . sortables = [ ] ;
590
592
$ ( o . connectToSortable ) . each ( function ( ) {
@@ -600,11 +602,12 @@ $.ui.plugin.add("draggable", "connectToSortable", {
600
602
} ) ;
601
603
602
604
} ,
603
- stop : function ( event , ui ) {
605
+ stop : function ( event , ui , inst ) {
604
606
605
607
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
606
- var inst = $ ( this ) . draggable ( "instance" ) ,
607
- uiSortable = $ . extend ( { } , ui , { item : inst . element } ) ;
608
+ var uiSortable = $ . extend ( { } , ui , {
609
+ item : inst . element
610
+ } ) ;
608
611
609
612
$ . each ( inst . sortables , function ( ) {
610
613
if ( this . instance . isOver ) {
@@ -637,9 +640,9 @@ $.ui.plugin.add("draggable", "connectToSortable", {
637
640
} ) ;
638
641
639
642
} ,
640
- drag : function ( event , ui ) {
643
+ drag : function ( event , ui , inst ) {
641
644
642
- var inst = $ ( this ) . draggable ( "instance" ) , that = this ;
645
+ var that = this ;
643
646
644
647
$ . each ( inst . sortables , function ( ) {
645
648
@@ -739,47 +742,50 @@ $.ui.plugin.add("draggable", "connectToSortable", {
739
742
} ) ;
740
743
741
744
$ . ui . plugin . add ( "draggable" , "cursor" , {
742
- start : function ( ) {
743
- var t = $ ( "body" ) , o = $ ( this ) . draggable ( "instance" ) . options ;
745
+ start : function ( event , ui , instance ) {
746
+ var t = $ ( "body" ) ,
747
+ o = instance . options ;
748
+
744
749
if ( t . css ( "cursor" ) ) {
745
750
o . _cursor = t . css ( "cursor" ) ;
746
751
}
747
752
t . css ( "cursor" , o . cursor ) ;
748
753
} ,
749
- stop : function ( ) {
750
- var o = $ ( this ) . draggable ( " instance" ) . options ;
754
+ stop : function ( event , ui , instance ) {
755
+ var o = instance . options ;
751
756
if ( o . _cursor ) {
752
757
$ ( "body" ) . css ( "cursor" , o . _cursor ) ;
753
758
}
754
759
}
755
760
} ) ;
756
761
757
762
$ . ui . plugin . add ( "draggable" , "opacity" , {
758
- start : function ( event , ui ) {
759
- var t = $ ( ui . helper ) , o = $ ( this ) . draggable ( "instance" ) . options ;
763
+ start : function ( event , ui , instance ) {
764
+ var t = $ ( ui . helper ) ,
765
+ o = instance . options ;
760
766
if ( t . css ( "opacity" ) ) {
761
767
o . _opacity = t . css ( "opacity" ) ;
762
768
}
763
769
t . css ( "opacity" , o . opacity ) ;
764
770
} ,
765
- stop : function ( event , ui ) {
766
- var o = $ ( this ) . draggable ( " instance" ) . options ;
771
+ stop : function ( event , ui , instance ) {
772
+ var o = instance . options ;
767
773
if ( o . _opacity ) {
768
774
$ ( ui . helper ) . css ( "opacity" , o . _opacity ) ;
769
775
}
770
776
}
771
777
} ) ;
772
778
773
779
$ . ui . plugin . add ( "draggable" , "scroll" , {
774
- start : function ( ) {
775
- var i = $ ( this ) . draggable ( "instance" ) ;
780
+ start : function ( event , ui , i ) {
776
781
if ( i . scrollParent [ 0 ] !== document && i . scrollParent [ 0 ] . tagName !== "HTML" ) {
777
782
i . overflowOffset = i . scrollParent . offset ( ) ;
778
783
}
779
784
} ,
780
- drag : function ( event ) {
785
+ drag : function ( event , ui , i ) {
781
786
782
- var i = $ ( this ) . draggable ( "instance" ) , o = i . options , scrolled = false ;
787
+ var o = i . options ,
788
+ scrolled = false ;
783
789
784
790
if ( i . scrollParent [ 0 ] !== document && i . scrollParent [ 0 ] . tagName !== "HTML" ) {
785
791
@@ -827,10 +833,9 @@ $.ui.plugin.add("draggable", "scroll", {
827
833
} ) ;
828
834
829
835
$ . ui . plugin . add ( "draggable" , "snap" , {
830
- start : function ( ) {
836
+ start : function ( event , ui , i ) {
831
837
832
- var i = $ ( this ) . draggable ( "instance" ) ,
833
- o = i . options ;
838
+ var o = i . options ;
834
839
835
840
i . snapElements = [ ] ;
836
841
@@ -847,10 +852,9 @@ $.ui.plugin.add("draggable", "snap", {
847
852
} ) ;
848
853
849
854
} ,
850
- drag : function ( event , ui ) {
855
+ drag : function ( event , ui , inst ) {
851
856
852
857
var ts , bs , ls , rs , l , r , t , b , i , first ,
853
- inst = $ ( this ) . draggable ( "instance" ) ,
854
858
o = inst . options ,
855
859
d = o . snapTolerance ,
856
860
x1 = ui . offset . left , x2 = x1 + inst . helperProportions . width ,
@@ -922,9 +926,9 @@ $.ui.plugin.add("draggable", "snap", {
922
926
} ) ;
923
927
924
928
$ . ui . plugin . add ( "draggable" , "stack" , {
925
- start : function ( ) {
929
+ start : function ( event , ui , instance ) {
926
930
var min ,
927
- o = $ ( this ) . draggable ( " instance" ) . options ,
931
+ o = instance . options ,
928
932
group = $ . makeArray ( $ ( o . stack ) ) . sort ( function ( a , b ) {
929
933
return ( parseInt ( $ ( a ) . css ( "zIndex" ) , 10 ) || 0 ) - ( parseInt ( $ ( b ) . css ( "zIndex" ) , 10 ) || 0 ) ;
930
934
} ) ;
@@ -940,15 +944,18 @@ $.ui.plugin.add("draggable", "stack", {
940
944
} ) ;
941
945
942
946
$ . ui . plugin . add ( "draggable" , "zIndex" , {
943
- start : function ( event , ui ) {
944
- var t = $ ( ui . helper ) , o = $ ( this ) . draggable ( "instance" ) . options ;
947
+ start : function ( event , ui , instance ) {
948
+ var t = $ ( ui . helper ) ,
949
+ o = instance . options ;
950
+
945
951
if ( t . css ( "zIndex" ) ) {
946
952
o . _zIndex = t . css ( "zIndex" ) ;
947
953
}
948
954
t . css ( "zIndex" , o . zIndex ) ;
949
955
} ,
950
- stop : function ( event , ui ) {
951
- var o = $ ( this ) . draggable ( "instance" ) . options ;
956
+ stop : function ( event , ui , instance ) {
957
+ var o = instance . options ;
958
+
952
959
if ( o . _zIndex ) {
953
960
$ ( ui . helper ) . css ( "zIndex" , o . _zIndex ) ;
954
961
}
0 commit comments