mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Tabs: Use .uniqueId() for panels and moved isLocal() into the widget prototype.
This commit is contained in:
parent
604e0949e3
commit
ecd4f95a50
@ -67,7 +67,7 @@ test( "aria-controls", function() {
|
|||||||
tabs = element.find( ".ui-tabs-nav li" );
|
tabs = element.find( ".ui-tabs-nav li" );
|
||||||
equal( tabs.eq( 0 ).attr( "aria-controls" ), "colon:test" );
|
equal( tabs.eq( 0 ).attr( "aria-controls" ), "colon:test" );
|
||||||
equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" );
|
equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" );
|
||||||
ok( /^ui-tabs-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" );
|
ok( /^ui-id-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" );
|
||||||
equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" );
|
equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
47
ui/jquery.ui.tabs.js
vendored
47
ui/jquery.ui.tabs.js
vendored
@ -14,23 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
(function( $, undefined ) {
|
(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", {
|
$.widget( "ui.tabs", {
|
||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
delay: 300,
|
delay: 300,
|
||||||
@ -49,6 +32,21 @@ $.widget( "ui.tabs", {
|
|||||||
load: null
|
load: null
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isLocal: (function() {
|
||||||
|
var rhash = /#.*$/;
|
||||||
|
|
||||||
|
return function( 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, "" ) );
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
|
||||||
_create: function() {
|
_create: function() {
|
||||||
var that = this,
|
var that = this,
|
||||||
options = this.options;
|
options = this.options;
|
||||||
@ -296,10 +294,6 @@ $.widget( "ui.tabs", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_tabId: function( tab ) {
|
|
||||||
return tab.attr( "aria-controls" ) || "ui-tabs-" + getNextTabId();
|
|
||||||
},
|
|
||||||
|
|
||||||
_sanitizeSelector: function( hash ) {
|
_sanitizeSelector: function( hash ) {
|
||||||
return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
|
return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
|
||||||
},
|
},
|
||||||
@ -406,12 +400,15 @@ $.widget( "ui.tabs", {
|
|||||||
originalAriaControls = tab.attr( "aria-controls" );
|
originalAriaControls = tab.attr( "aria-controls" );
|
||||||
|
|
||||||
// inline tab
|
// inline tab
|
||||||
if ( isLocal( anchor ) ) {
|
if ( that._isLocal( anchor ) ) {
|
||||||
selector = anchor.hash;
|
selector = anchor.hash;
|
||||||
|
panelId = selector.substring( 1 );
|
||||||
panel = that.element.find( that._sanitizeSelector( selector ) );
|
panel = that.element.find( that._sanitizeSelector( selector ) );
|
||||||
// remote tab
|
// remote tab
|
||||||
} else {
|
} 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;
|
selector = "#" + panelId;
|
||||||
panel = that.element.find( selector );
|
panel = that.element.find( selector );
|
||||||
if ( !panel.length ) {
|
if ( !panel.length ) {
|
||||||
@ -428,7 +425,7 @@ $.widget( "ui.tabs", {
|
|||||||
tab.data( "ui-tabs-aria-controls", originalAriaControls );
|
tab.data( "ui-tabs-aria-controls", originalAriaControls );
|
||||||
}
|
}
|
||||||
tab.attr({
|
tab.attr({
|
||||||
"aria-controls": selector.substring( 1 ),
|
"aria-controls": panelId,
|
||||||
"aria-labelledby": anchorId
|
"aria-labelledby": anchorId
|
||||||
});
|
});
|
||||||
panel.attr( "aria-labelledby", anchorId );
|
panel.attr( "aria-labelledby", anchorId );
|
||||||
@ -790,7 +787,7 @@ $.widget( "ui.tabs", {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// not remote
|
// not remote
|
||||||
if ( isLocal( anchor[ 0 ] ) ) {
|
if ( this._isLocal( anchor[ 0 ] ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user