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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | static/js/vendor/classList.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: static/js/main.js
===================================================================
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -1,74 +1,33 @@
"use strict";
(function()
{
- function escapeRegExp(string)
- {
- return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
- }
-
- function hasClass(element, className)
- {
- return !!element.className.match("\\b" + escapeRegExp(className) + "\\b");
- }
-
- function addClass(element, className)
- {
- if (hasClass(element, className))
- return;
-
- if (element.className.length)
- element.className += " ";
- element.className += className;
- }
-
- function removeClass(element, className)
- {
- var regExp = new RegExp("\\s*\\b" + escapeRegExp(className) + "\\b\\s*");
- element.className = element.className.replace(regExp, "");
- }
-
- function toggleClass(element, className)
- {
- if (hasClass(element, className))
- removeClass(element, className);
- else
- addClass(element, className);
- }
-
- function stopPropagation(event)
- {
- if (typeof window.event !== "undefined"
- && typeof window.event.cancelBubble !== "undefined")
- window.event.cancelBubble = true;
- else
- event.stopPropagation();
- }
-
function initLanguageSelection()
{
var locale = document.getElementById("navbar-locale-selected");
// skip if page does not have language selection (EG: blog)
- if (!locale)
- return;
+ if (!locale) return;
- locale.onclick = function()
+ locale.addEventListener("click", function()
{
- toggleClass(document.getElementById("navbar-locale-menu"), "visible");
- };
+ document.getElementById("navbar-locale-menu")
+ .classList.toggle("visible");
+ }, false);
}
function navigationClick(event)
{
- toggleClass(document.getElementById("navbar-menu"), "visible");
+ document.getElementById("navbar-menu")
+ .classList.toggle("visible");
}
function initMenu()
{
- document.getElementById("navbar-menu-toggle").onclick = navigationClick;
+ document.getElementById("navbar-menu-toggle")
+ .addEventListener("click", navigationClick, false);
}
initLanguageSelection();
initMenu();
})();
« 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