// workaround for core ticket #8381
this.element.appendTo( "#qunit-fixture" );
ok( this.element.is( "div" ), "generated div" );
- deepEqual( this.element.data( "ui-testWidget" ), this, "instance stored in .data()" );
+ deepEqual( this.element.testWidget( "instance" ), this, "instance stored in .data()" );
};
$.ui.testWidget();
$.ui.testWidget.prototype.defaultElement = "<span data-test='pass'></span>";
$.ui.testWidget.prototype._create = function() {
ok( this.element.is( "span[data-test=pass]" ), "generated span with properties" );
- deepEqual( this.element.data( "ui-testWidget" ), this, "instace stored in .data()" );
+ deepEqual( this.element.testWidget( "instance" ), this, "instace stored in .data()" );
};
$.ui.testWidget();
elem = $( "<input>" );
$.ui.testWidget.prototype._create = function() {
deepEqual( this.element[ 0 ], elem[ 0 ], "from element" );
- deepEqual( elem.data( "ui-testWidget" ), this, "instace stored in .data()" );
+ deepEqual( elem.testWidget( "instance" ), this, "instace stored in .data()" );
};
$.ui.testWidget( {}, elem[ 0 ] );
elem = $( "<div>" );
$.ui.testWidget.prototype._create = function() {
deepEqual( this.element[ 0 ], elem[ 0 ], "from jQuery object" );
- deepEqual( elem.data( "ui-testWidget" ), this, "instace stored in .data()" );
+ deepEqual( elem.testWidget( "instance" ), this, "instace stored in .data()" );
};
$.ui.testWidget( {}, elem );
.appendTo( "#qunit-fixture" );
$.ui.testWidget.prototype._create = function() {
deepEqual( this.element[ 0 ], elem[ 0 ], "from selector" );
- deepEqual( elem.data( "ui-testWidget" ), this, "instace stored in .data()" );
+ deepEqual( elem.testWidget( "instance" ), this, "instace stored in .data()" );
};
$.ui.testWidget( {}, "#element-normalization-selector" );
.testWidget();
shouldCreate = false;
- instance = elem.data( "ui-testWidget" );
+ instance = elem.testWidget( "instance" );
equal( typeof instance, "object", "instance stored in .data(pluginName)" );
equal( instance.element[0], elem[0], "element stored on widget" );
ret = elem.testWidget( "methodWithParams", "value1", "value2" );
equal( ret.end(), elem, "stack preserved" );
elem.testWidget( "destroy" );
- equal( elem.data( "ui-testWidget" ), null );
+ equal( elem.testWidget( "instance" ), null );
});
test( "direct usage", function() {
instance = new $.ui.testWidget( {}, elem );
shouldCreate = false;
- equal( $( elem ).data( "ui-testWidget" ), instance,
+ equal( $( elem ).testWidget( "instance" ), instance,
"instance stored in .data(pluginName)" );
equal( instance.element[ 0 ], elem, "element stored on widget" );
}
});
- instance = $( "<div>" ).testWidget3().data( "ui-testWidget3" );
+ instance = $( "<div>" ).testWidget3().testWidget3( "instance" );
instance.method( 5 );
delete $.ui.testWidget3;
delete $.ui.testWidget2;
}
});
- instance = $( "<div>" ).testWidget3().data( "ui-testWidget3" );
+ instance = $( "<div>" ).testWidget3().testWidget3( "instance" );
instance.method( 5, 10 );
delete $.ui.testWidget3;
delete $.ui.testWidget2;
$.widget( "ui.testWidget", {} );
var div = $( "<div>" ).testWidget();
function deepOption( from, to, msg ) {
- div.data( "ui-testWidget" ).options.foo = from;
+ div.testWidget( "instance" ).options.foo = from;
$.ui.testWidget.prototype._setOption = function( key, value ) {
deepEqual( key, "foo", msg + ": key" );
deepEqual( value, to, msg + ": value" );
div = $( "<div>" );
equal( div.testWidget( "instance" ), undefined );
div.testWidget();
- equal( div.testWidget( "instance" ), div.data( "ui-testWidget" ) );
+ equal( div.testWidget( "instance" ), div.testWidget( "instance" ) );
});
test( "._on() to element (default)", function() {
ok( true, "handler triggered" );
}
});
- var widget = $( "#widget" ).testWidget().data( "ui-testWidget" );
+ var widget = $( "#widget" ).testWidget().testWidget( "instance" );
$( "#widget-wrapper" ).testWidget();
widget.destroy();
$( document ).trigger( "customevent" );
$.widget( "ui.testWidget", {} );
var shouldTriggerWidget, shouldTriggerOther,
element = $( "#widget" ),
- widget = element.testWidget().data( "ui-testWidget" );
+ widget = element.testWidget().testWidget( "instance" );
widget._on( element, { foo: function() {
ok( shouldTriggerWidget, "foo called from _on" );
}});
$.widget( "ui.testWidget", {} );
var shouldTriggerWidget, shouldTriggerOther,
element = $( "#widget" ),
- widget = element.testWidget().data( "ui-testWidget" );
+ widget = element.testWidget().testWidget( "instance" );
widget._on( element, {
foo: function() {
ok( shouldTriggerWidget, "foo called from _on" );
$.widget( "ui.testWidget", {} );
var shouldTriggerWidget, shouldTriggerOther,
element = $( "#widget" ),
- widget = element.testWidget().data( "ui-testWidget" );
+ widget = element.testWidget().testWidget( "instance" );
widget._on( element, {
foo: function() {
ok( shouldTriggerWidget, "foo called from _on" );
deepEqual( ui, {}, "empty ui hash passed" );
handlers.push( this );
});
- deepEqual( $( "#widget" ).data( "ui-testWidget" )._trigger( "foo" ), true,
+ deepEqual( $( "#widget" ).testWidget( "instance" )._trigger( "foo" ), true,
"_trigger returns true when event is not cancelled" );
deepEqual( handlers, [
$( "#widget" )[ 0 ],
ok( true, "event was triggered" );
return false;
});
- deepEqual( $( "#widget" ).data( "ui-testWidget" )._trigger( "foo" ), false,
+ deepEqual( $( "#widget" ).testWidget( "instance" )._trigger( "foo" ), false,
"_trigger returns false when event is cancelled" );
});
return false;
}
});
- deepEqual( $( "#widget" ).data( "ui-testWidget" )._trigger( "foo" ), false,
+ deepEqual( $( "#widget" ).testWidget( "instance" )._trigger( "foo" ), false,
"_trigger returns false when callback returns false" );
});
});
test( "$.widget.bridge()", function() {
- expect( 9 );
+ expect( 10 );
var instance, ret,
elem = $( "<div>" );
strictEqual( elem.testWidget({ foo: "bar" }), elem, "plugin returns original jQuery object" );
instance = elem.data( "testWidget" );
equal( typeof instance, "object", "instance stored in .data(pluginName)" );
+ equal( typeof elem.testWidget( "instance" ), "object", "also retrievable via instance method" );
ret = elem.testWidget( "method", "value1" );
equal( ret, elem, "jQuery object returned from method call" );