Skip to content
Permalink
Browse files

Fix for #3838 - Components should use this.widgetName on internally

  • Loading branch information
eduardolundgren committed Jan 16, 2009
1 parent 358be8b commit 78c4d87d7b2f9f8ece53f062eb44cabf9dd51bf3
Showing with 172 additions and 111 deletions.
  1. +18 −11 ui/ui.accordion.js
  2. +10 −3 ui/ui.dialog.js
  3. +23 −17 ui/ui.draggable.js
  4. +15 −10 ui/ui.droppable.js
  5. +9 −3 ui/ui.progressbar.js
  6. +23 −17 ui/ui.resizable.js
  7. +9 −2 ui/ui.selectable.js
  8. +8 −2 ui/ui.slider.js
  9. +22 −16 ui/ui.sortable.js
  10. +35 −30 ui/ui.tabs.js
@@ -12,11 +12,18 @@
*/
(function($) {

var widgetName = "accordion";
var classWidgetName = ".accordion";

$.widget("ui.accordion", {

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

// update widgetName with the name given by the widget factory
widgetName = this.widgetName;
classWidgetName = '.' + widgetName;

if ( options.navigation ) {
var current = this.element.find("a").filter(options.navigationFilter);
if ( current.length ) {
@@ -32,8 +39,8 @@ $.widget("ui.accordion", {
this.element.addClass("ui-accordion ui-widget ui-helper-reset");
var groups = this.element.children().addClass("ui-accordion-group");
var headers = options.headers = groups.find("> :first-child").addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all")
.bind("mouseenter.accordion", function(){ $(this).addClass('ui-state-hover'); })
.bind("mouseleave.accordion", function(){ $(this).removeClass('ui-state-hover'); });
.bind("mouseenter." + widgetName, function(){ $(this).addClass('ui-state-hover'); })
.bind("mouseleave." + widgetName, function(){ $(this).removeClass('ui-state-hover'); });
// wrap content elements in div against animation issues
headers.next().wrap("<div></div>").addClass("ui-accordion-content").parent().addClass("ui-accordion-content-wrap ui-helper-reset ui-widget-content ui-corner-bottom");

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

if (options.event) {
this.element.bind((options.event) + ".accordion", clickHandler);
this.element.bind((options.event) + classWidgetName, clickHandler);
}
},

destroy: function() {
this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(".accordion");
$.removeData(this.element[0], "accordion");
this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(classWidgetName);
$.removeData(this.element[0], widgetName);
var groups = this.element.children().removeClass("ui-accordion-group "+this.options.selectedClass);
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")
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")
.removeAttr("role").removeAttr("aria-expanded").removeAttr("tabindex");
headers.find("a").removeAttr("tabindex");
headers.children(".ui-icon").remove();
@@ -168,11 +175,11 @@ function scopeCallback(callback, scope) {

function completed(cancel) {
// if removed while animated data can be empty
if (!$.data(this, "accordion")) {
if (!$.data(this, widgetName)) {
return;
}

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

function toggle(toShow, toHide, data, clickedActive, down) {
var options = $.data(this, "accordion").options;
var options = $.data(this, widgetName).options;
options.toShow = toShow;
options.toHide = toHide;
options.data = data;
var complete = scopeCallback(completed, this);

$.data(this, "accordion")._trigger("changestart", null, options.data);
$.data(this, widgetName)._trigger("changestart", null, options.data);

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

function clickHandler(event) {
var options = $.data(this, "accordion").options;
var options = $.data(this, widgetName).options;
if (options.disabled) {
return false;
}
@@ -14,6 +14,9 @@
*/
(function($) {

var widgetName = "dialog";
var classWidgetName = ".dialog";

var setDataSwitch = {
dragStart: "start.draggable",
drag: "drag.draggable",
@@ -30,6 +33,10 @@ var setDataSwitch = {
$.widget("ui.dialog", {

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

this.originalTitle = this.element.attr('title');
this.options.title = this.options.title || this.originalTitle;

@@ -61,7 +68,7 @@ $.widget("ui.dialog", {
&& ev.keyCode == $.ui.keyCode.ESCAPE && self.close());
})
.attr({
role: 'dialog',
role: widgetName,
'aria-labelledby': titleId
})
.mousedown(function() {
@@ -152,8 +159,8 @@ $.widget("ui.dialog", {
(this.overlay && this.overlay.destroy());
this.uiDialog.hide();
this.element
.unbind('.dialog')
.removeData('dialog')
.unbind(classWidgetName)
.removeData(widgetName)
.removeClass('ui-dialog-content ui-widget-content')
.hide().appendTo('body');
this.uiDialog.remove();
@@ -12,9 +12,15 @@
*/
(function($) {

var widgetName = "draggable";
var classWidgetName = ".draggable";

$.widget("ui.draggable", $.extend({}, $.ui.mouse, {

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

if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
this.element[0].style.position = 'relative';
@@ -27,8 +33,8 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
},

destroy: function() {
if(!this.element.data('draggable')) return;
this.element.removeData("draggable").unbind(".draggable").removeClass(this.options.cssNamespace+'-draggable '+this.options.cssNamespace+'-draggable-dragging '+this.options.cssNamespace+'-draggable-disabled');
if(!this.element.data(widgetName)) return;
this.element.removeData(widgetName).unbind(classWidgetName).removeClass(this.options.cssNamespace+'-draggable '+this.options.cssNamespace+'-draggable-dragging '+this.options.cssNamespace+'-draggable-disabled');
this._mouseDestroy();
},

@@ -426,10 +432,10 @@ $.extend($.ui.draggable, {
}
});

$.ui.plugin.add("draggable", "connectToSortable", {
$.ui.plugin.add(widgetName, "connectToSortable", {
start: function(event, ui) {

var inst = $(this).data("draggable");
var inst = $(this).data(widgetName);
inst.sortables = [];
$(ui.options.connectToSortable).each(function() {
// '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", {
stop: function(event, ui) {

//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
var inst = $(this).data("draggable");
var inst = $(this).data(widgetName);

$.each(inst.sortables, function() {
if(this.instance.isOver) {
@@ -486,7 +492,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
},
drag: function(event, ui) {

var inst = $(this).data("draggable"), self = this;
var inst = $(this).data(widgetName), self = this;

var checkPos = function(o) {
var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
@@ -556,7 +562,7 @@ $.ui.plugin.add("draggable", "connectToSortable", {
}
});

$.ui.plugin.add("draggable", "cursor", {
$.ui.plugin.add(widgetName, "cursor", {
start: function(event, ui) {
var t = $('body');
if (t.css("cursor")) ui.options._cursor = t.css("cursor");
@@ -567,7 +573,7 @@ $.ui.plugin.add("draggable", "cursor", {
}
});

$.ui.plugin.add("draggable", "iframeFix", {
$.ui.plugin.add(widgetName, "iframeFix", {
start: function(event, ui) {
$(ui.options.iframeFix === true ? "iframe" : ui.options.iframeFix).each(function() {
$('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
@@ -584,7 +590,7 @@ $.ui.plugin.add("draggable", "iframeFix", {
}
});

$.ui.plugin.add("draggable", "opacity", {
$.ui.plugin.add(widgetName, "opacity", {
start: function(event, ui) {
var t = $(ui.helper);
if(t.css("opacity")) ui.options._opacity = t.css("opacity");
@@ -595,18 +601,18 @@ $.ui.plugin.add("draggable", "opacity", {
}
});

$.ui.plugin.add("draggable", "scroll", {
$.ui.plugin.add(widgetName, "scroll", {
start: function(event, ui) {
var o = ui.options;
var i = $(this).data("draggable");
var i = $(this).data(widgetName);

if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();

},
drag: function(event, ui) {

var o = ui.options, scrolled = false;
var i = $(this).data("draggable");
var i = $(this).data(widgetName);

if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {

@@ -640,10 +646,10 @@ $.ui.plugin.add("draggable", "scroll", {
}
});

$.ui.plugin.add("draggable", "snap", {
$.ui.plugin.add(widgetName, "snap", {
start: function(event, ui) {

var inst = $(this).data("draggable");
var inst = $(this).data(widgetName);
inst.snapElements = [];

$(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", {
},
drag: function(event, ui) {

var inst = $(this).data("draggable");
var inst = $(this).data(widgetName);
var d = ui.options.snapTolerance;

var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width,
@@ -709,7 +715,7 @@ $.ui.plugin.add("draggable", "snap", {
}
});

$.ui.plugin.add("draggable", "stack", {
$.ui.plugin.add(widgetName, "stack", {
start: function(event, ui) {
var group = $.makeArray($(ui.options.stack.group)).sort(function(a,b) {
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", {
}
});

$.ui.plugin.add("draggable", "zIndex", {
$.ui.plugin.add(widgetName, "zIndex", {
start: function(event, ui) {
var t = $(ui.helper);
if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
@@ -13,9 +13,15 @@
*/
(function($) {

var widgetName = "droppable";
var classWidgetName = ".droppable";

$.widget("ui.droppable", {

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

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

this.element
.removeClass(this.options.cssNamespace+"-droppable "+this.options.cssNamespace+"-droppable-disabled")
.removeData("droppable")
.unbind(".droppable");
.removeData(widgetName)
.unbind(classWidgetName);
},

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

var childrenIntersection = false;
this.element.find(":data(droppable)").not("."+draggable.options.cssNamespace+"-draggable-dragging").each(function() {
var inst = $.data(this, 'droppable');
this.element.find(":data(" + widgetName + ")").not("."+draggable.options.cssNamespace+"-draggable-dragging").each(function() {
var inst = $.data(this, widgetName);
if(inst.options.greedy && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)) {
childrenIntersection = true; return false;
}
@@ -203,10 +209,9 @@ $.ui.ddmanager = {
current: null,
droppables: { 'default': [] },
prepareOffsets: function(t, event) {

var m = $.ui.ddmanager.droppables[t.options.scope];
var type = event ? event.type : null; // workaround for #2317
var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
var list = (t.currentItem || t.element).find(":data(" + widgetName + ")").andSelf();

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

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

var parentInstance;
if (this.options.greedy) {
var parent = this.element.parents(':data(droppable):eq(0)');
var parent = this.element.parents(':data(' + widgetName + '):eq(0)');
if (parent.length) {
parentInstance = $.data(parent[0], 'droppable');
parentInstance = $.data(parent[0], widgetName);
parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
}
}
@@ -289,7 +294,7 @@ $.ui.ddmanager = {
* Droppable Extensions
*/

$.ui.plugin.add("droppable", "activeClass", {
$.ui.plugin.add(widgetName, "activeClass", {
activate: function(event, ui) {
$(this).addClass(ui.options.activeClass);
},
@@ -301,7 +306,7 @@ $.ui.plugin.add("droppable", "activeClass", {
}
});

$.ui.plugin.add("droppable", "hoverClass", {
$.ui.plugin.add(widgetName, "hoverClass", {
over: function(event, ui) {
$(this).addClass(ui.options.hoverClass);
},
@@ -12,9 +12,15 @@
*/
(function($) {

var widgetName = "progressbar";
var classWidgetName = ".progressbar";

$.widget("ui.progressbar", {

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

var self = this,
options = this.options;
@@ -25,7 +31,7 @@ $.widget("ui.progressbar", {
+ " ui-widget-content"
+ " ui-corner-all")
.attr({
role: "progressbar",
role: widgetName,
"aria-valuemin": this._valueMin(),
"aria-valuemax": this._valueMax(),
"aria-valuenow": this._value()
@@ -48,8 +54,8 @@ $.widget("ui.progressbar", {
.removeAttr("aria-valuemin")
.removeAttr("aria-valuemax")
.removeAttr("aria-valuenow")
.removeData("progressbar")
.unbind(".progressbar");
.removeData(widgetName)
.unbind(classWidgetName);

this.valueDiv.remove();

0 comments on commit 78c4d87

Please sign in to comment.
You can’t perform that action at this time.