Skip to content

Commit a2ddfd5

Browse files
committed
Widget: Added create event. Fixes #6126 - Widget: Add create event.
1 parent 99b71a5 commit a2ddfd5

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

tests/unit/widget/widget_core.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ test( "widget creation", function() {
2727
});
2828

2929
test( "jQuery usage", function() {
30-
expect( 10 );
30+
expect( 11 );
3131

32-
var shouldInit = false;
32+
var shouldCreate = false;
3333

3434
$.widget( "ui.testWidget", {
3535
getterSetterVal: 5,
3636
_create: function() {
37-
ok( shouldInit, "init called on instantiation" );
37+
ok( shouldCreate, "create called on instantiation" );
3838
},
3939
methodWithParams: function( param1, param2 ) {
4040
ok( true, "method called via .pluginName(methodName)" );
@@ -54,9 +54,13 @@ test( "jQuery usage", function() {
5454
}
5555
});
5656

57-
shouldInit = true;
58-
var elem = $( "<div></div>" ).testWidget();
59-
shouldInit = false;
57+
shouldCreate = true;
58+
var elem = $( "<div></div>" )
59+
.bind( "testwidgetcreate", function() {
60+
ok( shouldCreate, "create event triggered on instantiation" );
61+
})
62+
.testWidget();
63+
shouldCreate = false;
6064

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

77-
var shouldInit = false;
81+
var shouldCreate = false;
7882

7983
$.widget( "ui.testWidget", {
8084
getterSetterVal: 5,
8185
_create: function() {
82-
ok( shouldInit, "init called on instantiation" );
86+
ok( shouldCreate, "create called on instantiation" );
8387
},
8488
methodWithParams: function( param1, param2 ) {
8589
ok( true, "method called dirctly" );
@@ -99,9 +103,9 @@ test( "direct usage", function() {
99103

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

102-
shouldInit = true;
106+
shouldCreate = true;
103107
var instance = new $.ui.testWidget( {}, elem );
104-
shouldInit = false;
108+
shouldCreate = false;
105109

106110
equals( $( elem ).data( "testWidget" ), instance,
107111
"instance stored in .data(pluginName)" );

ui/jquery.ui.widget.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ $.Widget.prototype = {
154154
});
155155

156156
this._create();
157+
this._trigger( "create" );
157158
this._init();
158159
},
159160
_create: function() {},

0 commit comments

Comments
 (0)