Please for the love of god, work

This commit is contained in:
Dominik V. Salonen 2018-03-14 14:07:48 +01:00
parent 00840634c0
commit e35258417e
1 changed files with 22 additions and 5 deletions

27
main.js
View File

@ -12,6 +12,8 @@ var page1 = "pages/about.html";
var page2 = "pages/about.html";
var page3 = "pages/about.html";
const contentArea = document.getElementById("page");
const spinner = '<i class="fas fa-spinner loading"></i>';
// Very bad function to get rid of the "active" class wherever it is atm
@ -21,22 +23,37 @@ function resetButtons() {
button3.className = "nav-button";
}
function setContent(navbutt, payload) {
document.getElementById("page").innerHTML = spinner;
function httpGet(myUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(contentArea, xmlHttp.responseText);
}
xmlHttp.open("GET", myUrl, true);
xmlHttp.send(null);
}
function activatePage(navbutt, source) {
contentArea.innerHTML = spinner;
resetButtons();
navbutt.className += " active";
httpGet(source, setContent);
}
function setContent(target, payload) {
target.innerHTML = payload;
}
function initialContent() {
// Slap on all the event listeners
button1.addEventListener('click', function() {
setContent(button1, page1);
activatePage(button1, page1);
}, false);
button2.addEventListener('click', function() {
setContent(button2, page2);
activatePage(button2, page2);
}, false);
button3.addEventListener('click', function() {
setContent(button3, page3);
activatePage(button3, page3);
}, false);
}