Skip to content

Commit bc6a28e

Browse files
committed
Tabs: Cleaned up _tabId() implementation.
1 parent 168ab66 commit bc6a28e

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

tests/unit/tabs/tabs_deprecated.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
module("tabs (deprecated): core");
44

5-
test( "#4581 - title attribute for remote tabs does not support foreign languages", function() {
6-
expect( 1 );
7-
8-
$( "#tabs2" ).tabs({
9-
selected: 3,
10-
beforeLoad: function( event, ui ) {
11-
event.preventDefault();
12-
equal( ui.panel.attr( "id" ), "∫ßáö_Սե", "proper title" );
13-
}
5+
test( "panel ids", function() {
6+
expect( 2 );
7+
8+
var element = $( "#tabs2" ).tabs();
9+
10+
element.one( "tabsbeforeload", function( event, ui ) {
11+
equal( ui.panel.attr( "id" ), "∫ßáö_Սե", "from title attribute" );
12+
event.preventDefault();
13+
});
14+
element.tabs( "option", "active", 3 );
15+
16+
element.one( "tabsbeforeload", function( event, ui ) {
17+
ok( /^ui-tabs-\d+$/.test( ui.panel.attr( "id" ) ), "generated id" );
18+
event.preventDefault();
1419
});
20+
element.tabs( "option", "active", 2 );
1521
});
1622

1723
module("tabs (deprecated): options");
@@ -326,14 +332,19 @@ test( "length", function() {
326332
equals( $( "#tabs2" ).tabs().tabs( "length" ), 4, "ajax tabs with missing panels" );
327333
});
328334

329-
test('url', function() {
330-
el = $('#tabs2').tabs();
331-
var tab = el.find('a:eq(3)'),
332-
url = tab.attr('href');
335+
test( "url", function() {
336+
expect( 2 );
333337

334-
el.tabs('url', 3, "data/test2.html");
335-
equals(tab.attr('href'), 'data/test2.html', 'Url was updated');
336-
tab.attr('href', url );
338+
var element = $( "#tabs2" ).tabs(),
339+
tab = element.find( "a" ).eq( 3 );
340+
341+
element.tabs( "url", 3, "data/test2.html" );
342+
equals( tab.attr( "href" ), "data/test2.html", "href was updated" );
343+
element.one( "tabsbeforeload", function( event, ui ) {
344+
equals( ui.ajaxSettings.url, "data/test2.html", "ajaxSettings.url" );
345+
event.preventDefault();
346+
});
347+
element.tabs( "option", "active", 3 );
337348
});
338349

339350
}( jQuery ) );

ui/jquery.ui.tabs.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ $.widget( "ui.tabs", {
128128
},
129129

130130
_tabId: function( a ) {
131-
return ( $( a ).attr( "aria-controls" ) || "" ) ||
132-
"ui-tabs-" + getNextTabId();
131+
return $( a ).attr( "aria-controls" ) || "ui-tabs-" + getNextTabId();
133132
},
134133

135134
_sanitizeSelector: function( hash ) {
@@ -860,21 +859,21 @@ if ( $.uiBackCompat !== false ) {
860859
};
861860
}( jQuery, jQuery.ui.tabs.prototype ) );
862861

863-
// _tabId method
862+
// panel ids (idPrefix option + title attribute)
864863
(function( $, prototype ) {
865864
$.extend( prototype.options, {
866865
idPrefix: "ui-tabs-"
867866
});
868867

869868
var _tabId = prototype._tabId;
870869
prototype._tabId = function( a ) {
871-
return ( $( a ).attr( "aria-controls" ) || "" ) ||
870+
return $( a ).attr( "aria-controls" ) ||
872871
a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF-]/g, "" ) ||
873872
this.options.idPrefix + getNextTabId();
874873
};
875874
}( jQuery, jQuery.ui.tabs.prototype ) );
876875

877-
// _tabId method
876+
// _createPanel method
878877
(function( $, prototype ) {
879878
$.extend( prototype.options, {
880879
panelTemplate: "<div></div>"

0 commit comments

Comments
 (0)