Skip to content

Commit

Permalink
Merge pull request cmda-minor-web-1718#2 from fennadew/patch-1
Browse files Browse the repository at this point in the history
Code review Fenna
  • Loading branch information
Casburggraaf authored Feb 8, 2018
2 parents c372b06 + a58667c commit 25baad8
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions app/static/app.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
// 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));
}

// 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();
Expand Down

0 comments on commit 25baad8

Please sign in to comment.