From b9426877cfe30b74d03ec756b93bd047c402d7ad Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 25 Nov 2018 18:44:06 +0100 Subject: we have site --- docs/js/site.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 docs/js/site.js (limited to 'docs/js/site.js') diff --git a/docs/js/site.js b/docs/js/site.js new file mode 100644 index 0000000..59d09f9 --- /dev/null +++ b/docs/js/site.js @@ -0,0 +1,48 @@ +const site = (function(){ + let section + let links = toArray(document.querySelectorAll('.menu a')) + let time = new Date() + let hour = time.getHours() + if (hour < 8 || hour > 16) { + document.body.parentNode.classList.add('night') + } else { + document.body.parentNode.classList.add('day') + } + setTimeout(() => { + document.body.classList.remove('loading') + navigateHash(window.location.hash) + const email = atob("eGVuYXZlY3RyYTkwOUBnbWFpbC5jb20=") + const twitter = atob("dmVjdHJheGVuYQ==") + document.querySelector("#email_addr").href = 'mailto:' + email + document.querySelector("#email_addr").innerHTML = email + document.querySelector("#twitter_addr").innerHTML = twitter + document.querySelector("#twitter_addr").href = 'https://twitter.com/' + twitter + }, 0) + function navigateHash(url){ + let new_section = url.split('#')[1] + if (section) { + document.body.classList.remove(section) + links.forEach(link => link.classList.remove('active')) + } + if (new_section && new_section !== 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 + } + // window.location.hash = section || "" + } + toArray(document.querySelectorAll('.menu a')).forEach(a => { + a.addEventListener("click", e => { + e.preventDefault() + sounds.play('click') + navigateHash(e.target.href) + }) + }) + function preload(src) { + const img = new Image + img.src = src + } + preload('img/pause-inv.png') +})() -- cgit v1.2.3-70-g09d2