14
14
*/
15
15
( function ( $ , undefined ) {
16
16
17
- var tabId = 0 ,
18
- rhash = / # .* $ / ;
19
-
20
- function getNextTabId ( ) {
21
- return ++ tabId ;
22
- }
23
-
24
- function isLocal ( anchor ) {
25
- // support: IE7
26
- // IE7 doesn't normalize the href property when set via script (#9317)
27
- anchor = anchor . cloneNode ( false ) ;
28
-
29
- return anchor . hash . length > 1 &&
30
- decodeURIComponent ( anchor . href . replace ( rhash , "" ) ) ===
31
- decodeURIComponent ( location . href . replace ( rhash , "" ) ) ;
32
- }
33
-
34
17
$ . widget ( "ui.tabs" , {
35
18
version : "@VERSION" ,
36
19
delay : 300 ,
@@ -49,6 +32,21 @@ $.widget( "ui.tabs", {
49
32
load : null
50
33
} ,
51
34
35
+ _isLocal : ( function ( ) {
36
+ var rhash = / # .* $ / ;
37
+
38
+ return function ( anchor ) {
39
+
40
+ // support: IE7
41
+ // IE7 doesn't normalize the href property when set via script (#9317)
42
+ anchor = anchor . cloneNode ( false ) ;
43
+
44
+ return anchor . hash . length > 1 &&
45
+ decodeURIComponent ( anchor . href . replace ( rhash , "" ) ) ===
46
+ decodeURIComponent ( location . href . replace ( rhash , "" ) ) ;
47
+ } ;
48
+ } ) ( ) ,
49
+
52
50
_create : function ( ) {
53
51
var that = this ,
54
52
options = this . options ;
@@ -296,10 +294,6 @@ $.widget( "ui.tabs", {
296
294
}
297
295
} ,
298
296
299
- _tabId : function ( tab ) {
300
- return tab . attr ( "aria-controls" ) || "ui-tabs-" + getNextTabId ( ) ;
301
- } ,
302
-
303
297
_sanitizeSelector : function ( hash ) {
304
298
return hash ? hash . replace ( / [ ! " $ % & ' ( ) * + , . \/ : ; < = > ? @ \[ \] \^ ` { | } ~ ] / g, "\\$&" ) : "" ;
305
299
} ,
@@ -406,12 +400,15 @@ $.widget( "ui.tabs", {
406
400
originalAriaControls = tab . attr ( "aria-controls" ) ;
407
401
408
402
// inline tab
409
- if ( isLocal ( anchor ) ) {
403
+ if ( that . _isLocal ( anchor ) ) {
410
404
selector = anchor . hash ;
405
+ panelId = selector . substring ( 1 ) ;
411
406
panel = that . element . find ( that . _sanitizeSelector ( selector ) ) ;
412
407
// remote tab
413
408
} else {
414
- panelId = that . _tabId ( tab ) ;
409
+ // If the tab doesn't already have aria-controls,
410
+ // generate an id by using a throw-away element
411
+ panelId = tab . attr ( "aria-controls" ) || $ ( { } ) . uniqueId ( ) [ 0 ] . id ;
415
412
selector = "#" + panelId ;
416
413
panel = that . element . find ( selector ) ;
417
414
if ( ! panel . length ) {
@@ -428,7 +425,7 @@ $.widget( "ui.tabs", {
428
425
tab . data ( "ui-tabs-aria-controls" , originalAriaControls ) ;
429
426
}
430
427
tab . attr ( {
431
- "aria-controls" : selector . substring ( 1 ) ,
428
+ "aria-controls" : panelId ,
432
429
"aria-labelledby" : anchorId
433
430
} ) ;
434
431
panel . attr ( "aria-labelledby" , anchorId ) ;
@@ -790,7 +787,7 @@ $.widget( "ui.tabs", {
790
787
} ;
791
788
792
789
// not remote
793
- if ( isLocal ( anchor [ 0 ] ) ) {
790
+ if ( this . _isLocal ( anchor [ 0 ] ) ) {
794
791
return ;
795
792
}
796
793
0 commit comments