1212 */
1313( function ( $ ) {
1414
15+ var widgetName = "draggable" ;
16+ var classWidgetName = ".draggable" ;
17+
1518$ . widget ( "ui.draggable" , $ . extend ( { } , $ . ui . mouse , {
1619
1720 _init : function ( ) {
21+ // update widgetName with the name given by the widget factory
22+ widgetName = this . widgetName ;
23+ classWidgetName = '.' + widgetName ;
1824
1925 if ( this . options . helper == 'original' && ! ( / ^ (?: r | a | f ) / ) . test ( this . element . css ( "position" ) ) )
2026 this . element [ 0 ] . style . position = 'relative' ;
@@ -27,8 +33,8 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
2733 } ,
2834
2935 destroy : function ( ) {
30- if ( ! this . element . data ( 'draggable' ) ) return ;
31- this . element . removeData ( "draggable" ) . unbind ( ".draggable" ) . removeClass ( this . options . cssNamespace + '-draggable ' + this . options . cssNamespace + '-draggable-dragging ' + this . options . cssNamespace + '-draggable-disabled' ) ;
36+ if ( ! this . element . data ( widgetName ) ) return ;
37+ this . element . removeData ( widgetName ) . unbind ( classWidgetName ) . removeClass ( this . options . cssNamespace + '-draggable ' + this . options . cssNamespace + '-draggable-dragging ' + this . options . cssNamespace + '-draggable-disabled' ) ;
3238 this . _mouseDestroy ( ) ;
3339 } ,
3440
@@ -426,10 +432,10 @@ $.extend($.ui.draggable, {
426432 }
427433} ) ;
428434
429- $ . ui . plugin . add ( "draggable" , "connectToSortable" , {
435+ $ . ui . plugin . add ( widgetName , "connectToSortable" , {
430436 start : function ( event , ui ) {
431437
432- var inst = $ ( this ) . data ( "draggable" ) ;
438+ var inst = $ ( this ) . data ( widgetName ) ;
433439 inst . sortables = [ ] ;
434440 $ ( ui . options . connectToSortable ) . each ( function ( ) {
435441 // 'this' points to a string, and should therefore resolved as query, but instead, if the string is assigned to a variable, it loops through the strings properties,
@@ -451,7 +457,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
451457 stop : function ( event , ui ) {
452458
453459 //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
454- var inst = $ ( this ) . data ( "draggable" ) ;
460+ var inst = $ ( this ) . data ( widgetName ) ;
455461
456462 $ . each ( inst . sortables , function ( ) {
457463 if ( this . instance . isOver ) {
@@ -486,7 +492,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
486492 } ,
487493 drag : function ( event , ui ) {
488494
489- var inst = $ ( this ) . data ( "draggable" ) , self = this ;
495+ var inst = $ ( this ) . data ( widgetName ) , self = this ;
490496
491497 var checkPos = function ( o ) {
492498 var dyClick = this . offset . click . top , dxClick = this . offset . click . left ;
@@ -556,7 +562,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
556562 }
557563} ) ;
558564
559- $ . ui . plugin . add ( "draggable" , "cursor" , {
565+ $ . ui . plugin . add ( widgetName , "cursor" , {
560566 start : function ( event , ui ) {
561567 var t = $ ( 'body' ) ;
562568 if ( t . css ( "cursor" ) ) ui . options . _cursor = t . css ( "cursor" ) ;
@@ -567,7 +573,7 @@ $.ui.plugin.add("draggable", "cursor", {
567573 }
568574} ) ;
569575
570- $ . ui . plugin . add ( "draggable" , "iframeFix" , {
576+ $ . ui . plugin . add ( widgetName , "iframeFix" , {
571577 start : function ( event , ui ) {
572578 $ ( ui . options . iframeFix === true ? "iframe" : ui . options . iframeFix ) . each ( function ( ) {
573579 $ ( '<div class="ui-draggable-iframeFix" style="background: #fff;"></div>' )
@@ -584,7 +590,7 @@ $.ui.plugin.add("draggable", "iframeFix", {
584590 }
585591} ) ;
586592
587- $ . ui . plugin . add ( "draggable" , "opacity" , {
593+ $ . ui . plugin . add ( widgetName , "opacity" , {
588594 start : function ( event , ui ) {
589595 var t = $ ( ui . helper ) ;
590596 if ( t . css ( "opacity" ) ) ui . options . _opacity = t . css ( "opacity" ) ;
@@ -595,18 +601,18 @@ $.ui.plugin.add("draggable", "opacity", {
595601 }
596602} ) ;
597603
598- $ . ui . plugin . add ( "draggable" , "scroll" , {
604+ $ . ui . plugin . add ( widgetName , "scroll" , {
599605 start : function ( event , ui ) {
600606 var o = ui . options ;
601- var i = $ ( this ) . data ( "draggable" ) ;
607+ var i = $ ( this ) . data ( widgetName ) ;
602608
603609 if ( i . scrollParent [ 0 ] != document && i . scrollParent [ 0 ] . tagName != 'HTML' ) i . overflowOffset = i . scrollParent . offset ( ) ;
604610
605611 } ,
606612 drag : function ( event , ui ) {
607613
608614 var o = ui . options , scrolled = false ;
609- var i = $ ( this ) . data ( "draggable" ) ;
615+ var i = $ ( this ) . data ( widgetName ) ;
610616
611617 if ( i . scrollParent [ 0 ] != document && i . scrollParent [ 0 ] . tagName != 'HTML' ) {
612618
@@ -640,10 +646,10 @@ $.ui.plugin.add("draggable", "scroll", {
640646 }
641647} ) ;
642648
643- $ . ui . plugin . add ( "draggable" , "snap" , {
649+ $ . ui . plugin . add ( widgetName , "snap" , {
644650 start : function ( event , ui ) {
645651
646- var inst = $ ( this ) . data ( "draggable" ) ;
652+ var inst = $ ( this ) . data ( widgetName ) ;
647653 inst . snapElements = [ ] ;
648654
649655 $ ( ui . options . snap . constructor != String ? ( ui . options . snap . items || ':data(draggable)' ) : ui . options . snap ) . each ( function ( ) {
@@ -658,7 +664,7 @@ $.ui.plugin.add("draggable", "snap", {
658664 } ,
659665 drag : function ( event , ui ) {
660666
661- var inst = $ ( this ) . data ( "draggable" ) ;
667+ var inst = $ ( this ) . data ( widgetName ) ;
662668 var d = ui . options . snapTolerance ;
663669
664670 var x1 = ui . absolutePosition . left , x2 = x1 + inst . helperProportions . width ,
@@ -709,7 +715,7 @@ $.ui.plugin.add("draggable", "snap", {
709715 }
710716} ) ;
711717
712- $ . ui . plugin . add ( "draggable" , "stack" , {
718+ $ . ui . plugin . add ( widgetName , "stack" , {
713719 start : function ( event , ui ) {
714720 var group = $ . makeArray ( $ ( ui . options . stack . group ) ) . sort ( function ( a , b ) {
715721 return ( parseInt ( $ ( a ) . css ( "zIndex" ) , 10 ) || ui . options . stack . min ) - ( parseInt ( $ ( b ) . css ( "zIndex" ) , 10 ) || ui . options . stack . min ) ;
@@ -723,7 +729,7 @@ $.ui.plugin.add("draggable", "stack", {
723729 }
724730} ) ;
725731
726- $ . ui . plugin . add ( "draggable" , "zIndex" , {
732+ $ . ui . plugin . add ( widgetName , "zIndex" , {
727733 start : function ( event , ui ) {
728734 var t = $ ( ui . helper ) ;
729735 if ( t . css ( "zIndex" ) ) ui . options . _zIndex = t . css ( "zIndex" ) ;
0 commit comments