From 957d0f2b09137740a8acf0b3807a1299fac13d40 Mon Sep 17 00:00:00 2001 From: fennadew Date: Thu, 8 Feb 2018 16:44:00 +0100 Subject: [PATCH 1/2] test --- test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test diff --git a/test b/test new file mode 100644 index 00000000..9daeafb9 --- /dev/null +++ b/test @@ -0,0 +1 @@ +test From a58667c4ec70f945c0ff2acc1ce85139327ba61d Mon Sep 17 00:00:00 2001 From: Fenna Date: Thu, 8 Feb 2018 16:58:35 +0100 Subject: [PATCH 2/2] code review --- app/static/app.js | 28 ++++++++++++++-------------- test | 1 - 2 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 test 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(); diff --git a/test b/test deleted file mode 100644 index 9daeafb9..00000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -test