module( "tabs (deprecated): options" );
-asyncTest( "ajaxOptions", function() {
- expect( 2 );
-
- var element = $( "#tabs2" ).tabs({
- ajaxOptions: {
- data: "foo=bar",
- converters: {
- "text html": function() {
- return "test";
- }
- }
- }
- });
- element.one( "tabsbeforeload", function( event, ui ) {
- equal( ui.ajaxSettings.url.replace( /^[^\?]+/, "" ), "?foo=bar", "ajaxOptions.data" );
- });
- element.one( "tabsload", function( event, ui ) {
- equal( $( ui.panel ).html(), "test" );
- start();
- });
- element.tabs( "option", "active", 2 );
-});
-
-asyncTest( "cache", function() {
- expect( 5 );
-
- var element = $( "#tabs2" ).tabs({
- cache: true
- });
- element.one( "tabsshow", function() {
- state( element, 0, 0, 1, 0, 0 );
- });
- element.one( "tabsload", function() {
- ok( true, "tabsload" );
-
- setTimeout(function() {
- element.tabs( "option", "active", 0 );
- state( element, 1, 0, 0, 0, 0 );
-
- element.one( "tabsshow", function() {
- state( element, 0, 0, 1, 0, 0 );
- });
- element.one( "tabsload", function() {
- ok( false, "should be cached" );
- });
- element.tabs( "option", "active", 2 );
- start();
- }, 1 );
- });
- element.tabs( "option", "active", 2 );
- state( element, 0, 0, 1, 0, 0 );
-});
-
test( "idPrefix", function() {
expect( 1 );
}
},
- // TODO: Remove this function in 1.10 when ajaxOptions is removed
_ajaxSettings: function( anchor, event, eventData ) {
var that = this;
return {
}
});
- // TODO: Remove _ajaxSettings() method when removing this extension
- // ajaxOptions and cache options
- $.widget( "ui.tabs", $.ui.tabs, {
- options: {
- ajaxOptions: null,
- cache: false
- },
-
- _create: function() {
- this._super();
-
- var that = this;
-
- this._on({ tabsbeforeload: function( event, ui ) {
- // tab is already cached
- if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) {
- event.preventDefault();
- return;
- }
-
- ui.jqXHR.success(function() {
- if ( that.options.cache ) {
- $.data( ui.tab[ 0 ], "cache.tabs", true );
- }
- });
- }});
- },
-
- _ajaxSettings: function( anchor, event, ui ) {
- var ajaxOptions = this.options.ajaxOptions;
- return $.extend( {}, ajaxOptions, {
- error: function( xhr, status ) {
- try {
- // Passing index avoid a race condition when this method is
- // called after the user has selected another tab.
- // Pass the anchor that initiated this request allows
- // loadError to manipulate the tab content panel via $(a.hash)
- ajaxOptions.error(
- xhr, status, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
- }
- catch ( error ) {}
- }
- }, this._superApply( arguments ) );
- },
-
- _setOption: function( key, value ) {
- // reset cache if switching from cached to not cached
- if ( key === "cache" && value === false ) {
- this.anchors.removeData( "cache.tabs" );
- }
- this._super( key, value );
- },
-
- _destroy: function() {
- this.anchors.removeData( "cache.tabs" );
- this._super();
- },
-
- url: function( index ){
- this.anchors.eq( index ).removeData( "cache.tabs" );
- this._superApply( arguments );
- }
- });
-
// abort method
$.widget( "ui.tabs", $.ui.tabs, {
abort: function() {