el.tabs('destroy');
});
-test('ajax', 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);
- }
- });
-
-});
-
})(jQuery);
remove: null,
select: null,
show: null,
- spinner: "<em>Loading…</em>",
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
};
ok(false, "missing test - untested code is broken code.");
});
+module("tabs (deprecated): spinner");
+
+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);
+ }
+ });
+});
+
}( jQuery ) );
equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if value is same as selected');
});
-test('spinner', function() {
- ok(false, "missing test - untested code is broken code.");
-});
-
test('tabTemplate', function() {
ok(false, "missing test - untested code is broken code.");
});
remove: null,
select: null,
show: null,
- spinner: "<em>Loading…</em>",
tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
},
};
},
- _cleanup: function() {
- // restore all former loading tabs labels
- this.lis.filter( ".ui-state-processing" )
- .removeClass( "ui-state-processing" )
- .find( "span:data(label.tabs)" )
- .each(function() {
- var el = $( this );
- el.html( el.data( "label.tabs" ) ).removeData( "label.tabs" );
- });
- },
-
_tabify: function( init ) {
var self = this,
o = this.options,
// load remote from here on
this.lis.eq( index ).addClass( "ui-state-processing" );
- if ( o.spinner ) {
- var span = $( "span", a );
- span.data( "label.tabs", span.html() ).html( o.spinner );
- }
-
this.xhr
.success( function( response ) {
self.element.find( self._sanitizeSelector( a.hash ) ).html( response );
delete this.xhr;
}
- // take care of tab labels
- self._cleanup();
+
+ self.lis.eq( index ).removeClass( "ui-state-processing" );
self._trigger( "load", null, eventData );
});
}
};
}( jQuery, jQuery.ui.tabs.prototype ) );
+
+ // spinner
+ (function( $, prototype ) {
+ $.extend( prototype.options, {
+ spinner: "<em>Loading…</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 );
+ }
+ }
+ 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 ) );
}
})( jQuery );