Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: static/js/main.js

Issue 29548567: Issue 4925 - Create accordion component for Help Center (Closed) Base URL: https://hg.adblockplus.org/help.eyeo.com
Patch Set: Created Sept. 18, 2017, 10:03 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: static/js/main.js
===================================================================
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -18,10 +18,52 @@
var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar-collapse");
for (var i = 0; i < toggleNavbarCollapseEls.length; i++)
{
toggleNavbarCollapseEls[i]
.addEventListener("click", toggleNavbarCollapse, false);
}
+ // Accordion menu
+
+ function setupAccordionMenu(accordionEl)
+ {
+ var accordionButtons = accordionEl.getElementsByClassName('accordion-toggle-button');
+ for ( var i = 0; i < accordionButtons.length; i++ ) {
+ accordionButtons[i].addEventListener("click", toggleAccordionSection, false);
+ if ( i !== 0 ) {
+ accordionButtons[i].setAttribute("aria-expanded", "false");
+ accordionButtons[i].setAttribute("aria-disabled", "false");
+ document
+ .getElementById( accordionButtons[i].getAttribute("aria-controls") )
+ .setAttribute("hidden", "true");
ire 2017/09/18 10:08:11 See https://issues.adblockplus.org/ticket/5703 reg
juliandoucette 2017/09/18 12:53:31 Acknowledged.
+ }
+ }
+ }
+
+ function toggleAccordionSection()
+ {
+ // Hide currently expanded section
+ var accordion = this.parentElement.parentElement;
+ var expandedButton = accordion.querySelector("button[aria-expanded='true']");
+ expandedButton.setAttribute("aria-expanded", "false");
+ expandedButton.setAttribute("aria-disabled", "false");
+ document
+ .getElementById( expandedButton.getAttribute("aria-controls") )
+ .setAttribute("hidden", "true");
+
+ // Expand new section
+ this.setAttribute("aria-expanded", "true");
+ this.setAttribute("aria-disabled", "true");
+ document
+ .getElementById( this.getAttribute("aria-controls") )
+ .removeAttribute("hidden");
+ }
+
+ var accordionMenus = document.getElementsByClassName('accordion');
+ for (var i = 0; i < accordionMenus.length; i++)
+ {
+ setupAccordionMenu( accordionMenus[i] );
+ }
ire 2017/09/18 10:08:11 This will be refactored in https://issues.adblockp
juliandoucette 2017/09/18 12:53:31 Acknowledged.
+
}, false);
}());

Powered by Google App Engine
This is Rietveld