});
test( "element normalization", function() {
- expect( 10 );
+ expect( 12 );
var elem;
$.widget( "ui.testWidget", {} );
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() {
.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", {
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, {},