diff --git a/app/static/app.js b/app/static/app.js index 62944fe3..7587ab62 100644 --- a/app/static/app.js +++ b/app/static/app.js @@ -1,16 +1,16 @@ // Create local scope (function() { //Init Aplication - var app = { - init: function() { + const app = { + init() { routers.init(); }, rootElement: document.body }; // Handle routes and states - var routers = { - init: function() { + const routers = { + init() { // Check if the window already has a hash and change active sections corspodending the hash if (window.location.hash) { sections.toggle(location.hash.substr(1)); @@ -18,25 +18,25 @@ // Listing to hashchange window.addEventListener("hashchange",function(){ - var route = location.hash.substr(1); + let route = location.hash.substr(1); sections.toggle(route); }); } - } + }; // Render / toggle sections - var sections = { + const sections = { sections: app.rootElement.querySelectorAll("body>section"), - toggle: function(route) { - for (let i = 0; i < this.sections.length; i++) { - this.sections[i].classList.remove("active"); + toggle(route) { + this.sections.forEach(function(el) { + el.classList.remove("active"); // Checking if the id is the same as the route - if (this.sections[i].id == route) { - this.sections[i].classList.add("active"); + if (el.id === route) { + el.classList.add("active"); } - } + }); } - } + }; // Start the Aplication app.init();