2019-12-02 12:22:45 +00:00
|
|
|
import {Synth} from '/assets/js/synth.js'
|
|
|
|
|
|
|
|
// audio for events
|
|
|
|
// AUDIO SETUP
|
|
|
|
const audioEngine = new (window.AudioContext || window.webkitAudioContext)()
|
|
|
|
audioEngine.suspend()
|
|
|
|
const masterGain = audioEngine.createGain()
|
|
|
|
const audioEl = document.querySelector('#audioToggle')
|
2019-12-02 17:11:32 +00:00
|
|
|
let audioAllowed = true
|
2019-12-02 12:22:45 +00:00
|
|
|
|
|
|
|
masterGain.gain.value = 0.9
|
|
|
|
masterGain.connect(audioEngine.destination)
|
|
|
|
|
|
|
|
const audioToggle = () => {
|
2019-12-02 17:11:32 +00:00
|
|
|
audioEl.classList.toggle('active')
|
2019-12-02 12:22:45 +00:00
|
|
|
if (audioEngine.state == 'suspended') {
|
|
|
|
audioEngine.resume()
|
2019-12-02 17:11:32 +00:00
|
|
|
audioAllowed = true
|
2019-12-02 12:22:45 +00:00
|
|
|
} else {
|
|
|
|
audioEngine.suspend()
|
2019-12-02 17:11:32 +00:00
|
|
|
audioAllowed = false
|
2019-12-02 12:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 15:42:11 +00:00
|
|
|
const audioEnable = () => {
|
2019-12-02 17:11:32 +00:00
|
|
|
if (audioEngine.state == 'suspended' && audioAllowed) {
|
|
|
|
audioEngine.resume()
|
|
|
|
}
|
2019-12-02 15:42:11 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
audioEl.addEventListener('click', audioToggle)
|
2019-12-02 12:22:45 +00:00
|
|
|
|
|
|
|
// NAVIGATION
|
2019-12-02 17:11:32 +00:00
|
|
|
let primaryNav = document.querySelectorAll('nav#primary>span')
|
2019-12-02 12:22:45 +00:00
|
|
|
let subNav = document.querySelector('nav#sub')
|
|
|
|
let menuItem = document.querySelector('#menuItem')
|
|
|
|
|
|
|
|
let menuVoices = []
|
|
|
|
|
|
|
|
for (let n of primaryNav) {
|
2019-12-02 17:11:32 +00:00
|
|
|
// remove shitty firefox span spacing
|
2019-12-02 12:22:45 +00:00
|
|
|
n.nextSibling.parentNode.removeChild(n.nextSibling)
|
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
// create synthVoices per navItem
|
2019-12-02 12:22:45 +00:00
|
|
|
menuVoices[n.dataset.link] = new Synth(audioEngine)
|
|
|
|
menuVoices[n.dataset.link].gain.connect(masterGain)
|
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
// unsuspend sound on mouseenter
|
|
|
|
n.addEventListener('mouseenter', audioEnable)
|
2019-12-02 15:42:11 +00:00
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
// primary navigation click events
|
2019-12-02 12:22:45 +00:00
|
|
|
n.addEventListener('click', (e) => {
|
|
|
|
for (let _n of primaryNav) {
|
|
|
|
if (n === _n && n.dataset.link != '~') {
|
|
|
|
n.classList.toggle('active')
|
|
|
|
} else if (n.dataset.link == '~') {
|
|
|
|
window.location.href = '/'
|
|
|
|
} else {
|
|
|
|
_n.classList.remove('active')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// subnav is nav element
|
|
|
|
if (!subNav.classList.contains('active')) {
|
|
|
|
subNav.classList.add('active')
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let s of subNav.children) {
|
|
|
|
if (s.id == n.dataset.link) {
|
|
|
|
s.classList.add('active')
|
|
|
|
} else {
|
|
|
|
s.classList.remove('active')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
// mouseover on primary nav for big botom text
|
2019-12-02 12:22:45 +00:00
|
|
|
n.addEventListener('mouseenter', () => {
|
|
|
|
if (n.dataset.link == '~') {
|
|
|
|
menuItem.textContent = '\u003C\u007E'
|
|
|
|
} else {
|
|
|
|
menuItem.textContent = n.dataset.link
|
|
|
|
}
|
|
|
|
menuItem.className = 'active'
|
|
|
|
menuVoices[n.dataset.link].noteOn()
|
|
|
|
})
|
|
|
|
|
|
|
|
n.addEventListener('mouseout', () => {
|
|
|
|
menuItem.className = 'inactive'
|
|
|
|
menuVoices[n.dataset.link].noteOff()
|
|
|
|
})
|
2019-12-02 17:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SCROLL TO TOP NAVIGATION
|
|
|
|
const toTop = document.querySelector('nav#toTop')
|
2019-12-02 12:22:45 +00:00
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
toTop.addEventListener('click', (e) => {
|
|
|
|
window.scrollTo(0,0)
|
|
|
|
})
|
2019-12-02 12:22:45 +00:00
|
|
|
|
2019-12-02 17:11:32 +00:00
|
|
|
window.addEventListener('scroll', (e) => {
|
|
|
|
let scrollY = window.scrollY
|
|
|
|
if (scrollY > 50) {
|
|
|
|
toTop.classList.add('active')
|
|
|
|
} else {
|
|
|
|
toTop.classList.remove('active')
|
|
|
|
}
|
|
|
|
})
|