aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/accordion/no-auto-height.html12
-rw-r--r--tests/unit/accordion/accordion.html6
-rw-r--r--tests/unit/accordion/accordion_options.js24
-rw-r--r--ui/ui.accordion.js28
4 files changed, 42 insertions, 28 deletions
diff --git a/demos/accordion/no-auto-height.html b/demos/accordion/no-auto-height.html
index 49b7c3bb8..b76c8d9cc 100644
--- a/demos/accordion/no-auto-height.html
+++ b/demos/accordion/no-auto-height.html
@@ -10,7 +10,8 @@
<script type="text/javascript">
$(function() {
$("#accordion").accordion({
- autoHeight: false
+ autoHeight: false,
+ navigation: true
});
});
</script>
@@ -20,15 +21,15 @@
<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>
diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html
index bce2e8cd7..fbb3a85d0 100644
--- a/tests/unit/accordion/accordion.html
+++ b/tests/unit/accordion/accordion.html
@@ -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>
diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js
index 1ef6542a3..95edae597 100644
--- a/tests/unit/accordion/accordion_options.js
+++ b/tests/unit/accordion/accordion_options.js
@@ -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);
diff --git a/ui/ui.accordion.js b/ui/ui.accordion.js
index 5fb6b501a..de1a29f1e 100644
--- a/ui/ui.accordion.js
+++ b/ui/ui.accordion.js
@@ -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);