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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 (function(){ 1 (function(){
2 document.addEventListener("DOMContentLoaded", function() 2 document.addEventListener("DOMContentLoaded", function()
3 { 3 {
4 4
5 // Change html class name from "no-js" to "js" 5 // Change html class name from "no-js" to "js"
6 document.documentElement.className = "js"; 6 document.documentElement.className = "js";
7 7
8 // Toggle Navbar Collapse 8 // Toggle Navbar Collapse
9 function toggleNavbarCollapse() 9 function toggleNavbarCollapse()
10 { 10 {
11 var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar- collapse"); 11 var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar- collapse");
12 for (var i = 0; i < navbarCollapseEls.length; i++) 12 for (var i = 0; i < navbarCollapseEls.length; i++)
13 { 13 {
14 navbarCollapseEls[i] 14 navbarCollapseEls[i]
15 .classList.toggle("open") 15 .classList.toggle("open")
16 } 16 }
17 } 17 }
18 18
19 var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar -collapse"); 19 var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar -collapse");
20 for (var i = 0; i < toggleNavbarCollapseEls.length; i++) 20 for (var i = 0; i < toggleNavbarCollapseEls.length; i++)
21 { 21 {
22 toggleNavbarCollapseEls[i] 22 toggleNavbarCollapseEls[i]
23 .addEventListener("click", toggleNavbarCollapse, false); 23 .addEventListener("click", toggleNavbarCollapse, false);
24 } 24 }
25 25
26 // Accordion menu
27
28 function setupAccordionMenu(accordionEl)
29 {
30 var accordionButtons = accordionEl.getElementsByClassName('accordion-toggl e-button');
31 for ( var i = 0; i < accordionButtons.length; i++ ) {
32 accordionButtons[i].addEventListener("click", toggleAccordionSection, fa lse);
33 if ( i !== 0 ) {
34 accordionButtons[i].setAttribute("aria-expanded", "false");
35 accordionButtons[i].setAttribute("aria-disabled", "false");
36 document
37 .getElementById( accordionButtons[i].getAttribute("aria-controls") )
38 .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.
39 }
40 }
41 }
42
43 function toggleAccordionSection()
44 {
45 // Hide currently expanded section
46 var accordion = this.parentElement.parentElement;
47 var expandedButton = accordion.querySelector("button[aria-expanded='true'] ");
48 expandedButton.setAttribute("aria-expanded", "false");
49 expandedButton.setAttribute("aria-disabled", "false");
50 document
51 .getElementById( expandedButton.getAttribute("aria-controls") )
52 .setAttribute("hidden", "true");
53
54 // Expand new section
55 this.setAttribute("aria-expanded", "true");
56 this.setAttribute("aria-disabled", "true");
57 document
58 .getElementById( this.getAttribute("aria-controls") )
59 .removeAttribute("hidden");
60 }
61
62 var accordionMenus = document.getElementsByClassName('accordion');
63 for (var i = 0; i < accordionMenus.length; i++)
64 {
65 setupAccordionMenu( accordionMenus[i] );
66 }
ire 2017/09/18 10:08:11 This will be refactored in https://issues.adblockp
juliandoucette 2017/09/18 12:53:31 Acknowledged.
67
26 }, false); 68 }, false);
27 }()); 69 }());
OLDNEW

Powered by Google App Engine
This is Rietveld