@@ -18,6 +18,19 @@ function getNextTabId() {
18
18
return ++ tabId ;
19
19
}
20
20
21
+ var isLocal = ( function ( ) {
22
+ var rhash = / # .* $ / ,
23
+ currentPage = location . href . replace ( rhash , "" ) ;
24
+
25
+ return function ( anchor ) {
26
+ // clone the node to work around IE 6 not normalizing the href property
27
+ // if it's manually set, i.e., a.href = "#foo" kills the normalization
28
+ anchor = anchor . cloneNode ( ) ;
29
+ return anchor . hash . length > 1 &&
30
+ anchor . href . replace ( rhash , "" ) === currentPage ;
31
+ } ;
32
+ } ) ( ) ;
33
+
21
34
$ . widget ( "ui.tabs" , {
22
35
version : "@VERSION" ,
23
36
options : {
@@ -197,8 +210,7 @@ $.widget( "ui.tabs", {
197
210
} ,
198
211
199
212
_processTabs : function ( ) {
200
- var self = this ,
201
- fragmentId = / ^ # .+ / ; // Safari 2 reports '#' for an empty hash
213
+ var self = this ;
202
214
203
215
this . list = this . element . find ( "ol,ul" ) . eq ( 0 ) ;
204
216
this . lis = $ ( " > li:has(a[href])" , this . list ) ;
@@ -208,40 +220,21 @@ $.widget( "ui.tabs", {
208
220
this . panels = $ ( [ ] ) ;
209
221
210
222
this . anchors . each ( function ( i , a ) {
211
- var href = $ ( a ) . attr ( "href" ) ,
212
- hrefBase = href . split ( "#" ) [ 0 ] ,
213
- selector ,
214
- panel ,
215
- baseEl ;
216
-
217
- // For dynamically created HTML that contains a hash as href IE < 8 expands
218
- // such href to the full page url with hash and then misinterprets tab as ajax.
219
- // Same consideration applies for an added tab with a fragment identifier
220
- // since a[href=#fragment-identifier] does unexpectedly not match.
221
- // Thus normalize href attribute...
222
- if ( hrefBase && ( hrefBase === location . toString ( ) . split ( "#" ) [ 0 ] ||
223
- ( baseEl = $ ( "base" ) [ 0 ] ) && hrefBase === baseEl . href ) ) {
224
- href = a . hash ;
225
- a . href = href ;
226
- }
223
+ var selector , panel ;
227
224
228
225
// inline tab
229
- if ( fragmentId . test ( href ) ) {
230
- selector = href ;
226
+ if ( isLocal ( a ) ) {
227
+ selector = a . hash ;
231
228
panel = self . element . find ( self . _sanitizeSelector ( selector ) ) ;
232
229
// remote tab
233
- // prevent loading the page itself if href is just "#"
234
- } else if ( href && href !== "#" ) {
230
+ } else {
235
231
var id = self . _tabId ( a ) ;
236
232
selector = "#" + id ;
237
233
panel = self . element . find ( selector ) ;
238
234
if ( ! panel . length ) {
239
235
panel = self . _createPanel ( id ) ;
240
236
panel . insertAfter ( self . panels [ i - 1 ] || self . list ) ;
241
237
}
242
- // invalid tab href
243
- } else {
244
- self . options . disabled . push ( i ) ;
245
238
}
246
239
247
240
if ( panel . length ) {
@@ -525,21 +518,18 @@ $.widget( "ui.tabs", {
525
518
options = this . options ,
526
519
anchor = this . anchors . eq ( index ) ,
527
520
panel = self . _getPanelForTab ( anchor ) ,
528
- // TODO until #3808 is fixed strip fragment identifier from url
529
- // (IE fails to load from such url)
530
- url = anchor . attr ( "href" ) . replace ( / # .* $ / , "" ) ,
531
521
eventData = {
532
522
tab : anchor ,
533
523
panel : panel
534
524
} ;
535
525
536
526
// not remote
537
- if ( ! url ) {
527
+ if ( isLocal ( anchor [ 0 ] ) ) {
538
528
return ;
539
529
}
540
530
541
531
this . xhr = $ . ajax ( {
542
- url : url ,
532
+ url : anchor . attr ( "href" ) ,
543
533
beforeSend : function ( jqXHR , settings ) {
544
534
return self . _trigger ( "beforeLoad" , event ,
545
535
$ . extend ( { jqXHR : jqXHR , ajaxSettings : settings } , eventData ) ) ;
0 commit comments