From 6800e1a2f97a7d8aaf20d065aa2ce517528e5068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Sat, 21 Jan 2012 08:46:02 -0500 Subject: [PATCH] Tabs: Pass tab and panel in create event. Fixes #7868 - Tabs: Provide tab and panel details in create event. --- tests/unit/tabs/tabs_events.js | 39 ++++++++++++++++++++++++++++++++++ ui/jquery.ui.tabs.js | 7 ++++++ 2 files changed, 46 insertions(+) diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js index f5cde180b..333578907 100644 --- a/tests/unit/tabs/tabs_events.js +++ b/tests/unit/tabs/tabs_events.js @@ -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 ); diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 168aa0ee5..7a701405c 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -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