Commit 0d593c7f authored by Dominik V. Salonen's avatar Dominik V. Salonen Committed by Dominik V. Salonen

I think I've finally figured out how JS is supposed to be written. So gonna...

I think I've finally figured out how JS is supposed to be written. So gonna try changing courses to a less retarded solution.
parent fc3c7026
......@@ -2,6 +2,7 @@
<head>
<title>Quad's site</title>
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" />
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<link href="style.css" rel="stylesheet" />
</head>
<body onload="javascript:initialContent();">
......
......@@ -7,13 +7,12 @@ const button1 = document.getElementById('button1');
const button2 = document.getElementById('button2');
const button3 = document.getElementById('button3');
// Make the base URL a variable because it's easier if I ever move the site
const baseUrl = "https://quad.moe/test/";
// Create variables that will get populated by loadContent() later
var payload1;
var payload2;
var payload3;
var page1 = "pages/about.html";
var page2 = "pages/about.html";
var page3 = "pages/about.html";
const spinner = '<i class="fas fa-spinner loading"></i>';
// Very bad function to get rid of the "active" class wherever it is atm
function resetButtons() {
......@@ -22,57 +21,22 @@ function resetButtons() {
button3.className = "nav-button";
}
// Fetch all the page contents
async function loadContent(baseUrl) {
const http1 = fetch("pages/about.html");
const http2 = fetch("pages/about.html");
const http3 = fetch("pages/about.html");
const requests = [http1, http2, http3];
const responses = await Promise.all(requests);
return responses;
}
function setContent(navbutt, payload) {
document.getElementById("page").innerHTML = payload;
document.getElementById("page").innerHTML = spinner;
resetButtons();
navbutt.className += " active";
}
function initialContent() {
// Get the HTML we need
// This returns Response { type: "basic", url: "https://example.com", redirected: false... etc.
loadContent().then((res) => {console.log(res);});
// This returns a Promise object with <state>: "pending"
loadContent().then((res) => {console.log(res[0].text());});
contents = loadContent();
// Can't figure out how to make sure that each web request in loadContent()
// has returned proper HTML before it actually proceeds executing the rest of this funciton
// Then store the text only for later use
payload1 = contents[0].text();
payload2 = contents[1].text();
payload3 = contents[2].text();
console.log(payload1);
function initialContent() {
// Slap on all the event listeners
button1.addEventListener('click', function() {
setContent(button1, payload1);
setContent(button1, page1);
}, false);
button2.addEventListener('click', function() {
setContent(button2, payload2);
setContent(button2, page2);
}, false);
button3.addEventListener('click', function() {
setContent(button3, payload3);
setContent(button3, page3);
}, false);
// And finally enable the first tab
setContent(button1, payload1);
}
......@@ -98,6 +98,14 @@ h1, h2, h3, h4, h5, p {
margin-bottom: 50px;
}
.loading {
font-size: 26pt;
color: #FF5555;
text-align: center;
margin-top: 50px;
margin-bottom: 50px;
}
.notice {
color: #3b3b3b;
text-align: right;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment