]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Refactored spinner implementation. Fixes #7134 - Tabs: Deprecate spinner option.
authorScott González <scott.gonzalez@gmail.com>
Mon, 9 May 2011 16:52:00 +0000 (12:52 -0400)
committerScott González <scott.gonzalez@gmail.com>
Mon, 9 May 2011 16:52:00 +0000 (12:52 -0400)
tests/unit/tabs/tabs_deprecated.js
ui/jquery.ui.tabs.js

index 8d63409a802cb2622188934730222160e87563e8..0094bc4f79e19f8964df75f1e4d8d0cee21d2c88 100644 (file)
@@ -106,34 +106,19 @@ test('cookie', function() {
 
 });
 
+asyncTest( "spinner", function() {
+       expect( 2 );
 
-test('spinner', function() {
-       expect(4);
-       stop();
-
-       el = $('#tabs2');
-
-       el.tabs({
-               selected: 2,
-               load: function() {
-                       // spinner: default spinner
-                       setTimeout(function() {
-                               equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed");
-                               equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed");
-                               el.tabs('destroy');
-                               el.tabs({
-                                       selected: 2,
-                                       spinner: '<img src="spinner.gif" alt="">',
-                                       load: function() {
-                                               // spinner: image
-                                               equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed");
-                                               equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed");
-                                               start();
-                                       }
-                               });
-                       }, 1);
-               }
+       var element = $( "#tabs2" ).tabs();
+
+       element.one( "tabsbeforeload", function( event, ui ) {
+               equals( element.find( ".ui-tabs-nav li:eq(2) em" ).length, 1, "beforeload" );
+       });
+       element.one( "tabsload", function( event, ui ) {
+               equals( element.find( ".ui-tabs-nav li:eq(2) em" ).length, 0, "load" );
+               start();
        });
+       element.tabs( "option", "active", 2 );
 });
 
 test( "selected", function() {
index 58c181670ba02ac75d5445c6ce87436b6c21fb2e..f0661b3add386e4916a7ea56fb469efdb86e9917 100644 (file)
@@ -743,34 +743,28 @@ if ( $.uiBackCompat !== false ) {
        }( jQuery, jQuery.ui.tabs.prototype ) );
 
        // spinner
-       (function( $, prototype ) {
-               $.extend( prototype.options, {
+       $.widget( "ui.tabs", $.ui.tabs, {
+               options: {
                        spinner: "<em>Loading&#8230;</em>"
-               });
-
-               var _create = prototype._create;
-               prototype._create = function() {
-                       _create.call( this );
-                       var self = this;
-
-                       this.element.bind( "tabsbeforeload", function( event, ui ) {
-                               if ( self.options.spinner ) {
-                                       var span = $( "span", ui.tab );
-                                       if ( span.length ) {
-                                               span.data( "label.tabs", span.html() ).html( self.options.spinner );
+               },
+               _create: function() {
+                       this._super( "_create" );
+                       this._bind({
+                               tabsbeforeload: function( event, ui ) {
+                                       if ( !this.options.spinner ) {
+                                               return;
                                        }
+       
+                                       var span = ui.tab.find( "span" ),
+                                               html = span.html();
+                                       span.html( this.options.spinner );
+                                       ui.jqXHR.complete(function() {
+                                               span.html( html );
+                                       });
                                }
-                               ui.jqXHR.complete( function() {
-                                       if ( self.options.spinner ) {
-                                               var span = $( "span", ui.tab );
-                                               if ( span.length ) {
-                                                       span.html( span.data( "label.tabs" ) ).removeData( "label.tabs" );
-                                               }
-                                       }
-                               });
                        });
-               };
-       }( jQuery, jQuery.ui.tabs.prototype ) );
+               }
+       });
 
        // enable/disable events
        (function( $, prototype ) {