Skip to content
Permalink
Browse files

Use pushStack in widget method. Fixes #5732 - make the widget method …

…maintain the stack
  • Loading branch information...
jzaefferer committed Jul 30, 2010
1 parent b3940d2 commit ea58cd5ac0d852a9c7d7ceadbcbb74006cf9052d
@@ -38,6 +38,14 @@ test("search", function() {
same( $(".ui-menu .ui-menu-item").length, 2, "only java and javascript for 'ja'" );

$("#autocomplete").autocomplete("destroy");
})
});

test("widget", function() {
var ac = $("#autocomplete").autocomplete({
source: data
});
same(ac.autocomplete("widget")[0], $(":ui-menu")[0]);
same(ac.autocomplete("widget").end()[0], ac[0]);
});

})(jQuery);
@@ -16,4 +16,18 @@ test("destroy", function() {
equal( afterHtml, beforeHtml );
});

test("widget", function() {
var submit = $("#submit").button();
same(submit.button("widget")[0], submit[0]);
same(submit.button("widget").end()[0], submit[0]);

var check = $("#check").button();
same(check.button("widget")[0], check.next("label")[0]);
same(check.button("widget").end()[0], check[0]);

var radio = $("#radio01").button();
same(radio.button("widget")[0], radio.next("label")[0]);
same(radio.button("widget").end()[0], radio[0]);
});

})(jQuery);
@@ -130,4 +130,10 @@ test("open", function() {
ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog visible after open method called');
});

test("widget", function() {
var dialog = $('<div></div>').dialog();
same(dialog.dialog("widget")[0], dialog.parent()[0]);
same(dialog.dialog("widget").end()[0], dialog[0]);
});

})(jQuery);
@@ -151,18 +151,21 @@ test(".widget() - base", function() {
_create: function() {}
});
var div = $("<div></div>").testWidget()
same(div[0], div.testWidget("widget")[0]);
same(div.testWidget("widget")[0], div[0]);
same(div.testWidget("widget").end()[0], div[0]);
});

test(".widget() - overriden", function() {
var wrapper = $("<div></div>");
$.widget("ui.testWidget", {
_create: function() {},
widget: function() {
return wrapper;
return this.element.pushStack(wrapper.get());
}
});
same(wrapper[0], $("<div></div>").testWidget().testWidget("widget")[0]);
var div = $("<div></div>").testWidget();
same(div.testWidget("widget")[0], wrapper[0]);
same(div.testWidget("widget").end()[0], div[0]);
});

})(jQuery);
@@ -311,7 +311,7 @@ $.widget( "ui.autocomplete", {
},

widget: function() {
return this.menu.element;
return this.element.pushStack(this.menu.element.get());
}
});

@@ -210,7 +210,7 @@ $.widget( "ui.button", {
},

widget: function() {
return this.buttonElement;
return this.element.pushStack(this.buttonElement.get());
},

destroy: function() {
@@ -207,7 +207,7 @@ $.widget("ui.dialog", {
},

widget: function() {
return this.uiDialog;
return this.element.pushStack(this.uiDialog.get());
},

close: function(event) {
@@ -160,7 +160,7 @@ $.Widget.prototype = {
},

widget: function() {
return this.element;
return this.element.pushStack(this.element.get());
},

option: function( key, value ) {

2 comments on commit ea58cd5

@scottgonzalez

This comment has been minimized.

Copy link
Member

replied Jul 30, 2010

This maintains the wrong stack. The stack that needs to be maintained is a level higher than the plugin instances. The tests all pass because they only run against a set with a single element.

@jzaefferer

This comment has been minimized.

Copy link
Member Author

replied Jul 30, 2010

Maintaining a higher stack is barely feasible. And not that useful anyway: The widget method is a getter, which always work with only the first element. So having .end() return that element makes perfect sense.

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