]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Fixed show event.
authorScott González <scott.gonzalez@gmail.com>
Tue, 10 May 2011 17:56:59 +0000 (13:56 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 10 May 2011 17:56:59 +0000 (13:56 -0400)
tests/unit/tabs/tabs_deprecated.js
ui/jquery.ui.tabs.js

index 49999670ff3786f8efa78e5346e57729db5cde03..539e9b94d53c483dba5cdfc3a5c460e94306e549 100644 (file)
@@ -251,24 +251,45 @@ test( "disable", function() {
        element.tabs( "disable", 1 );
 });
 
-test('show', function() {
-       expect(5);
 
-       var uiObj, eventObj;
-       el = $('#tabs1').tabs({
-               show: function(event, ui) {
-                       uiObj = ui;
-                       eventObj = event;
-               }
+test( "show", function() {
+       expect( 13 );
+
+       var element = $( "#tabs1" ).tabs({
+                       active: false,
+                       collapsible: true
+               }),
+               tabs = element.find( ".ui-tabs-nav a" ),
+               panels = element.find( ".ui-tabs-panel" );
+
+       // from collapsed
+       element.one( "tabsshow", function( event, ui ) {
+               ok( !( "originalEvent" in event ), "originalEvent" );
+               strictEqual( ui.tab, tabs[ 0 ], "ui.tab" );
+               strictEqual( ui.panel, panels[ 0 ], "ui.panel" );
+               equal( ui.index, 0 );
+               tabs_state( element, 1, 0, 0 );
        });
-       ok(uiObj !== undefined, 'trigger callback after initialization');
-       equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
-       equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
-       equals(uiObj.index, 0, 'contain index');
+       element.tabs( "option", "active", 0 );
+       tabs_state( element, 1, 0, 0 );
 
-       el.find( "li:eq(1) a" ).simulate( "click" );
-       equals( eventObj.originalEvent.type, "click", "show triggered by click" );
+       // switching tabs
+       element.one( "tabsshow", function( event, ui ) {
+               equals( event.originalEvent.type, "click", "originalEvent" );
+               strictEqual( ui.tab, tabs[ 1 ], "ui.tab" );
+               strictEqual( ui.panel, panels[ 1 ], "ui.panel" );
+               equal( ui.index, 1 );
+               tabs_state( element, 0, 1, 0 );
+       });
+       tabs.eq( 1 ).click();
+       tabs_state( element, 0, 1, 0 );
 
+       // collapsing
+       element.one( "tabsshow", function( event, ui ) {
+               ok( false, "collapsing" );
+       });
+       element.tabs( "option", "active", false );
+       tabs_state( element, 0, 0, 0 );
 });
 
 test('select', function() {
index cd9b04f0ded1703b0b7fc65d2605854943bbc436..dca6a538d3d1edf7a8e869e8804a23f8ebbb6722 100644 (file)
@@ -108,15 +108,7 @@ $.widget( "ui.tabs", {
                        var panel = that._getPanelForTab( this.active );
 
                        panel.show();
-
                        this.lis.eq( options.active ).addClass( "ui-tabs-active ui-state-active" );
-
-                       // TODO: we need to remove this or add it to accordion
-                       // seems to be expected behavior that the activate callback is fired
-                       that.element.queue( "tabs", function() {
-                               that._trigger( "activate", null, that._ui( that.active[ 0 ], panel[ 0 ] ) );
-                       });
-
                        this.load( options.active );
                } else {
                        this.active = $();
@@ -968,8 +960,16 @@ if ( $.uiBackCompat !== false ) {
                        show: null,
                        select: null
                });
-               var _trigger = prototype._trigger;
+               var _create = prototype._create,
+                       _trigger = prototype._trigger;
 
+               prototype._create = function() {
+                       _create.call( this );
+                       if ( this.options.active !== false ) {
+                               this._trigger( "show", null, this._ui(
+                                       this.active[ 0 ], this._getPanelForTab( this.active )[ 0 ] ) );
+                       }
+               }
                prototype._trigger = function( type, event, data ) {
                        var ret = _trigger.apply( this, arguments );
                        if ( !ret ) {
@@ -981,8 +981,12 @@ if ( $.uiBackCompat !== false ) {
                                        panel: data.newPanel[ 0 ],
                                        index: data.newTab.closest( "li" ).index()
                                });
-                       } else if ( type === "activate" ) {
-                               ret = _trigger.call( this, "show", event, data );
+                       } else if ( type === "activate" && data.newTab.length ) {
+                               ret = _trigger.call( this, "show", event, {
+                                       tab: data.newTab[ 0 ],
+                                       panel: data.newPanel[ 0 ],
+                                       index: data.newTab.closest( "li" ).index()
+                               });
                        }
                };
        }( jQuery, jQuery.ui.tabs.prototype ) );