Update 'main.js'
This commit is contained in:
parent
9f8d406c58
commit
9831b9fc8d
57
main.js
57
main.js
|
@ -1,33 +1,42 @@
|
||||||
// I suck at JS okay, don't judge. I know this is horrendous.
|
// I suck at JS okay, don't judge. I know this is horrendous. Heavy copy/paste junk.
|
||||||
// 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.
|
||||||
|
|
||||||
var button1 = document.getElementById('button1');
|
// Find all our buttons
|
||||||
var button2 = document.getElementById('button2');
|
const button1 = document.getElementById('button1');
|
||||||
var button3 = document.getElementById('button3');
|
const button2 = document.getElementById('button2');
|
||||||
|
const button3 = document.getElementById('button3');
|
||||||
|
|
||||||
contsrc = "file:///H:/Side projects/Site/";
|
// Make the base URL a variable because it's easier if I ever move the site
|
||||||
|
const baseUrl = "file:///H:/Side projects/Site/";
|
||||||
|
|
||||||
var payload1 = "Hellow";
|
// Create variables that will get populated by loadContent() later
|
||||||
//var payload2 = new Promise(function(resolve) {
|
var payload1;
|
||||||
// setTimeout(resolve(httpGet(contsrc + "pages/about.html")), 100, 'foo')});
|
var payload2;
|
||||||
var payload2 = "Ayy";
|
var payload3;
|
||||||
var payload3 = "lmao3";
|
|
||||||
|
|
||||||
|
// Very bad function to get rid of the "active" class wherever it is atm
|
||||||
function resetButtons() {
|
function resetButtons() {
|
||||||
button1.className = "nav-button";
|
button1.className = "nav-button";
|
||||||
button2.className = "nav-button";
|
button2.className = "nav-button";
|
||||||
button3.className = "nav-button";
|
button3.className = "nav-button";
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpGet(myUrl) {
|
// Fetch all the page contents
|
||||||
var request = new XMLHttpRequest();
|
async function loadContent(baseUrl) {
|
||||||
|
const http1 = fetch(baseUrl + "pages/about.html");
|
||||||
|
const http2 = fetch(baseUrl + "pages/about.html");
|
||||||
|
const http3 = fetch(baseUrl + "pages/about.html");
|
||||||
|
|
||||||
request.open('GET', myUrl, true);
|
const requests = [http1, http2, http3];
|
||||||
request.send(null);
|
|
||||||
|
|
||||||
if (request.status == 200) {
|
const responses = await Promise.all(requests);
|
||||||
return request.responseText;
|
|
||||||
|
for (let response of responses) {
|
||||||
|
console.log("Loaded data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return responses
|
||||||
}
|
}
|
||||||
|
|
||||||
function setContent(navbutt, payload) {
|
function setContent(navbutt, payload) {
|
||||||
|
@ -36,18 +45,26 @@ function setContent(navbutt, payload) {
|
||||||
navbutt.className += " active";
|
navbutt.className += " active";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initialContent() {
|
||||||
|
|
||||||
|
// Get the HTML we need
|
||||||
|
var contents = loadContent();
|
||||||
|
|
||||||
|
payload1 = contents[0];
|
||||||
|
payload2 = contents[1];
|
||||||
|
payload3 = contents[2];
|
||||||
|
|
||||||
|
// Slap on all the event listeners
|
||||||
button1.addEventListener('click', function() {
|
button1.addEventListener('click', function() {
|
||||||
setContent(button1, payload1);
|
setContent(button1, payload1);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
button2.addEventListener('click', function() {
|
button2.addEventListener('click', function() {
|
||||||
setContent(button2, payload2);
|
setContent(button2, payload2);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
button3.addEventListener('click', function() {
|
button3.addEventListener('click', function() {
|
||||||
setContent(button3, payload3);
|
setContent(button3, payload3);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
function initialContent() {
|
// And finally enable the first tab
|
||||||
setContent(button1, payload1);
|
setContent(button1, payload1);
|
||||||
}
|
}
|
Loading…
Reference in New Issue