]> source.dussan.org Git - jquery-ui.git/commitdiff
accordion fix for #4653: added tests, adopted no-auto-height demo to also cover navig...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 3 Jul 2009 21:05:22 +0000 (21:05 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 3 Jul 2009 21:05:22 +0000 (21:05 +0000)
demos/accordion/no-auto-height.html
tests/unit/accordion/accordion.html
tests/unit/accordion/accordion_options.js
ui/ui.accordion.js

index 49b7c3bb8a35512f60edfee3e25a6ce2bf873a89..b76c8d9cca2b46ab4e404d2e6ee3e56cfa0b38e1 100644 (file)
@@ -10,7 +10,8 @@
        <script type="text/javascript">
        $(function() {
                $("#accordion").accordion({
-                       autoHeight: false
+                       autoHeight: false,
+                       navigation: true
                });
        });
        </script>
 <div class="demo">
 
 <div id="accordion">
-       <h3><a href="#">Section 1</a></h3>
+       <h3><a href="#section1">Section 1</a></h3>
        <div>
                <p>Mauris mauris ante, blandit et, ultrices a, susceros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
        </div>
-       <h3><a href="#">Section 2</a></h3>
+       <h3><a href="#section2">Section 2</a></h3>
        <div>
                <p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p>
        </div>
-       <h3><a href="#">Section 3</a></h3>
+       <h3><a href="#section3">Section 3</a></h3>
        <div>
                <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p>
                <ul>
@@ -40,6 +41,7 @@
                        <li>List item</li>
                        <li>List item</li>
                </ul>
+               <a href="#othercontent">Link to other content</a>
        </div>
 </div>
 
@@ -51,6 +53,8 @@
 
 <p>Setting <code>autoHeight: false</code> allows to accordion panels to keep their native height.</p>
 
+<p>In addition, the <code>navigation</code> option is enabled, opening the panel based on the current location, eg. no-auto-height.html#panel2 would open the second panel on page load. It also finds anchors within the content, so #othercontent will open the third section, as it contains a link with that href.</p>
+
 </div><!-- End demo-description -->
 
 </body>
index bce2e8cd7dc98108cba8174b2279b78a89c16576..fbb3a85d052ab6ae1d04d0d4749d3d672e8e7598 100644 (file)
@@ -58,7 +58,7 @@
 
        <ul id="navigation">
                <li>
-                       <a href="?p=1.1.1">Guitar</a>
+                       <h2><a href="?p=1.1.1">Guitar</a></h2>
                        <ul>
                                <li><a href="?p=1.1.1.1">Electric</a></li>
                                <li><a href="?p=1.1.1.2">Acoustic</a></li>
@@ -68,7 +68,7 @@
                        </ul> 
                </li>
                <li>
-                       <a href="?p=1.1.2"><span>Bass</span></a>
+                       <h2><a href="?p=1.1.2"><span>Bass</span></a></h2>
                        <ul>
                                <li><a href="?p=1.1.2.1">Electric</a></li>
                                <li><a href="?p=1.1.2.2">Acoustic</a></li>
@@ -80,7 +80,7 @@
                        </ul> 
                </li>
                <li>
-                       <a href="?p=1.1.3">Drums</a>
+                       <h2><a href="?p=1.1.3">Drums</a></h2>
                        <ul>
                                <li><a href="?p=1.1.3.2">Acoustic Drums</a></li>
                                <li><a href="?p=1.1.3.3">Electronic Drums</a></li>
index 1ef6542a3f493b90df0dd6cad8548be2443d20e2..95edae597455806751a47d7b43e0885b917e8a53 100644 (file)
@@ -136,16 +136,24 @@ test("{ icons: false }", function() {
        icons(false);
 });
 
-test("{ navigation: false }, default", function() {
-       ok(false, 'missing test - untested code is broken code');
-});
-
-test("{ navigation: true }", function() {
-       ok(false, 'missing test - untested code is broken code');
+test("{ navigation: true, navigationFilter: header }", function() {
+       $("#navigation").accordion({
+               navigation: true,
+               navigationFilter: function() {
+                       return /\?p=1\.1\.3$/.test(this.href);
+               }
+       });
+       equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
 });
 
-test("{ navigationFilter: Function }, default", function() {
-       ok(false, 'missing test - untested code is broken code');
+test("{ navigation: true, navigationFilter: content }", function() {
+       $("#navigation").accordion({
+               navigation: true,
+               navigationFilter: function() {
+                       return /\?p=1\.1\.3\.2$/.test(this.href);
+               }
+       });
+       equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
 });
 
 })(jQuery);
index 5fb6b501a3c06ee287575d7e969f4db8baaefa12..de1a29f1e8411070434dc9263e7f619abaf1c3ff 100644 (file)
@@ -27,18 +27,6 @@ $.widget("ui.accordion", {
                        o.collapsible = !o.alwaysOpen;
                }
 
-               if ( o.navigation ) {
-                       var current = this.element.find("a").filter(o.navigationFilter);
-                       if ( current.length ) {
-                               if ( current.filter(o.header).length ) {
-                                       this.active = current;
-                               } else {
-                                       this.active = current.parent().parent().prev();
-                                       current.addClass("ui-accordion-content-active");
-                               }
-                       }
-               }
-
                this.element.addClass("ui-accordion ui-widget ui-helper-reset");
                
                // in lack of child-selectors in CSS we need to mark top-LIs in a UL-accordion for some IE-fix
@@ -56,6 +44,20 @@ $.widget("ui.accordion", {
                        .next()
                                .addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom");
 
+               if ( o.navigation ) {
+                       var current = this.element.find("a").filter(o.navigationFilter);
+                       if ( current.length ) {
+                               var header = current.closest(".ui-accordion-header");
+                               if ( header.length ) {
+                                       // anchor within header
+                                       this.active = header;
+                               } else {
+                                       // anchor within content
+                                       this.active = current.closest(".ui-accordion-content").prev();
+                               }
+                       }
+               }
+
                this.active = this._findActive(this.active || o.active).toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top");
                this.active.next().addClass('ui-accordion-content-active');
 
@@ -276,7 +278,7 @@ $.widget("ui.accordion", {
                // switch classes
                this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all")
                        .find(".ui-icon").removeClass(o.icons.headerSelected).addClass(o.icons.header);
-               this.active.next().addClass('ui-accordion-content-active');
+               this.active.next().removeClass('ui-accordion-content-active');
                if (!clickedIsActive) {
                        clicked.removeClass("ui-state-default ui-corner-all").addClass("ui-state-active ui-corner-top")
                                .find(".ui-icon").removeClass(o.icons.header).addClass(o.icons.headerSelected);