Please for the love of god, work
This commit is contained in:
parent
00840634c0
commit
e35258417e
27
main.js
27
main.js
|
@ -12,6 +12,8 @@ var page1 = "pages/about.html";
|
||||||
var page2 = "pages/about.html";
|
var page2 = "pages/about.html";
|
||||||
var page3 = "pages/about.html";
|
var page3 = "pages/about.html";
|
||||||
|
|
||||||
|
const contentArea = document.getElementById("page");
|
||||||
|
|
||||||
const spinner = '<i class="fas fa-spinner loading"></i>';
|
const spinner = '<i class="fas fa-spinner loading"></i>';
|
||||||
|
|
||||||
// Very bad function to get rid of the "active" class wherever it is atm
|
// Very bad function to get rid of the "active" class wherever it is atm
|
||||||
|
@ -21,22 +23,37 @@ function resetButtons() {
|
||||||
button3.className = "nav-button";
|
button3.className = "nav-button";
|
||||||
}
|
}
|
||||||
|
|
||||||
function setContent(navbutt, payload) {
|
function httpGet(myUrl, callback) {
|
||||||
document.getElementById("page").innerHTML = spinner;
|
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();
|
resetButtons();
|
||||||
navbutt.className += " active";
|
navbutt.className += " active";
|
||||||
|
httpGet(source, setContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setContent(target, payload) {
|
||||||
|
target.innerHTML = payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialContent() {
|
function initialContent() {
|
||||||
|
|
||||||
// Slap on all the event listeners
|
// Slap on all the event listeners
|
||||||
button1.addEventListener('click', function() {
|
button1.addEventListener('click', function() {
|
||||||
setContent(button1, page1);
|
activatePage(button1, page1);
|
||||||
}, false);
|
}, false);
|
||||||
button2.addEventListener('click', function() {
|
button2.addEventListener('click', function() {
|
||||||
setContent(button2, page2);
|
activatePage(button2, page2);
|
||||||
}, false);
|
}, false);
|
||||||
button3.addEventListener('click', function() {
|
button3.addEventListener('click', function() {
|
||||||
setContent(button3, page3);
|
activatePage(button3, page3);
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue