aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.tabs.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/jquery.ui.tabs.js')
-rw-r--r--ui/jquery.ui.tabs.js87
1 files changed, 44 insertions, 43 deletions
diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js
index 62bab2d9f..5eaab1aae 100644
--- a/ui/jquery.ui.tabs.js
+++ b/ui/jquery.ui.tabs.js
@@ -18,6 +18,19 @@ function getNextTabId() {
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( false );
+ return anchor.hash.length > 1 &&
+ anchor.href.replace( rhash, "" ) === currentPage;
+ };
+})();
+
$.widget( "ui.tabs", {
version: "@VERSION",
options: {
@@ -197,8 +210,7 @@ $.widget( "ui.tabs", {
},
_processTabs: function() {
- var self = this,
- fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
+ var self = this;
this.list = this.element.find( "ol,ul" ).eq( 0 );
this.lis = $( " > li:has(a[href])", this.list );
@@ -208,30 +220,14 @@ $.widget( "ui.tabs", {
this.panels = $( [] );
this.anchors.each(function( i, a ) {
- var href = $( a ).attr( "href" ),
- 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;
- }
+ var selector, panel;
// inline tab
- if ( fragmentId.test( href ) ) {
- selector = href;
+ if ( isLocal( a ) ) {
+ selector = a.hash;
panel = self.element.find( self._sanitizeSelector( selector ) );
// remote tab
- // prevent loading the page itself if href is just "#"
- } else if ( href && href !== "#" ) {
+ } else {
var id = self._tabId( a );
selector = "#" + id;
panel = self.element.find( selector );
@@ -239,9 +235,6 @@ $.widget( "ui.tabs", {
panel = self._createPanel( id );
panel.insertAfter( self.panels[ i - 1 ] || self.list );
}
- // invalid tab href
- } else {
- self.options.disabled.push( i );
}
if ( panel.length) {
@@ -525,21 +518,18 @@ $.widget( "ui.tabs", {
options = this.options,
anchor = this.anchors.eq( index ),
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 = {
tab: anchor,
panel: panel
};
// not remote
- if ( !url ) {
+ if ( isLocal( anchor[ 0 ] ) ) {
return;
}
this.xhr = $.ajax({
- url: url,
+ url: anchor.attr( "href" ),
beforeSend: function( jqXHR, settings ) {
return self._trigger( "beforeLoad", event,
$.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
@@ -551,19 +541,27 @@ $.widget( "ui.tabs", {
this.xhr
.success(function( response ) {
- panel.html( response );
- self._trigger( "load", event, eventData );
+ // TODO: IE resolves cached XHRs immediately
+ // remove when core #10467 is fixed
+ setTimeout(function() {
+ panel.html( response );
+ self._trigger( "load", event, eventData );
+ }, 1 );
})
.complete(function( jqXHR, status ) {
- if ( status === "abort" ) {
- self.panels.stop( false, true );
- }
-
- self.lis.eq( index ).removeClass( "ui-tabs-loading" );
-
- if ( jqXHR === self.xhr ) {
- delete self.xhr;
- }
+ // TODO: IE resolves cached XHRs immediately
+ // remove when core #10467 is fixed
+ setTimeout(function() {
+ if ( status === "abort" ) {
+ self.panels.stop( false, true );
+ }
+
+ self.lis.eq( index ).removeClass( "ui-tabs-loading" );
+
+ if ( jqXHR === self.xhr ) {
+ delete self.xhr;
+ }
+ }, 1 );
});
}
@@ -802,11 +800,14 @@ if ( $.uiBackCompat !== false ) {
index = this._getIndex( index );
var options = this.options,
tab = this.lis.eq( index ).remove(),
- panel = this.panels.eq( index ).remove();
+ panel = this._getPanelForTab( tab.find( "a[aria-controls]" ) ).remove();
// If selected tab was removed focus tab to the right or
// in case the last tab was removed the tab to the left.
- if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 1) {
+ // We check for more than 2 tabs, because if there are only 2,
+ // then when we remove this tab, there will only be one tab left
+ // so we don't need to detect which tab to activate.
+ if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 2 ) {
this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
}