From 550a1e1debdc35337262a0b78b51e4dbf7aa02a6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 17 Feb 2021 16:27:16 +0100 Subject: fix js --- docs/assets/js/site.js | 91 ++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/docs/assets/js/site.js b/docs/assets/js/site.js index 6549405..f93b47d 100644 --- a/docs/assets/js/site.js +++ b/docs/assets/js/site.js @@ -1,8 +1,8 @@ -const site = (function(){ - let section - let links = toArray(document.querySelectorAll('.menu a')) - let time = new Date() - let hour = time.getHours() +const site = (function () { + let section; + let links = toArray(document.querySelectorAll(".menu a")); + let time = new Date(); + let hour = time.getHours(); let quotes = [ "So, are soft-synths as nasty as they say?", "Ah, a hardware person, I get it.", @@ -12,62 +12,67 @@ const site = (function(){ "Get in there, sweep the filter and give yourself a pat on the back. In that order.", "Not a museum. Move along.", "I've got to get out of this studio and back out there.", - ] + ]; if (hour < 8 || hour > 16) { - document.body.parentNode.classList.add('night') + document.body.parentNode.classList.add("night"); } else { - document.body.parentNode.classList.add('day') + document.body.parentNode.classList.add("day"); } - preload('img/pause-inv.png') + preload("/assets/img/pause-inv.png"); setTimeout(() => { - document.body.classList.remove('loading') + document.body.classList.remove("loading"); // navigateHash(window.location.hash) - const email = atob("eGVuYXZlY3RyYTkwOUBnbWFpbC5jb20=") - document.querySelector("#email_addr").href = 'mailto:' + email - document.querySelector("#email_addr").innerHTML = email - }, 0) - toArray(document.querySelectorAll('.menu a')).forEach(a => { - a.addEventListener("click", e => { - if (e.target.getAttribute('href').indexOf('#') === -1) { - sounds.play('click') - return + const email = atob("eGVuYXZlY3RyYTkwOUBnbWFpbC5jb20="); + document.querySelector("#email_addr").href = "mailto:" + email; + document.querySelector("#email_addr").innerHTML = email; + }, 0); + toArray(document.querySelectorAll(".menu a")).forEach((a) => { + a.addEventListener("click", (e) => { + const href = e.target.getAttribute("href") || ""; + if (href.indexOf("#") === -1) { + sounds.play("click"); + return; } - e.preventDefault() - sounds.play('click') - console.log(e.target) - if (e.target.nodeName.toLowerCase() !== 'a') { - navigateHash(e.target.parentNode.href) + e.preventDefault(); + sounds.play("click"); + console.log(e.target); + if (e.target.nodeName.toLowerCase() !== "a") { + navigateHash(e.target.parentNode.href); } else { - navigateHash(e.target.href) + navigateHash(e.target.href); } - }) - }) - function navigateHash(url){ + }); + }); + function navigateHash(url) { if (is_mobile) { - player.hidePlaylist() + player.hidePlaylist(); } - let new_section = (url || "").split('#')[1] + let new_section = (url || "").split("#")[1]; if (section) { - document.body.classList.remove(section) - links.forEach(link => link.classList.remove('active')) + document.body.classList.remove(section); + links.forEach((link) => link.classList.remove("active")); } if (new_section && new_section !== section) { - if (new_section.match('hardware')) { - document.querySelector('#quote').innerHTML = choice(quotes) + if (new_section.match("hardware")) { + document.querySelector("#quote").innerHTML = choice(quotes); } - document.body.classList.add(new_section) - links.forEach(link => link.getAttribute('href').match(new_section) && link.classList.add('active')) - section = new_section + document.body.classList.add(new_section); + links.forEach( + (link) => + link.getAttribute("href").match(new_section) && + link.classList.add("active") + ); + section = new_section; } else { - section = null + section = null; } // window.location.hash = section || "" } function preload(src) { - const img = new Image - img.src = src + const img = new Image(); + img.src = src; } return { - navigateHash: navigateHash - } -})() + navigateHash: navigateHash, + }; +})(); -- cgit v1.2.3-70-g09d2