2018-03-14 07:16:21 +00:00
|
|
|
// I suck at JS okay, don't judge. I know this is horrendous. Heavy copy/paste junk.
|
|
|
|
// Code is commented more than it needs to be because I'm still learning and the comments are basically post-it notes to help me remember.
|
|
|
|
// Ajax is entirely pointless for this site, but I did it to learn.
|
|
|
|
|
|
|
|
// Find all our buttons
|
|
|
|
const button1 = document.getElementById('button1');
|
|
|
|
const button2 = document.getElementById('button2');
|
|
|
|
const button3 = document.getElementById('button3');
|
|
|
|
|
|
|
|
// Create variables that will get populated by loadContent() later
|
2018-03-14 12:46:37 +00:00
|
|
|
var page1 = "pages/about.html";
|
2018-03-14 13:37:07 +00:00
|
|
|
var page2 = "pages/social.html";
|
2018-03-14 19:12:52 +00:00
|
|
|
var page3 = "pages/projects.html";
|
2018-03-14 12:46:37 +00:00
|
|
|
|
2018-03-14 13:07:48 +00:00
|
|
|
const contentArea = document.getElementById("page");
|
|
|
|
|
2018-03-14 07:16:21 +00:00
|
|
|
// Very bad function to get rid of the "active" class wherever it is atm
|
|
|
|
function resetButtons() {
|
|
|
|
button1.className = "nav-button";
|
|
|
|
button2.className = "nav-button";
|
|
|
|
button3.className = "nav-button";
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:07:48 +00:00
|
|
|
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) {
|
2018-03-14 07:16:21 +00:00
|
|
|
resetButtons();
|
|
|
|
navbutt.className += " active";
|
2018-03-15 15:45:40 +00:00
|
|
|
console.log("there's absolutely no reason for this site to use ajax lmao");
|
2018-03-14 13:07:48 +00:00
|
|
|
httpGet(source, setContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setContent(target, payload) {
|
|
|
|
target.innerHTML = payload;
|
2018-03-14 07:16:21 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 12:46:37 +00:00
|
|
|
function initialContent() {
|
2018-03-14 07:16:21 +00:00
|
|
|
|
|
|
|
// Slap on all the event listeners
|
|
|
|
button1.addEventListener('click', function() {
|
2018-03-14 13:07:48 +00:00
|
|
|
activatePage(button1, page1);
|
2018-03-14 07:16:21 +00:00
|
|
|
}, false);
|
|
|
|
button2.addEventListener('click', function() {
|
2018-03-14 13:07:48 +00:00
|
|
|
activatePage(button2, page2);
|
2018-03-14 07:16:21 +00:00
|
|
|
}, false);
|
|
|
|
button3.addEventListener('click', function() {
|
2018-03-14 13:07:48 +00:00
|
|
|
activatePage(button3, page3);
|
2018-03-14 07:16:21 +00:00
|
|
|
}, false);
|
2018-03-15 07:34:33 +00:00
|
|
|
|
2018-08-31 11:00:36 +00:00
|
|
|
setContent(contentArea, '<p class="initial-text"><i class="fa fa-arrow-up" aria-hidden="true"></i><br>Click a button!</p>');
|
2018-03-14 09:08:50 +00:00
|
|
|
}
|
2018-03-15 15:28:22 +00:00
|
|
|
|
2018-03-15 15:31:10 +00:00
|
|
|
initialContent();
|