]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Fixed load event with back compat enabled.
authorScott González <scott.gonzalez@gmail.com>
Tue, 17 May 2011 19:46:41 +0000 (15:46 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 17 May 2011 19:46:41 +0000 (15:46 -0400)
tests/unit/tabs/tabs_deprecated.js
tests/unit/tabs/tabs_events.js
tests/unit/tabs/tabs_methods.js
ui/jquery.ui.tabs.js

index 4b50df405e72e37afcb187778a98621d65fe2d03..1323c774a0c395fdc39af879b2c4882f230d71fa 100644 (file)
@@ -35,7 +35,7 @@ asyncTest( "ajaxOptions", function() {
                }
        });
        element.one( "tabsload", function( event, ui ) {
-               equals( ui.panel.html(), "test" );
+               equals( $( ui.panel ).html(), "test" );
                start();
        });
        element.tabs( "option", "active", 2 );
@@ -220,6 +220,62 @@ test( "selected", function() {
 
 module( "tabs (deprecated): events" );
 
+asyncTest( "load", function() {
+       expect( 15 );
+
+       var tab, panelId, panel,
+               element = $( "#tabs2" );
+
+       // init
+       element.one( "tabsload", function( event, ui ) {
+               tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
+               panelId = tab.attr( "aria-controls" );
+               panel = $( "#" + panelId );
+
+               ok( !( "originalEvent" in event ), "originalEvent" );
+               strictEqual( ui.tab, tab[ 0 ], "tab" );
+               strictEqual( ui.panel, panel[ 0 ], "panel" );
+               equals( $( ui.panel ).find( "p" ).length, 1, "panel html" );
+               tabs_state( element, 0, 0, 1, 0, 0 );
+               tabsload1();
+       });
+       element.tabs({ active: 2 });
+
+       function tabsload1() {
+               // .option()
+               element.one( "tabsload", function( event, ui ) {
+                       tab = element.find( ".ui-tabs-nav a" ).eq( 3 );
+                       panelId = tab.attr( "aria-controls" );
+                       panel = $( "#" + panelId );
+
+                       ok( !( "originalEvent" in event ), "originalEvent" );
+                       strictEqual( ui.tab, tab[ 0 ], "tab" );
+                       strictEqual( ui.panel, panel[ 0 ], "panel" );
+                       equals( $( ui.panel ).find( "p" ).length, 1, "panel html" );
+                       tabs_state( element, 0, 0, 0, 1, 0 );
+                       tabsload2();
+               });
+               element.tabs( "option", "active", 3 );
+       }
+
+       function tabsload2() {
+               // click, change panel content
+               element.one( "tabsload", function( event, ui ) {
+                       tab = element.find( ".ui-tabs-nav a" ).eq( 4 );
+                       panelId = tab.attr( "aria-controls" );
+                       panel = $( "#" + panelId );
+
+                       equals( event.originalEvent.type, "click", "originalEvent" );
+                       strictEqual( ui.tab, tab[ 0 ], "tab" );
+                       strictEqual( ui.panel, panel[ 0 ], "panel" );
+                       equals( $( ui.panel ).find( "p" ).length, 1, "panel html" );
+                       tabs_state( element, 0, 0, 0, 0, 1 );
+                       start();
+               });
+               element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
+       }
+});
+
 test( "enable", function() {
        expect( 3 );
 
index 2fabaafca49af9526f94592e1803f288d4a154a6..12c9bb87b3e6d4ebdf90cc65066fe36233e366bd 100644 (file)
@@ -209,66 +209,68 @@ test( "beforeLoad", function() {
        equals( panel.html(), "<p>testing</p>", "panel html after" );
 });
 
-asyncTest( "load", function() {
-       expect( 21 );
+if ( $.uiBackCompat === false ) {
+       asyncTest( "load", function() {
+               expect( 21 );
 
-       var tab, panelId, panel,
-               element = $( "#tabs2" );
-
-       // init
-       element.one( "tabsload", function( event, ui ) {
-               tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
-               panelId = tab.attr( "aria-controls" );
-               panel = $( "#" + panelId );
-
-               ok( !( "originalEvent" in event ), "originalEvent" );
-               equals( ui.tab.size(), 1, "tab size" );
-               strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
-               equals( ui.panel.size(), 1, "panel size" );
-               strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
-               equals( ui.panel.find( "p" ).length, 1, "panel html" );
-               tabs_state( element, 0, 0, 1, 0, 0 );
-               tabsload1();
-       });
-       element.tabs({ active: 2 });
+               var tab, panelId, panel,
+                       element = $( "#tabs2" );
 
-       function tabsload1() {
-               // .option()
+               // init
                element.one( "tabsload", function( event, ui ) {
-                       tab = element.find( ".ui-tabs-nav a" ).eq( 3 );
+                       tab = element.find( ".ui-tabs-nav a" ).eq( 2 );
                        panelId = tab.attr( "aria-controls" );
                        panel = $( "#" + panelId );
-
+       
                        ok( !( "originalEvent" in event ), "originalEvent" );
                        equals( ui.tab.size(), 1, "tab size" );
                        strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
                        equals( ui.panel.size(), 1, "panel size" );
                        strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
                        equals( ui.panel.find( "p" ).length, 1, "panel html" );
-                       tabs_state( element, 0, 0, 0, 1, 0 );
-                       tabsload2();
+                       tabs_state( element, 0, 0, 1, 0, 0 );
+                       tabsload1();
                });
-               element.tabs( "option", "active", 3 );
-       }
+               element.tabs({ active: 2 });
 
-       function tabsload2() {
-               // click, change panel content
-               element.one( "tabsload", function( event, ui ) {
-                       tab = element.find( ".ui-tabs-nav a" ).eq( 4 );
-                       panelId = tab.attr( "aria-controls" );
-                       panel = $( "#" + panelId );
+               function tabsload1() {
+                       // .option()
+                       element.one( "tabsload", function( event, ui ) {
+                               tab = element.find( ".ui-tabs-nav a" ).eq( 3 );
+                               panelId = tab.attr( "aria-controls" );
+                               panel = $( "#" + panelId );
 
-                       equals( event.originalEvent.type, "click", "originalEvent" );
-                       equals( ui.tab.size(), 1, "tab size" );
-                       strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
-                       equals( ui.panel.size(), 1, "panel size" );
-                       strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
-                       equals( ui.panel.find( "p" ).length, 1, "panel html" );
-                       tabs_state( element, 0, 0, 0, 0, 1 );
-                       start();
-               });
-               element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
-       }
-});
+                               ok( !( "originalEvent" in event ), "originalEvent" );
+                               equals( ui.tab.size(), 1, "tab size" );
+                               strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+                               equals( ui.panel.size(), 1, "panel size" );
+                               strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+                               equals( ui.panel.find( "p" ).length, 1, "panel html" );
+                               tabs_state( element, 0, 0, 0, 1, 0 );
+                               tabsload2();
+                       });
+                       element.tabs( "option", "active", 3 );
+               }
+
+               function tabsload2() {
+                       // click, change panel content
+                       element.one( "tabsload", function( event, ui ) {
+                               tab = element.find( ".ui-tabs-nav a" ).eq( 4 );
+                               panelId = tab.attr( "aria-controls" );
+                               panel = $( "#" + panelId );
+
+                               equals( event.originalEvent.type, "click", "originalEvent" );
+                               equals( ui.tab.size(), 1, "tab size" );
+                               strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
+                               equals( ui.panel.size(), 1, "panel size" );
+                               strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+                               equals( ui.panel.find( "p" ).length, 1, "panel html" );
+                               tabs_state( element, 0, 0, 0, 0, 1 );
+                               start();
+                       });
+                       element.find( ".ui-tabs-nav a" ).eq( 4 ).click();
+               }
+       });
+}
 
 }( jQuery ) );
index 5cf917550e5b473c7fba56aff03edfb6bcf5a70e..ec21e2de79059b663adc0af35668790b130d16dc 100644 (file)
@@ -165,16 +165,20 @@ asyncTest( "load", function() {
                tabs_state( element, 1, 0, 0, 0, 0 );
        });
        element.one( "tabsload", function( event, ui ) {
+               // TODO: remove wrapping in 2.0
+               var uiTab = $( ui.tab ),
+                       uiPanel = $( ui.panel );
+
                var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
                        panelId = tab.attr( "aria-controls" ),
                        panel = $( "#" + panelId );
                
                ok( !( "originalEvent" in event ), "originalEvent" );
-               equals( ui.tab.size(), 1, "tab size" );
-               strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
-               equals( ui.panel.size(), 1, "panel size" );
-               strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
-               equals( ui.panel.find( "p" ).length, 1, "panel html" );
+               equals( uiTab.size(), 1, "tab size" );
+               strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
+               equals( uiPanel.size(), 1, "panel size" );
+               strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
+               equals( uiPanel.find( "p" ).length, 1, "panel html" );
                tabs_state( element, 1, 0, 0, 0, 0 );
                setTimeout( tabsload1, 1 );
        });
@@ -209,15 +213,19 @@ asyncTest( "load", function() {
                        tabs_state( element, 0, 0, 0, 1, 0 );
                });
                element.one( "tabsload", function( event, ui ) {
+                       // TODO: remove wrapping in 2.0
+                       var uiTab = $( ui.tab ),
+                               uiPanel = $( ui.panel );
+
                        var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
                                panelId = tab.attr( "aria-controls" ),
                                panel = $( "#" + panelId );
                        
                        ok( !( "originalEvent" in event ), "originalEvent" );
-                       equals( ui.tab.size(), 1, "tab size" );
-                       strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" );
-                       equals( ui.panel.size(), 1, "panel size" );
-                       strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" );
+                       equals( uiTab.size(), 1, "tab size" );
+                       strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" );
+                       equals( uiPanel.size(), 1, "panel size" );
+                       strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" );
                        tabs_state( element, 0, 0, 0, 1, 0 );
                        start();
                });
index 84d623f62b0be52315c2bfeb20c55ea0ad7cd39a..b20cd9a2617ab26f2e53fb591a0aadef41627f9b 100644 (file)
@@ -1009,6 +1009,18 @@ if ( $.uiBackCompat !== false ) {
                        }
                }
        });
+
+       // load event
+       $.widget( "ui.tabs", $.ui.tabs, {
+               _trigger: function( type, event, data ) {
+                       var _data = $.extend( {}, data );
+                       if ( type === "load" ) {
+                               _data.panel = _data.panel[ 0 ];
+                               _data.tab = _data.tab[ 0 ];
+                       }
+                       return this._super( "_trigger", type, event, _data );
+               }
+       });
 }
 
 })( jQuery );