There are some scripts that are to run on the home page and they are living in the wrong places. The first one is the clock script in the index.html HEAD SCRIPT element. We don't want that there. It only runs in the home page, and it isn't in our separation of concerns methodology. So cut the script out of the index script tag and paste it into the home.js file.
In the routing.js file there is a function called home.loadSections. This is also outside of its home. When we created it, we noted it with a TODO to move later. So now cut it out and paste it into the home.js file.
Now the /app/home/home.js file has the full home object including home.dayArray, home.monthArray, the home.getTime function, the home.correctDigit function, and the home.loadSections function. It should be followed by calls to the home.loadSections and home.getTime functions.
The home function should look like the following example without much more modification:
console.log(id)
var home = {};
home.dayArray = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
home.monthArray = ["January","February","March","April","May","June","July","August","September","October","November","December"];
home.getTime = function(){
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
var d=home.dayArray[today.getDay()];
var mo=home.monthArray[today.getMonth()];
var y=today.getFullYear();
m = home.correctDigit(m);
s = home.correctDigit(s);
document.getElementById('time').innerHTML = "<br><h1 class='large'>"+h+":"+m+":"+s+"</h1> <span class='dark'>"+d+",</span class='dark'> <span class='dark'>"+mo+"</span> <span class='dark'>"+y+"</span>";
var t = setTimeout(function(){home.getTime()},500);
};
home.correctDigit = function(i){
if (i<10)i = "0" + i; // add zero in front of numbers < 10
return i;
};
home.loadSections = function() {
for (i = 0; i < routing.routesArray.length; i++) {
routing.routesArray[i].callBack.call();
services.getPage(pageRoute.partial,routing.routesArray[i].path,services.routing.writeHTML);
}
};
home.getTime();
home.loadSections();