]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Pass tab and panel in create event. Fixes #7868 - Tabs: Provide tab and panel...
authorScott González <scott.gonzalez@gmail.com>
Sat, 21 Jan 2012 13:46:02 +0000 (08:46 -0500)
committerScott González <scott.gonzalez@gmail.com>
Sat, 21 Jan 2012 13:46:02 +0000 (08:46 -0500)
tests/unit/tabs/tabs_events.js
ui/jquery.ui.tabs.js

index f5cde180bb6ab8e77e737bba4258bf578a7fe10a..3335789079e73cafd9f829acdd584b1afe10f32d 100644 (file)
@@ -2,6 +2,45 @@
 
 module( "tabs: events" );
 
+test( "create", function() {
+       expect( 10 );
+
+       var element = $( "#tabs1" ),
+               tabs = element.find( "ul a" ),
+               panels = element.children( "div" );
+
+       element.tabs({
+               create: function( event, ui ) {
+                       equals( ui.tab.size(), 1, "tab size" );
+                       strictEqual( ui.tab[ 0 ], tabs[ 0 ], "tab" );
+                       equals( ui.panel.size(), 1, "panel size" );
+                       strictEqual( ui.panel[ 0 ], panels[ 0 ], "panel" );
+               }
+       });
+       element.tabs( "destroy" );
+
+       element.tabs({
+               active: 2,
+               create: function( event, ui ) {
+                       equals( ui.tab.size(), 1, "tab size" );
+                       strictEqual( ui.tab[ 0 ], tabs[ 2 ], "tab" );
+                       equals( ui.panel.size(), 1, "panel size" );
+                       strictEqual( ui.panel[ 0 ], panels[ 2 ], "panel" );
+               }
+       });
+       element.tabs( "destroy" );
+
+       element.tabs({
+               active: false,
+               collapsible: true,
+               create: function( event, ui ) {
+                       equals( ui.tab.size(), 0, "tab size" );
+                       equals( ui.panel.size(), 0, "panel size" );
+               }
+       });
+       element.tabs( "destroy" );
+});
+
 test( "beforeActivate", function() {
        expect( 38 );
 
index 168aa0ee55153a10dc63ee0d619d19272f522270..7a701405ca19e6b28c258ba91a5b26443bae745c 100644 (file)
@@ -120,6 +120,13 @@ $.widget( "ui.tabs", {
                }
        },
 
+       _getCreateEventData: function() {
+               return {
+                       tab: this.active,
+                       panel: !this.active.length ? $() : this._getPanelForTab( this.active )
+               };
+       },
+
        _setOption: function( key, value ) {
                if ( key == "active" ) {
                        // _activate() will handle invalid values and update this.options