diff options
Diffstat (limited to 'ui/jquery.ui.tabs.js')
-rw-r--r-- | ui/jquery.ui.tabs.js | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 4077c9ac5..25395b8fc 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -14,23 +14,6 @@ */ (function( $, undefined ) { -var tabId = 0, - rhash = /#.*$/; - -function getNextTabId() { - return ++tabId; -} - -function isLocal( anchor ) { - // support: IE7 - // IE7 doesn't normalize the href property when set via script (#9317) - anchor = anchor.cloneNode( false ); - - return anchor.hash.length > 1 && - decodeURIComponent( anchor.href.replace( rhash, "" ) ) === - decodeURIComponent( location.href.replace( rhash, "" ) ); -} - $.widget( "ui.tabs", { version: "@VERSION", delay: 300, @@ -49,6 +32,31 @@ $.widget( "ui.tabs", { load: null }, + _isLocal: (function() { + var rhash = /#.*$/; + + return function( anchor ) { + var anchorUrl, locationUrl; + + // support: IE7 + // IE7 doesn't normalize the href property when set via script (#9317) + anchor = anchor.cloneNode( false ); + + anchorUrl = anchor.href.replace( rhash, "" ); + locationUrl = location.href.replace( rhash, "" ); + + // decoding may throw an error if the URL isn't UTF-8 (#9518) + try { + anchorUrl = decodeURIComponent( anchorUrl ); + } catch ( error ) {} + try { + locationUrl = decodeURIComponent( locationUrl ); + } catch ( error ) {} + + return anchor.hash.length > 1 && anchorUrl === locationUrl; + }; + })(), + _create: function() { var that = this, options = this.options; @@ -296,10 +304,6 @@ $.widget( "ui.tabs", { } }, - _tabId: function( tab ) { - return tab.attr( "aria-controls" ) || "ui-tabs-" + getNextTabId(); - }, - _sanitizeSelector: function( hash ) { return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : ""; }, @@ -406,12 +410,15 @@ $.widget( "ui.tabs", { originalAriaControls = tab.attr( "aria-controls" ); // inline tab - if ( isLocal( anchor ) ) { + if ( that._isLocal( anchor ) ) { selector = anchor.hash; + panelId = selector.substring( 1 ); panel = that.element.find( that._sanitizeSelector( selector ) ); // remote tab } else { - panelId = that._tabId( tab ); + // If the tab doesn't already have aria-controls, + // generate an id by using a throw-away element + panelId = tab.attr( "aria-controls" ) || $( {} ).uniqueId()[ 0 ].id; selector = "#" + panelId; panel = that.element.find( selector ); if ( !panel.length ) { @@ -428,7 +435,7 @@ $.widget( "ui.tabs", { tab.data( "ui-tabs-aria-controls", originalAriaControls ); } tab.attr({ - "aria-controls": selector.substring( 1 ), + "aria-controls": panelId, "aria-labelledby": anchorId }); panel.attr( "aria-labelledby", anchorId ); @@ -790,7 +797,7 @@ $.widget( "ui.tabs", { }; // not remote - if ( isLocal( anchor[ 0 ] ) ) { + if ( this._isLocal( anchor[ 0 ] ) ) { return; } |