mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Tabs: Fixed detection of local vs. remote tabs. Fixes #4941 - Mishandling of base tag. Fixes #4836 - Self refering href only partially detected.
This commit is contained in:
parent
ac04462d22
commit
18a3b53988
@ -48,7 +48,7 @@ test( "aria-controls", function() {
|
|||||||
tabs = element.find( ".ui-tabs-nav a" );
|
tabs = element.find( ".ui-tabs-nav a" );
|
||||||
tabs.each(function() {
|
tabs.each(function() {
|
||||||
var tab = $( this );
|
var tab = $( this );
|
||||||
equal( tab.attr( "href" ).substring( 1 ), tab.attr( "aria-controls" ) );
|
equal( tab.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) );
|
||||||
});
|
});
|
||||||
|
|
||||||
element = $( "#tabs2" ).tabs();
|
element = $( "#tabs2" ).tabs();
|
||||||
|
50
ui/jquery.ui.tabs.js
vendored
50
ui/jquery.ui.tabs.js
vendored
@ -18,6 +18,19 @@ function getNextTabId() {
|
|||||||
return ++tabId;
|
return ++tabId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isLocal = (function() {
|
||||||
|
var rhash = /#.*$/,
|
||||||
|
currentPage = location.href.replace( rhash, "" );
|
||||||
|
|
||||||
|
return function( anchor ) {
|
||||||
|
// clone the node to work around IE 6 not normalizing the href property
|
||||||
|
// if it's manually set, i.e., a.href = "#foo" kills the normalization
|
||||||
|
anchor = anchor.cloneNode();
|
||||||
|
return anchor.hash.length > 1 &&
|
||||||
|
anchor.href.replace( rhash, "" ) === currentPage;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
$.widget( "ui.tabs", {
|
$.widget( "ui.tabs", {
|
||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
options: {
|
options: {
|
||||||
@ -197,8 +210,7 @@ $.widget( "ui.tabs", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_processTabs: function() {
|
_processTabs: function() {
|
||||||
var self = this,
|
var self = this;
|
||||||
fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
|
|
||||||
|
|
||||||
this.list = this.element.find( "ol,ul" ).eq( 0 );
|
this.list = this.element.find( "ol,ul" ).eq( 0 );
|
||||||
this.lis = $( " > li:has(a[href])", this.list );
|
this.lis = $( " > li:has(a[href])", this.list );
|
||||||
@ -208,30 +220,14 @@ $.widget( "ui.tabs", {
|
|||||||
this.panels = $( [] );
|
this.panels = $( [] );
|
||||||
|
|
||||||
this.anchors.each(function( i, a ) {
|
this.anchors.each(function( i, a ) {
|
||||||
var href = $( a ).attr( "href" ),
|
var selector, panel;
|
||||||
hrefBase = href.split( "#" )[ 0 ],
|
|
||||||
selector,
|
|
||||||
panel,
|
|
||||||
baseEl;
|
|
||||||
|
|
||||||
// For dynamically created HTML that contains a hash as href IE < 8 expands
|
|
||||||
// such href to the full page url with hash and then misinterprets tab as ajax.
|
|
||||||
// Same consideration applies for an added tab with a fragment identifier
|
|
||||||
// since a[href=#fragment-identifier] does unexpectedly not match.
|
|
||||||
// Thus normalize href attribute...
|
|
||||||
if ( hrefBase && ( hrefBase === location.toString().split( "#" )[ 0 ] ||
|
|
||||||
( baseEl = $( "base" )[ 0 ]) && hrefBase === baseEl.href ) ) {
|
|
||||||
href = a.hash;
|
|
||||||
a.href = href;
|
|
||||||
}
|
|
||||||
|
|
||||||
// inline tab
|
// inline tab
|
||||||
if ( fragmentId.test( href ) ) {
|
if ( isLocal( a ) ) {
|
||||||
selector = href;
|
selector = a.hash;
|
||||||
panel = self.element.find( self._sanitizeSelector( selector ) );
|
panel = self.element.find( self._sanitizeSelector( selector ) );
|
||||||
// remote tab
|
// remote tab
|
||||||
// prevent loading the page itself if href is just "#"
|
} else {
|
||||||
} else if ( href && href !== "#" ) {
|
|
||||||
var id = self._tabId( a );
|
var id = self._tabId( a );
|
||||||
selector = "#" + id;
|
selector = "#" + id;
|
||||||
panel = self.element.find( selector );
|
panel = self.element.find( selector );
|
||||||
@ -239,9 +235,6 @@ $.widget( "ui.tabs", {
|
|||||||
panel = self._createPanel( id );
|
panel = self._createPanel( id );
|
||||||
panel.insertAfter( self.panels[ i - 1 ] || self.list );
|
panel.insertAfter( self.panels[ i - 1 ] || self.list );
|
||||||
}
|
}
|
||||||
// invalid tab href
|
|
||||||
} else {
|
|
||||||
self.options.disabled.push( i );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( panel.length) {
|
if ( panel.length) {
|
||||||
@ -525,21 +518,18 @@ $.widget( "ui.tabs", {
|
|||||||
options = this.options,
|
options = this.options,
|
||||||
anchor = this.anchors.eq( index ),
|
anchor = this.anchors.eq( index ),
|
||||||
panel = self._getPanelForTab( anchor ),
|
panel = self._getPanelForTab( anchor ),
|
||||||
// TODO until #3808 is fixed strip fragment identifier from url
|
|
||||||
// (IE fails to load from such url)
|
|
||||||
url = anchor.attr( "href" ).replace( /#.*$/, "" ),
|
|
||||||
eventData = {
|
eventData = {
|
||||||
tab: anchor,
|
tab: anchor,
|
||||||
panel: panel
|
panel: panel
|
||||||
};
|
};
|
||||||
|
|
||||||
// not remote
|
// not remote
|
||||||
if ( !url ) {
|
if ( isLocal( anchor[ 0 ] ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.xhr = $.ajax({
|
this.xhr = $.ajax({
|
||||||
url: url,
|
url: anchor.attr( "href" ),
|
||||||
beforeSend: function( jqXHR, settings ) {
|
beforeSend: function( jqXHR, settings ) {
|
||||||
return self._trigger( "beforeLoad", event,
|
return self._trigger( "beforeLoad", event,
|
||||||
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
|
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user