Skip to content

Commit

Permalink
Widget: Added create event. Fixes #6126 - Widget: Add create event.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed Sep 30, 2010
1 parent 99b71a5 commit a2ddfd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/unit/widget/widget_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ test( "widget creation", function() {
});

test( "jQuery usage", function() {
expect( 10 );
expect( 11 );

var shouldInit = false;
var shouldCreate = false;

$.widget( "ui.testWidget", {
getterSetterVal: 5,
_create: function() {
ok( shouldInit, "init called on instantiation" );
ok( shouldCreate, "create called on instantiation" );
},
methodWithParams: function( param1, param2 ) {
ok( true, "method called via .pluginName(methodName)" );
Expand All @@ -54,9 +54,13 @@ test( "jQuery usage", function() {
}
});

shouldInit = true;
var elem = $( "<div></div>" ).testWidget();
shouldInit = false;
shouldCreate = true;
var elem = $( "<div></div>" )
.bind( "testwidgetcreate", function() {
ok( shouldCreate, "create event triggered on instantiation" );
})
.testWidget();
shouldCreate = false;

var instance = elem.data( "testWidget" );
equals( typeof instance, "object", "instance stored in .data(pluginName)" );
Expand All @@ -74,12 +78,12 @@ test( "jQuery usage", function() {
test( "direct usage", function() {
expect( 9 );

var shouldInit = false;
var shouldCreate = false;

$.widget( "ui.testWidget", {
getterSetterVal: 5,
_create: function() {
ok( shouldInit, "init called on instantiation" );
ok( shouldCreate, "create called on instantiation" );
},
methodWithParams: function( param1, param2 ) {
ok( true, "method called dirctly" );
Expand All @@ -99,9 +103,9 @@ test( "direct usage", function() {

var elem = $( "<div></div>" )[ 0 ];

shouldInit = true;
shouldCreate = true;
var instance = new $.ui.testWidget( {}, elem );
shouldInit = false;
shouldCreate = false;

equals( $( elem ).data( "testWidget" ), instance,
"instance stored in .data(pluginName)" );
Expand Down
1 change: 1 addition & 0 deletions ui/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ $.Widget.prototype = {
});

this._create();
this._trigger( "create" );
this._init();
},
_create: function() {},
Expand Down

0 comments on commit a2ddfd5

Please sign in to comment.