summaryrefslogtreecommitdiff
path: root/docs/js/site.js
blob: df9d657368aedc4117059a09be37cf92a3ad3a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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')
  }
  preload('img/pause-inv.png')
  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)
  toArray(document.querySelectorAll('.menu a')).forEach(a => {
    a.addEventListener("click", e => {
      e.preventDefault()
      sounds.play('click')
      navigateHash(e.target.href)
    })
  })
  function navigateHash(url){
    if (is_mobile) {
      player.hidePlaylist()
    }
    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 || ""
  }
  function preload(src) {
    const img = new Image
    img.src = src
  }
  return {
    navigateHash: navigateHash
  }
})()