mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Tabs: Set ajaxOptions in intial $.ajax() call. Fixes #8504 - Ajax in Tabs not passing data in 1.9. beta 1.
This commit is contained in:
parent
536d112aa9
commit
af67883226
@ -25,10 +25,11 @@ test( "panel ids", function() {
|
|||||||
module( "tabs (deprecated): options" );
|
module( "tabs (deprecated): options" );
|
||||||
|
|
||||||
asyncTest( "ajaxOptions", function() {
|
asyncTest( "ajaxOptions", function() {
|
||||||
expect( 1 );
|
expect( 2 );
|
||||||
|
|
||||||
var element = $( "#tabs2" ).tabs({
|
var element = $( "#tabs2" ).tabs({
|
||||||
ajaxOptions: {
|
ajaxOptions: {
|
||||||
|
data: "foo=bar",
|
||||||
converters: {
|
converters: {
|
||||||
"text html": function() {
|
"text html": function() {
|
||||||
return "test";
|
return "test";
|
||||||
@ -36,6 +37,9 @@ asyncTest( "ajaxOptions", function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
element.one( "tabsbeforeload", function( event, ui ) {
|
||||||
|
equal( ui.ajaxSettings.url.replace( /^[^\?]+/, "" ), "?foo=bar", "ajaxOptions.data" );
|
||||||
|
});
|
||||||
element.one( "tabsload", function( event, ui ) {
|
element.one( "tabsload", function( event, ui ) {
|
||||||
equal( $( ui.panel ).html(), "test" );
|
equal( $( ui.panel ).html(), "test" );
|
||||||
start();
|
start();
|
||||||
|
51
ui/jquery.ui.tabs.js
vendored
51
ui/jquery.ui.tabs.js
vendored
@ -792,13 +792,7 @@ $.widget( "ui.tabs", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.xhr = $.ajax({
|
this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );
|
||||||
url: anchor.attr( "href" ),
|
|
||||||
beforeSend: function( jqXHR, settings ) {
|
|
||||||
return that._trigger( "beforeLoad", event,
|
|
||||||
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// support: jQuery <1.8
|
// support: jQuery <1.8
|
||||||
// jQuery <1.8 returns false if the request is canceled in beforeSend,
|
// jQuery <1.8 returns false if the request is canceled in beforeSend,
|
||||||
@ -835,6 +829,18 @@ $.widget( "ui.tabs", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// TODO: Remove this function in 1.10 when ajaxOptions is removed
|
||||||
|
_ajaxSettings: function( anchor, event, eventData ) {
|
||||||
|
var that = this;
|
||||||
|
return {
|
||||||
|
url: anchor.attr( "href" ),
|
||||||
|
beforeSend: function( jqXHR, settings ) {
|
||||||
|
return that._trigger( "beforeLoad", event,
|
||||||
|
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
_getPanelForTab: function( tab ) {
|
_getPanelForTab: function( tab ) {
|
||||||
var id = $( tab ).attr( "aria-controls" );
|
var id = $( tab ).attr( "aria-controls" );
|
||||||
return this.element.find( this._sanitizeSelector( "#" + id ) );
|
return this.element.find( this._sanitizeSelector( "#" + id ) );
|
||||||
@ -860,6 +866,7 @@ if ( $.uiBackCompat !== false ) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: Remove _ajaxSettings() method when removing this extension
|
||||||
// ajaxOptions and cache options
|
// ajaxOptions and cache options
|
||||||
$.widget( "ui.tabs", $.ui.tabs, {
|
$.widget( "ui.tabs", $.ui.tabs, {
|
||||||
options: {
|
options: {
|
||||||
@ -879,19 +886,6 @@ if ( $.uiBackCompat !== false ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.extend( ui.ajaxSettings, that.options.ajaxOptions, {
|
|
||||||
error: function( xhr, s, e ) {
|
|
||||||
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)
|
|
||||||
that.options.ajaxOptions.error( xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
|
|
||||||
}
|
|
||||||
catch ( e ) {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.jqXHR.success(function() {
|
ui.jqXHR.success(function() {
|
||||||
if ( that.options.cache ) {
|
if ( that.options.cache ) {
|
||||||
$.data( ui.tab[ 0 ], "cache.tabs", true );
|
$.data( ui.tab[ 0 ], "cache.tabs", true );
|
||||||
@ -900,6 +894,23 @@ if ( $.uiBackCompat !== false ) {
|
|||||||
}});
|
}});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_ajaxSettings: function( anchor, event, ui ) {
|
||||||
|
var ajaxOptions = this.options.ajaxOptions;
|
||||||
|
return $.extend( {}, ajaxOptions, {
|
||||||
|
error: function( xhr, s, e ) {
|
||||||
|
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, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
|
||||||
|
}
|
||||||
|
catch ( e ) {}
|
||||||
|
}
|
||||||
|
}, this._superApply( arguments ) );
|
||||||
|
},
|
||||||
|
|
||||||
_setOption: function( key, value ) {
|
_setOption: function( key, value ) {
|
||||||
// reset cache if switching from cached to not cached
|
// reset cache if switching from cached to not cached
|
||||||
if ( key === "cache" && value === false ) {
|
if ( key === "cache" && value === false ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user