Skip to content

Commit 78c4d87

Browse files
Fix for #3838 - Components should use this.widgetName on internally
1 parent 358be8b commit 78c4d87

10 files changed

Lines changed: 172 additions & 111 deletions

ui/ui.accordion.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
*/
1313
(function($) {
1414

15+
var widgetName = "accordion";
16+
var classWidgetName = ".accordion";
17+
1518
$.widget("ui.accordion", {
1619

1720
_init: function() {
1821
var options = this.options;
1922

23+
// update widgetName with the name given by the widget factory
24+
widgetName = this.widgetName;
25+
classWidgetName = '.' + widgetName;
26+
2027
if ( options.navigation ) {
2128
var current = this.element.find("a").filter(options.navigationFilter);
2229
if ( current.length ) {
@@ -32,8 +39,8 @@ $.widget("ui.accordion", {
3239
this.element.addClass("ui-accordion ui-widget ui-helper-reset");
3340
var groups = this.element.children().addClass("ui-accordion-group");
3441
var headers = options.headers = groups.find("> :first-child").addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all")
35-
.bind("mouseenter.accordion", function(){ $(this).addClass('ui-state-hover'); })
36-
.bind("mouseleave.accordion", function(){ $(this).removeClass('ui-state-hover'); });
42+
.bind("mouseenter." + widgetName, function(){ $(this).addClass('ui-state-hover'); })
43+
.bind("mouseleave." + widgetName, function(){ $(this).removeClass('ui-state-hover'); });
3744
// wrap content elements in div against animation issues
3845
headers.next().wrap("<div></div>").addClass("ui-accordion-content").parent().addClass("ui-accordion-content-wrap ui-helper-reset ui-widget-content ui-corner-bottom");
3946

@@ -79,15 +86,15 @@ $.widget("ui.accordion", {
7986
options.headers.find('a').attr('tabIndex','-1');
8087

8188
if (options.event) {
82-
this.element.bind((options.event) + ".accordion", clickHandler);
89+
this.element.bind((options.event) + classWidgetName, clickHandler);
8390
}
8491
},
8592

8693
destroy: function() {
87-
this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(".accordion");
88-
$.removeData(this.element[0], "accordion");
94+
this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(classWidgetName);
95+
$.removeData(this.element[0], widgetName);
8996
var groups = this.element.children().removeClass("ui-accordion-group "+this.options.selectedClass);
90-
var headers = this.options.headers.unbind(".accordion").removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-corner-top")
97+
var headers = this.options.headers.unbind(classWidgetName).removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-corner-top")
9198
.removeAttr("role").removeAttr("aria-expanded").removeAttr("tabindex");
9299
headers.find("a").removeAttr("tabindex");
93100
headers.children(".ui-icon").remove();
@@ -168,11 +175,11 @@ function scopeCallback(callback, scope) {
168175

169176
function completed(cancel) {
170177
// if removed while animated data can be empty
171-
if (!$.data(this, "accordion")) {
178+
if (!$.data(this, widgetName)) {
172179
return;
173180
}
174181

175-
var instance = $.data(this, "accordion");
182+
var instance = $.data(this, widgetName);
176183
var options = instance.options;
177184
options.running = cancel ? 0 : --options.running;
178185
if ( options.running ) {
@@ -188,13 +195,13 @@ function completed(cancel) {
188195
}
189196

190197
function toggle(toShow, toHide, data, clickedActive, down) {
191-
var options = $.data(this, "accordion").options;
198+
var options = $.data(this, widgetName).options;
192199
options.toShow = toShow;
193200
options.toHide = toHide;
194201
options.data = data;
195202
var complete = scopeCallback(completed, this);
196203

197-
$.data(this, "accordion")._trigger("changestart", null, options.data);
204+
$.data(this, widgetName)._trigger("changestart", null, options.data);
198205

199206
// count elements to animate
200207
options.running = toHide.size() === 0 ? toShow.size() : toHide.size();
@@ -263,7 +270,7 @@ function toggle(toShow, toHide, data, clickedActive, down) {
263270
}
264271

265272
function clickHandler(event) {
266-
var options = $.data(this, "accordion").options;
273+
var options = $.data(this, widgetName).options;
267274
if (options.disabled) {
268275
return false;
269276
}

ui/ui.dialog.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
(function($) {
1616

17+
var widgetName = "dialog";
18+
var classWidgetName = ".dialog";
19+
1720
var setDataSwitch = {
1821
dragStart: "start.draggable",
1922
drag: "drag.draggable",
@@ -30,6 +33,10 @@ var setDataSwitch = {
3033
$.widget("ui.dialog", {
3134

3235
_init: function() {
36+
// update widgetName with the name given by the widget factory
37+
widgetName = this.widgetName;
38+
classWidgetName = '.' + widgetName;
39+
3340
this.originalTitle = this.element.attr('title');
3441
this.options.title = this.options.title || this.originalTitle;
3542

@@ -61,7 +68,7 @@ $.widget("ui.dialog", {
6168
&& ev.keyCode == $.ui.keyCode.ESCAPE && self.close());
6269
})
6370
.attr({
64-
role: 'dialog',
71+
role: widgetName,
6572
'aria-labelledby': titleId
6673
})
6774
.mousedown(function() {
@@ -152,8 +159,8 @@ $.widget("ui.dialog", {
152159
(this.overlay && this.overlay.destroy());
153160
this.uiDialog.hide();
154161
this.element
155-
.unbind('.dialog')
156-
.removeData('dialog')
162+
.unbind(classWidgetName)
163+
.removeData(widgetName)
157164
.removeClass('ui-dialog-content ui-widget-content')
158165
.hide().appendTo('body');
159166
this.uiDialog.remove();

ui/ui.draggable.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
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");

ui/ui.droppable.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
*/
1414
(function($) {
1515

16+
var widgetName = "droppable";
17+
var classWidgetName = ".droppable";
18+
1619
$.widget("ui.droppable", {
1720

1821
_init: function() {
22+
// update widgetName with the name given by the widget factory
23+
widgetName = this.widgetName;
24+
classWidgetName = '.' + widgetName;
1925

2026
var o = this.options, accept = o.accept;
2127
this.isover = 0; this.isout = 1;
@@ -43,8 +49,8 @@ $.widget("ui.droppable", {
4349

4450
this.element
4551
.removeClass(this.options.cssNamespace+"-droppable "+this.options.cssNamespace+"-droppable-disabled")
46-
.removeData("droppable")
47-
.unbind(".droppable");
52+
.removeData(widgetName)
53+
.unbind(classWidgetName);
4854
},
4955

5056
_setData: function(key, value) {
@@ -105,8 +111,8 @@ $.widget("ui.droppable", {
105111
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
106112

107113
var childrenIntersection = false;
108-
this.element.find(":data(droppable)").not("."+draggable.options.cssNamespace+"-draggable-dragging").each(function() {
109-
var inst = $.data(this, 'droppable');
114+
this.element.find(":data(" + widgetName + ")").not("."+draggable.options.cssNamespace+"-draggable-dragging").each(function() {
115+
var inst = $.data(this, widgetName);
110116
if(inst.options.greedy && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)) {
111117
childrenIntersection = true; return false;
112118
}
@@ -203,10 +209,9 @@ $.ui.ddmanager = {
203209
current: null,
204210
droppables: { 'default': [] },
205211
prepareOffsets: function(t, event) {
206-
207212
var m = $.ui.ddmanager.droppables[t.options.scope];
208213
var type = event ? event.type : null; // workaround for #2317
209-
var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
214+
var list = (t.currentItem || t.element).find(":data(" + widgetName + ")").andSelf();
210215

211216
droppablesLoop: for (var i = 0; i < m.length; i++) {
212217

@@ -257,9 +262,9 @@ $.ui.ddmanager = {
257262

258263
var parentInstance;
259264
if (this.options.greedy) {
260-
var parent = this.element.parents(':data(droppable):eq(0)');
265+
var parent = this.element.parents(':data(' + widgetName + '):eq(0)');
261266
if (parent.length) {
262-
parentInstance = $.data(parent[0], 'droppable');
267+
parentInstance = $.data(parent[0], widgetName);
263268
parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
264269
}
265270
}
@@ -289,7 +294,7 @@ $.ui.ddmanager = {
289294
* Droppable Extensions
290295
*/
291296

292-
$.ui.plugin.add("droppable", "activeClass", {
297+
$.ui.plugin.add(widgetName, "activeClass", {
293298
activate: function(event, ui) {
294299
$(this).addClass(ui.options.activeClass);
295300
},
@@ -301,7 +306,7 @@ $.ui.plugin.add("droppable", "activeClass", {
301306
}
302307
});
303308

304-
$.ui.plugin.add("droppable", "hoverClass", {
309+
$.ui.plugin.add(widgetName, "hoverClass", {
305310
over: function(event, ui) {
306311
$(this).addClass(ui.options.hoverClass);
307312
},

ui/ui.progressbar.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
*/
1313
(function($) {
1414

15+
var widgetName = "progressbar";
16+
var classWidgetName = ".progressbar";
17+
1518
$.widget("ui.progressbar", {
1619

1720
_init: function() {
21+
// update widgetName with the name given by the widget factory
22+
widgetName = this.widgetName;
23+
classWidgetName = '.' + widgetName;
1824

1925
var self = this,
2026
options = this.options;
@@ -25,7 +31,7 @@ $.widget("ui.progressbar", {
2531
+ " ui-widget-content"
2632
+ " ui-corner-all")
2733
.attr({
28-
role: "progressbar",
34+
role: widgetName,
2935
"aria-valuemin": this._valueMin(),
3036
"aria-valuemax": this._valueMax(),
3137
"aria-valuenow": this._value()
@@ -48,8 +54,8 @@ $.widget("ui.progressbar", {
4854
.removeAttr("aria-valuemin")
4955
.removeAttr("aria-valuemax")
5056
.removeAttr("aria-valuenow")
51-
.removeData("progressbar")
52-
.unbind(".progressbar");
57+
.removeData(widgetName)
58+
.unbind(classWidgetName);
5359

5460
this.valueDiv.remove();
5561

0 commit comments

Comments
 (0)