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

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

Issue 29322846: Issue 2826 - Hamburger menu not visible on all pages (Closed)
Patch Set: Created July 28, 2015, 11:51 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 | « static/css/main-mobile.css ('k') | templates/default.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 "use strict"; 1 "use strict";
2 2
3 (function() 3 (function()
4 { 4 {
5 function escapeRegExp(string) 5 function escapeRegExp(string)
6 { 6 {
7 return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); 7 return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
8 } 8 }
9 9
10 function hasClass(element, className) 10 function hasClass(element, className)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 language.onclick = function(event) 58 language.onclick = function(event)
59 { 59 {
60 if (hasClass(languageSelection, "visible")) 60 if (hasClass(languageSelection, "visible"))
61 return; 61 return;
62 62
63 addClass(languageSelection, "visible"); 63 addClass(languageSelection, "visible");
64 stopPropagation(event); 64 stopPropagation(event);
65 }; 65 };
66 } 66 }
67 67
68 function getSelectedItem(menu) 68 function navigationClick(e)
Thomas Greiner 2015/07/29 11:06:59 Rename variable to "event" to (1) make it consiste
saroyanm 2015/07/29 13:55:50 Done.
69 { 69 {
70 var items = menu.getElementsByTagName("li"); 70 var element = e.target;
71 for (var i = 0; i < items.length; i++) 71 while (true)
72 { 72 {
73 var item = items[i]; 73 if (!element)
74 if (hasClass(item, "selected")) 74 return;
75 return item; 75
76 if (hasClass(element, "selected") || element.id == "hamburger")
77 {
78 if ("querySelector" in document)
79 toggleClass(document.querySelector("header nav>ul"), "visible");
Thomas Greiner 2015/07/29 11:06:59 Don't forget to call `event.preventDefault()` and
Thomas Greiner 2015/07/29 11:06:59 Detail: Missing whitespaces in selector string.
saroyanm 2015/07/29 13:55:50 Done.
saroyanm 2015/07/29 13:55:50 Done.
80 return;
81 }
82 element = element.parentElement;
76 } 83 }
77 } 84 }
78 85
79 function initMenu() 86 function initMenu()
80 { 87 {
81 if ("querySelector" in document) 88 if ("querySelector" in document)
82 { 89 document.querySelector("nav").onclick = navigationClick;
Thomas Greiner 2015/07/29 11:06:59 No need to use `document.querySelector`. `document
saroyanm 2015/07/29 13:55:50 Just noticed that there are two nav elements on th
83 var menu = document.querySelector("header nav>ul");
84 var selectedItem = getSelectedItem(menu);
85 if (selectedItem)
86 selectedItem.onclick = function()
87 {
88 toggleClass(menu, "visible");
89 };
90 }
91 } 90 }
92 91
93 function initFooterSection(section) 92 function initFooterSection(section)
94 { 93 {
95 var header = section.getElementsByTagName("h1")[0]; 94 var header = section.getElementsByTagName("h1")[0];
96 header.onclick = function() 95 header.onclick = function()
97 { 96 {
98 toggleClass(section, "visible"); 97 toggleClass(section, "visible");
99 }; 98 };
100 } 99 }
101 100
102 function initFooter() 101 function initFooter()
103 { 102 {
104 var footerContent = document.getElementById("footer-content"); 103 var footerContent = document.getElementById("footer-content");
105 var footerNav = footerContent.getElementsByTagName("nav")[0]; 104 var footerNav = footerContent.getElementsByTagName("nav")[0];
106 var footerNavSections = footerNav.getElementsByTagName("section"); 105 var footerNavSections = footerNav.getElementsByTagName("section");
107 106
108 for (var i = 0; i < footerNavSections.length; i++) 107 for (var i = 0; i < footerNavSections.length; i++)
109 { 108 {
110 var section = footerNavSections[i]; 109 var section = footerNavSections[i];
111 initFooterSection(section); 110 initFooterSection(section);
112 } 111 }
113 } 112 }
114 113
115 initLanguageSelection(); 114 initLanguageSelection();
116 initMenu(); 115 initMenu();
117 initFooter(); 116 initFooter();
118 })(); 117 })();
OLDNEW
« no previous file with comments | « static/css/main-mobile.css ('k') | templates/default.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld