]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Added create event. Fixes #6126 - Widget: Add create event.
authorScott González <scott.gonzalez@gmail.com>
Thu, 30 Sep 2010 00:36:45 +0000 (17:36 -0700)
committerScott González <scott.gonzalez@gmail.com>
Thu, 30 Sep 2010 00:36:45 +0000 (17:36 -0700)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 76d6543c249e90eb2dab496b3692f1892171ad48..364838e3f208dded6b3e5946e9e5f1a1a9b597ce 100644 (file)
@@ -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)" );
@@ -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)" );
@@ -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" );
@@ -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)" );
index 866f7441e5cb230f88099b4dead9aefb17648218..bc6408125c7f523f44b7e8205df5b672803b14a0 100644 (file)
@@ -154,6 +154,7 @@ $.Widget.prototype = {
                });
 
                this._create();
+               this._trigger( "create" );
                this._init();
        },
        _create: function() {},