Skip to content

Commit 1ca5ae1

Browse files
author
Klaus Hartl
committed
Tabs: normalization of href attribute required in IE, fixes #4134
1 parent e5268f9 commit 1ca5ae1

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

tests/unit/tabs/tabs_methods.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test('disable', function() {
4343
});
4444

4545
test('add', function() {
46-
expect(3);
46+
expect(4);
4747

4848
el = $('#tabs1').tabs();
4949
el.tabs('add', "#new", 'New');
@@ -55,6 +55,8 @@ test('add', function() {
5555
ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from existing tab');
5656
other.simulate('mouseout');
5757

58+
equals($('a', added).attr('href'), '#new', 'should not expand href to full url of current page');
59+
5860
ok(false, "missing test - untested code is broken code.");
5961
});
6062

ui/ui.tabs.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@ $.widget("ui.tabs", {
8181
this.$tabs.each(function(i, a) {
8282
var href = $(a).attr('href');
8383

84-
// For dynamically created HTML that contains a hash as href IE expands
85-
// such href to the full page url with hash and then misinterprets tab as ajax...
86-
if (href.split('#')[0] == location.toString().split('#')[0]) href = a.hash;
87-
84+
// For dynamically created HTML that contains a hash as href IE < 8 expands
85+
// such href to the full page url with hash and then misinterprets tab as ajax.
86+
// Same consideration applies for an added tab with a fragment identifier
87+
// since a[href=#fragment-identifier] does unexpectedly not match.
88+
// Thus normalize href attribute...
89+
if (href.split('#')[0] == location.toString().split('#')[0]) {
90+
href = a.hash;
91+
a.href = href;
92+
}
93+
8894
// inline tab
89-
if (fragmentId.test(href))
95+
if (fragmentId.test(href)) {
9096
self.$panels = self.$panels.add(self._sanitizeSelector(href));
97+
}
9198

9299
// remote tab
93100
else if (href != '#') { // prevent loading the page itself if href is just "#"
@@ -109,8 +116,9 @@ $.widget("ui.tabs", {
109116
}
110117

111118
// invalid tab href
112-
else
119+
else {
113120
o.disabled.push(i);
121+
}
114122
});
115123

116124
// initialization from scratch

0 commit comments

Comments
 (0)