Skip to content
Permalink
Browse files

UI Tabs: url containing a fragment identfier broke Ajax tab loading, …

…fixes #3627
  • Loading branch information
Klaus Hartl
Klaus Hartl committed Jan 19, 2009
1 parent 8f4ae53 commit 59c6f97625cf6f149af7543b1739aa8d22737e6e
Showing with 26 additions and 15 deletions.
  1. +1 −4 tests/unit/tabs/tabs.html
  2. +14 −5 tests/unit/tabs/tabs.js
  3. +11 −6 ui/ui.tabs.js
@@ -16,9 +16,7 @@
<script type="text/javascript" src="tabs.js"></script>
</head>
<body>

<div id="main">

<div id="tabs1">
<ul>
<li><a href="#fragment-1">1</a></li>
@@ -33,12 +31,11 @@
<ul>
<li><a href="#colon:test">1</a></li>
<li><a href="#inline-style">2</a></li>
<li><a href="test.html#test">1</a></li>
</ul>
<div id="colon:test"></div>
<div style="height: 300px;" id="inline-style"></div>
</div>

</div>

</body>
</html>
@@ -83,7 +83,8 @@ module('tabs');
test('remove', function() {
expect(4);

var el = $('#tabs1 > ul').tabs();
var el = $('#tabs1').tabs();

el.tabs('remove', 0);
equals(el.tabs('length'), 2, 'remove tab');
equals($('li a[href$="fragment-1"]', el).length, 0, 'remove associated list item');
@@ -92,10 +93,9 @@ module('tabs');
// TODO delete tab -> focus tab to right
// TODO delete last tab -> focus tab to left

el = $('#tabs2 > ul').tabs({ selected: 1 });
el.tabs('select', 1);
el.tabs('remove', 1);
equals(el.data('selected.tabs'), 0, 'update selected property');

equals(el.data('selected.tabs'), 0, 'update selected property');
});

test('enable', function() {
@@ -219,7 +219,7 @@ module('tabs: Tickets');
};
var expected = inlineStyle('height');

var el = $('#tabs2 > ul').tabs();
var el = $('#tabs2').tabs();
equals(inlineStyle('height'), expected, 'init should not remove inline style');

el.tabs('select', 1);
@@ -234,6 +234,15 @@ module('tabs: Tickets');
});

});

test('Ajax tab with url containing a fragment identifier fails to load, #3627', function() { // http://ui.jquery.com/bugs/ticket/3627
expect(1);

var el = $('#tabs2').tabs();

equals( $('a:eq(2)', el).data('load.tabs'), 'test.html', 'should ignore fragment identifier' );

});

// test('', function() {
// expect(0);
@@ -93,17 +93,21 @@ $.widget("ui.tabs", {
this.$lis = $('li:has(a[href])', this.list);
this.$tabs = this.$lis.map(function() { return $('a', this)[0]; });
this.$panels = $([]);

var self = this, o = this.options;

var fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
this.$tabs.each(function(i, a) {
var href = $(a).attr('href');

// inline tab
if (a.hash && a.hash.replace('#', '')) // Safari 2 reports '#' for an empty hash
self.$panels = self.$panels.add(self._sanitizeSelector(a.hash));
if (fragmentId.test(href))
self.$panels = self.$panels.add(self._sanitizeSelector(href));

// remote tab
else if ($(a).attr('href') != '#') { // prevent loading the page itself if href is just "#"
$.data(a, 'href.tabs', a.href); // required for restore on destroy
$.data(a, 'load.tabs', a.href); // mutable
else if (href != '#') { // prevent loading the page itself if href is just "#"
$.data(a, 'href.tabs', href); // required for restore on destroy
$.data(a, 'load.tabs', href.replace(/#.*$/, '')); // mutable data, NOTE IE fails to load if url contains fragment identifier - TODO jQuery Ajax bug?
var id = self._tabId(a);
a.href = '#' + id;
var $panel = $('#' + id);
@@ -114,6 +118,7 @@ $.widget("ui.tabs", {
}
self.$panels = self.$panels.add($panel);
}

// invalid tab href
else
o.disabled.push(i + 1);

0 comments on commit 59c6f97

Please sign in to comment.
You can’t perform that action at this time.