r2111 - in trunk: tests/unit/tabs ui

r2111 - in trunk: tests/unit/tabs ui


Author: klaus.hartl
Date: Thu Feb 19 12:19:13 2009
New Revision: 2111
Modified:
trunk/tests/unit/tabs/tabs_methods.js
trunk/ui/ui.tabs.js
Log:
Tabs: normalization of href attribute required in IE, fixes #4134
Modified: trunk/tests/unit/tabs/tabs_methods.js
==============================================================================
--- trunk/tests/unit/tabs/tabs_methods.js    (original)
+++ trunk/tests/unit/tabs/tabs_methods.js    Thu Feb 19 12:19:13 2009
@@ -43,7 +43,7 @@
});
test('add', function() {
-    expect(3);
+    expect(4);
    
    el = $('#tabs1').tabs();
    el.tabs('add', "#new", 'New');
@@ -54,6 +54,8 @@
    var other = $('li:first', el).simulate('mouseover');
    ok(other.is('.ui-state-hover'), 'should not remove mouseover handler from
existing tab');
    other.simulate('mouseout');
+    
+    equals($('a', added).attr('href'), '#new', 'should not expand href to
full url of current page');
    
    ok(false, "missing test - untested code is broken code.");
});
Modified: trunk/ui/ui.tabs.js
==============================================================================
--- trunk/ui/ui.tabs.js    (original)
+++ trunk/ui/ui.tabs.js    Thu Feb 19 12:19:13 2009
@@ -81,13 +81,20 @@
        this.$tabs.each(function(i, a) {
            var href = $(a).attr('href');
-            // For dynamically created HTML that contains a hash as href IE expands
-            // such href to the full page url with hash and then misinterprets tab
as ajax...
-            if (href.split('#')[0] == location.toString().split('#')[0]) href =
a.hash;
-
+            // For dynamically created HTML that contains a hash as href IE < 8
expands
+            // such href to the full page url with hash and then misinterprets tab
as ajax.
+            // Same consideration applies for an added tab with a fragment
identifier
+            // since a[href=#fragment-identifier] does unexpectedly not match.
+            // Thus normalize href attribute...
+            if (href.split('#')[0] == location.toString().split('#')[0]) {
+                href = a.hash;
+                a.href = href;
+            }
+            
            // inline tab
-            if (fragmentId.test(href))
+            if (fragmentId.test(href)) {
                self.$panels = self.$panels.add(self._sanitizeSelector(href));
+            }
            // remote tab
            else if (href != '#') { // prevent loading the page itself if href is
just "#"
@@ -109,8 +116,9 @@
            }
            // invalid tab href
-            else
+            else {
                o.disabled.push(i);
+            }
        });
        // initialization from scratch