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

Side by Side Diff: static/js/main.js

Issue 29564555: Issue 5824 - Refactor CustomSelect on help.eyeo.com (Closed) Base URL: https://hg.adblockplus.org/help.eyeo.com
Patch Set: Update comment style Created Oct. 10, 2017, 11:54 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
« no previous file with comments | « includes/layout/footer.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function(){ 1 (function(){
2 document.addEventListener("DOMContentLoaded", function() 2 document.addEventListener("DOMContentLoaded", function()
3 { 3 {
4 4
5 /**************************************************************************
6 * General
7 **************************************************************************/
8
5 // Change html class name from "no-js" to "js" 9 // Change html class name from "no-js" to "js"
6 document.documentElement.className = "js"; 10 document.documentElement.className = "js";
7 11
8 // Toggle Navbar Collapse 12 /**************************************************************************
13 * Navbar
14 **************************************************************************/
15
9 function toggleNavbarCollapse() 16 function toggleNavbarCollapse()
10 { 17 {
11 var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar- collapse"); 18 var navbarCollapseEls = this.parentElement.getElementsByClassName("navbar- collapse");
12 for (var i = 0; i < navbarCollapseEls.length; i++) 19 for (var i = 0; i < navbarCollapseEls.length; i++)
13 { 20 {
14 navbarCollapseEls[i] 21 navbarCollapseEls[i]
15 .classList.toggle("open") 22 .classList.toggle("open")
16 } 23 }
17 } 24 }
18 25
19 var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar -collapse"); 26 var toggleNavbarCollapseEls = document.getElementsByClassName("toggle-navbar -collapse");
20 for (var i = 0; i < toggleNavbarCollapseEls.length; i++) 27 for (var i = 0; i < toggleNavbarCollapseEls.length; i++)
21 { 28 {
22 toggleNavbarCollapseEls[i] 29 toggleNavbarCollapseEls[i]
23 .addEventListener("click", toggleNavbarCollapse, false); 30 .addEventListener("click", toggleNavbarCollapse, false);
24 } 31 }
25 32
26 // Custom Select 33 /**************************************************************************
27 function onClickCustomSelect() 34 * CustomSelect
35 **************************************************************************/
36
37 function CustomSelect(select)
28 { 38 {
29 var options = this.nextElementSibling; 39 this.select = select;
30 if (options.getAttribute("aria-hidden") == "true") 40 this.close();
41 select.addEventListener("click", this._onClick.bind(this), false);
42 }
43
44 CustomSelect.prototype._onClick = function(event)
45 {
46 if (event.target.classList.contains("custom-select-selected"))
31 { 47 {
32 options.removeAttribute("aria-hidden"); 48 var options = this.select.querySelector(".custom-select-options");
33 this.setAttribute("aria-expanded", "true"); 49 if (options.getAttribute("aria-hidden") == "true")
34 } 50 {
35 else 51 this.open();
36 { 52 }
37 options.setAttribute("aria-hidden", "true"); 53 else
38 this.setAttribute("aria-expanded", "false"); 54 {
55 this.close();
56 }
39 } 57 }
40 } 58 }
41 59
42 var customSelectEls = document.getElementsByClassName('custom-select-selecte d'); 60 CustomSelect.prototype.open = function()
43 for (var i = 0; i < customSelectEls.length; i++)
44 { 61 {
45 customSelectEls[i] 62 this.select
46 .addEventListener("click", onClickCustomSelect, false); 63 .querySelector(".custom-select-selected")
47 customSelectEls[i] 64 .setAttribute("aria-expanded", "true");
48 .nextElementSibling 65
66 this.select
67 .querySelector(".custom-select-options")
68 .removeAttribute("aria-hidden");
69 }
70
71 CustomSelect.prototype.close = function()
72 {
73 this.select
74 .querySelector(".custom-select-selected")
75 .setAttribute("aria-expanded", "false");
76
77 this.select
78 .querySelector(".custom-select-options")
49 .setAttribute("aria-hidden", "true"); 79 .setAttribute("aria-hidden", "true");
50 } 80 }
81
82 new CustomSelect(document.getElementById("language-select"));
51 83
52 }, false); 84 }, false);
53 }()); 85 }());
OLDNEW
« no previous file with comments | « includes/layout/footer.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld