Skip to content
Permalink
Browse files

Widget: Allow this.element to be the widget instance instead of a DOM…

… element. Fixes #6895 - Widget: Allow non-DOM based widget.
  • Loading branch information...
scottgonzalez committed Jan 24, 2011
1 parent bc71499 commit cc90b440607a1af87c4abb8b2ee3325e96b0f5a1
Showing with 32 additions and 2 deletions.
  1. +31 −1 tests/unit/widget/widget_core.js
  2. +1 −1 ui/jquery.ui.widget.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", {
@@ -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, {},

0 comments on commit cc90b44

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