| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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 navigationClick(e) | 68 function navigationClick(event) |
|
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 element = e.target; | 70 var element = event.target; |
| 71 while (true) | 71 while (true) |
| 72 { | 72 { |
| 73 if (!element) | 73 if (!element) |
| 74 return; | 74 return false; |
| 75 | 75 |
| 76 if (hasClass(element, "selected") || element.id == "hamburger") | 76 if (hasClass(element, "selected") || element.id == "hamburger") |
| 77 { | 77 { |
| 78 if ("querySelector" in document) | 78 if ("querySelector" in document) |
| 79 toggleClass(document.querySelector("header nav>ul"), "visible"); | 79 { |
|
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; | 80 event.preventDefault(); |
| 81 toggleClass(document.querySelector("header nav > ul"), "visible"); | |
| 82 } | |
| 83 return false; | |
| 81 } | 84 } |
| 82 element = element.parentElement; | 85 element = element.parentElement; |
| 83 } | 86 } |
| 84 } | 87 } |
| 85 | 88 |
| 86 function initMenu() | 89 function initMenu() |
| 87 { | 90 { |
| 88 if ("querySelector" in document) | 91 if ("querySelector" in document) |
| 89 document.querySelector("nav").onclick = navigationClick; | 92 document.querySelector("header 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
| |
| 90 } | 93 } |
| 91 | 94 |
| 92 function initFooterSection(section) | 95 function initFooterSection(section) |
| 93 { | 96 { |
| 94 var header = section.getElementsByTagName("h1")[0]; | 97 var header = section.getElementsByTagName("h1")[0]; |
| 95 header.onclick = function() | 98 header.onclick = function() |
| 96 { | 99 { |
| 97 toggleClass(section, "visible"); | 100 toggleClass(section, "visible"); |
| 98 }; | 101 }; |
| 99 } | 102 } |
| 100 | 103 |
| 101 function initFooter() | 104 function initFooter() |
| 102 { | 105 { |
| 103 var footerContent = document.getElementById("footer-content"); | 106 var footerContent = document.getElementById("footer-content"); |
| 104 var footerNav = footerContent.getElementsByTagName("nav")[0]; | 107 var footerNav = footerContent.getElementsByTagName("nav")[0]; |
| 105 var footerNavSections = footerNav.getElementsByTagName("section"); | 108 var footerNavSections = footerNav.getElementsByTagName("section"); |
| 106 | 109 |
| 107 for (var i = 0; i < footerNavSections.length; i++) | 110 for (var i = 0; i < footerNavSections.length; i++) |
| 108 { | 111 { |
| 109 var section = footerNavSections[i]; | 112 var section = footerNavSections[i]; |
| 110 initFooterSection(section); | 113 initFooterSection(section); |
| 111 } | 114 } |
| 112 } | 115 } |
| 113 | 116 |
| 114 initLanguageSelection(); | 117 initLanguageSelection(); |
| 115 initMenu(); | 118 initMenu(); |
| 116 initFooter(); | 119 initFooter(); |
| 117 })(); | 120 })(); |
| LEFT | RIGHT |