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

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

Issue 29587659: Noissue - Added classList polyfill and refactored main.js (Closed) Base URL: https://bitbucket.org/adblockplus/adblockplus.org
Patch Set: Created Oct. 24, 2017, 2:20 p.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 | « no previous file | static/js/vendor/classList.js » ('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)
6 {
7 return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
8 }
9
10 function hasClass(element, className)
11 {
12 return !!element.className.match("\\b" + escapeRegExp(className) + "\\b");
13 }
14
15 function addClass(element, className)
16 {
17 if (hasClass(element, className))
18 return;
19
20 if (element.className.length)
21 element.className += " ";
22 element.className += className;
23 }
24
25 function removeClass(element, className)
26 {
27 var regExp = new RegExp("\\s*\\b" + escapeRegExp(className) + "\\b\\s*");
28 element.className = element.className.replace(regExp, "");
29 }
30
31 function toggleClass(element, className)
32 {
33 if (hasClass(element, className))
34 removeClass(element, className);
35 else
36 addClass(element, className);
37 }
38
39 function stopPropagation(event)
40 {
41 if (typeof window.event !== "undefined"
42 && typeof window.event.cancelBubble !== "undefined")
43 window.event.cancelBubble = true;
44 else
45 event.stopPropagation();
46 }
47
48 function initLanguageSelection() 5 function initLanguageSelection()
49 { 6 {
50 var locale = document.getElementById("navbar-locale-selected"); 7 var locale = document.getElementById("navbar-locale-selected");
51 8
52 // skip if page does not have language selection (EG: blog) 9 // skip if page does not have language selection (EG: blog)
53 if (!locale) 10 if (!locale) return;
54 return;
55 11
56 locale.onclick = function() 12 locale.addEventListener("click", function()
57 { 13 {
58 toggleClass(document.getElementById("navbar-locale-menu"), "visible"); 14 document.getElementById("navbar-locale-menu")
59 }; 15 .classList.toggle("visible");
16 }, false);
60 } 17 }
61 18
62 function navigationClick(event) 19 function navigationClick(event)
63 { 20 {
64 toggleClass(document.getElementById("navbar-menu"), "visible"); 21 document.getElementById("navbar-menu")
22 .classList.toggle("visible");
65 } 23 }
66 24
67 function initMenu() 25 function initMenu()
68 { 26 {
69 document.getElementById("navbar-menu-toggle").onclick = navigationClick; 27 document.getElementById("navbar-menu-toggle")
28 .addEventListener("click", navigationClick, false);
70 } 29 }
71 30
72 initLanguageSelection(); 31 initLanguageSelection();
73 initMenu(); 32 initMenu();
74 })(); 33 })();
OLDNEW
« no previous file with comments | « no previous file | static/js/vendor/classList.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld