aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-01-24 13:33:24 -0500
committerScott González <scott.gonzalez@gmail.com>2011-01-24 13:33:24 -0500
commitcc90b440607a1af87c4abb8b2ee3325e96b0f5a1 (patch)
tree7152681fe4f4280f8ff6aa441163d7a7f1f29454
parentbc71499a505d0932668b4ae75603cd9dbfd4a2ac (diff)
downloadjquery-ui-cc90b440607a1af87c4abb8b2ee3325e96b0f5a1.tar.gz
jquery-ui-cc90b440607a1af87c4abb8b2ee3325e96b0f5a1.zip
Widget: Allow this.element to be the widget instance instead of a DOM element. Fixes #6895 - Widget: Allow non-DOM based widget.
-rw-r--r--tests/unit/widget/widget_core.js32
-rw-r--r--ui/jquery.ui.widget.js2
2 files changed, 32 insertions, 2 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js
index 189b75368..269b897c5 100644
--- a/tests/unit/widget/widget_core.js
+++ b/tests/unit/widget/widget_core.js
@@ -27,7 +27,7 @@ test( "widget creation", function() {
});
test( "element normalization", function() {
- expect( 10 );
+ expect( 12 );
var elem;
$.widget( "ui.testWidget", {} );
@@ -65,6 +65,14 @@ test( "element normalization", function() {
same( elem.data( "testWidget" ), this, "instace stored in .data()" );
};
$.ui.testWidget( {}, "#element-normalization-selector" );
+
+ $.ui.testWidget.prototype.defaultElement = null;
+ $.ui.testWidget.prototype._create = function() {
+ // using strictEqual throws an error (Maximum call stack size exceeded)
+ ok( this.element[ 0 ] === this, "instance as element" );
+ ok( this.element.data( "testWidget" ) === this, "instance stored in .data()" );
+ };
+ $.ui.testWidget();
});
test( "jQuery usage", function() {
@@ -573,6 +581,28 @@ test( "._trigger() - provide event and ui", function() {
.testWidget( "testEvent" );
});
+test( "._triger() - instance as element", function() {
+ expect( 4 );
+ $.widget( "ui.testWidget", {
+ defaultElement: null,
+ testEvent: function() {
+ var ui = { foo: "bar" };
+ this._trigger( "foo", null, ui );
+ }
+ });
+ var instance = $.ui.testWidget({
+ foo: function( event, ui ) {
+ equal( event.type, "testwidgetfoo", "event object passed to callback" );
+ same( ui, { foo: "bar" }, "ui object passed to callback" );
+ }
+ });
+ $( instance ).bind( "testwidgetfoo", function( event, ui ) {
+ equal( event.type, "testwidgetfoo", "event object passed to event handler" );
+ same( ui, { foo: "bar" }, "ui object passed to event handler" );
+ });
+ instance.testEvent();
+});
+
test( "auto-destroy - .remove()", function() {
expect( 1 );
$.widget( "ui.testWidget", {
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index f6089519b..7dfcb4447 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -133,7 +133,7 @@ $.Widget.prototype = {
disabled: false
},
_createWidget: function( options, element ) {
- element = $( element || this.defaultElement )[ 0 ];
+ element = $( element || this.defaultElement || this )[ 0 ];
$.data( element, this.widgetName, this );
this.element = $( element );
this.options = $.extend( true, {},