diff options
author | Klaus Hartl <klaus.hartl@googlemail.com> | 2009-01-19 23:11:30 +0000 |
---|---|---|
committer | Klaus Hartl <klaus.hartl@googlemail.com> | 2009-01-19 23:11:30 +0000 |
commit | 59c6f97625cf6f149af7543b1739aa8d22737e6e (patch) | |
tree | 58d3c66d26d2fc42b5a8513da1249fe90bbf06e3 | |
parent | 8f4ae539f3d09cd6e4f6348dcb9b8b5846d69c12 (diff) | |
download | jquery-ui-59c6f97625cf6f149af7543b1739aa8d22737e6e.tar.gz jquery-ui-59c6f97625cf6f149af7543b1739aa8d22737e6e.zip |
UI Tabs: url containing a fragment identfier broke Ajax tab loading, fixes #3627
-rw-r--r-- | tests/unit/tabs/tabs.html | 5 | ||||
-rw-r--r-- | tests/unit/tabs/tabs.js | 19 | ||||
-rw-r--r-- | ui/ui.tabs.js | 17 |
3 files changed, 26 insertions, 15 deletions
diff --git a/tests/unit/tabs/tabs.html b/tests/unit/tabs/tabs.html index b6d466adb..939553429 100644 --- a/tests/unit/tabs/tabs.html +++ b/tests/unit/tabs/tabs.html @@ -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> diff --git a/tests/unit/tabs/tabs.js b/tests/unit/tabs/tabs.js index a5257dbfc..90c52a246 100644 --- a/tests/unit/tabs/tabs.js +++ b/tests/unit/tabs/tabs.js @@ -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); diff --git a/ui/ui.tabs.js b/ui/ui.tabs.js index 54609c3fd..0bcd68fb8 100644 --- a/ui/ui.tabs.js +++ b/ui/ui.tabs.js @@ -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); |