2019-03-15 14:53:48 +00:00
|
|
|
// interaction
|
|
|
|
const primaryNav = document.querySelector('nav')
|
|
|
|
const menuItem = document.querySelector('#menuItem')
|
|
|
|
|
|
|
|
// TODO: (create voice class per button)
|
2019-03-16 16:16:24 +00:00
|
|
|
let menuVoices = []
|
2019-04-29 21:29:56 +00:00
|
|
|
let activePage
|
2019-03-16 16:16:24 +00:00
|
|
|
|
2019-03-18 22:18:52 +00:00
|
|
|
const subContent = (active) => {
|
|
|
|
let parent = document.querySelector(`\#${active}`)
|
|
|
|
let menu = parent.querySelector(`\.subMenu`)
|
2019-03-16 16:16:24 +00:00
|
|
|
if (menu) {
|
2019-03-18 22:18:52 +00:00
|
|
|
return { menu: menu, parent: parent }
|
2019-03-16 16:16:24 +00:00
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 22:18:52 +00:00
|
|
|
const subMenuListeners = (active) => {
|
|
|
|
let sc = subContent(active)
|
|
|
|
if (sc.menu) {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(`You are on ${active} w\/ a menu`)
|
2019-03-18 22:18:52 +00:00
|
|
|
for (let s of sc.menu.children) {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(s)
|
2019-03-18 22:18:52 +00:00
|
|
|
s.addEventListener('click', () => {
|
|
|
|
showContent(s.dataset.link, sc.parent)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(`${active} has no menu`)
|
2019-03-18 22:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const showContent = (section, parent = false) => {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(`section: ${section}\nparent: ${parent ? true : false}`)
|
2019-03-18 22:18:52 +00:00
|
|
|
let query
|
|
|
|
if (parent) {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(parent)
|
2019-03-18 22:18:52 +00:00
|
|
|
query = parent.querySelectorAll('.content')
|
|
|
|
className = `content page`
|
|
|
|
} else {
|
|
|
|
query = document.querySelectorAll(`.content`)
|
|
|
|
className = `content`
|
|
|
|
}
|
|
|
|
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(query)
|
2019-03-18 22:18:52 +00:00
|
|
|
|
|
|
|
for (let q of query) {
|
|
|
|
if (q.id == section) {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(`active id : ${section}`)
|
2019-03-18 22:18:52 +00:00
|
|
|
subQ = q
|
|
|
|
q.className = `${className} visible`
|
|
|
|
} else {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log('hiding divs')
|
2019-03-18 22:18:52 +00:00
|
|
|
q.className = `${className}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(content)
|
2019-03-18 22:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const findContent = (domElement, id) => {
|
|
|
|
for (let sect of domElement) {
|
|
|
|
if (id == sect.id) {
|
|
|
|
return sect
|
2019-03-16 16:16:24 +00:00
|
|
|
} else {
|
2019-03-18 22:18:52 +00:00
|
|
|
return null
|
2019-03-16 16:16:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 14:53:48 +00:00
|
|
|
|
2019-03-18 22:18:52 +00:00
|
|
|
// --> PRIMARY NAVIGATION
|
|
|
|
//
|
2019-03-15 14:53:48 +00:00
|
|
|
for (let c of primaryNav.children) {
|
|
|
|
// TODO: (create voice class per button)
|
2019-03-16 16:16:24 +00:00
|
|
|
menuVoices[c.dataset.link] = new Synth(audioEngine)
|
|
|
|
menuVoices[c.dataset.link].gain.connect(masterGain)
|
2019-03-15 14:53:48 +00:00
|
|
|
|
|
|
|
c.addEventListener('click', () => {
|
2019-03-16 16:16:24 +00:00
|
|
|
menuVoices[c.dataset.link].mod()
|
|
|
|
|
|
|
|
for (let _c of primaryNav.children) {
|
|
|
|
if (c === _c && c.dataset.link != '~') {
|
|
|
|
c.className = 'active'
|
2019-03-18 22:18:52 +00:00
|
|
|
activePage = c.dataset.link
|
2019-03-16 16:16:24 +00:00
|
|
|
} else {
|
|
|
|
_c.className = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 22:18:52 +00:00
|
|
|
// SHOW CONTENT FUNCTION
|
|
|
|
showContent(c.dataset.link)
|
|
|
|
|
|
|
|
// subPage Render
|
|
|
|
subMenuListeners(c.dataset.link)
|
2019-03-15 14:53:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
c.addEventListener('mouseenter', () => {
|
2019-04-29 21:29:56 +00:00
|
|
|
if (c.dataset.link == '~') {
|
|
|
|
menuItem.textContent = '\u003C\u007E'
|
|
|
|
} else {
|
|
|
|
menuItem.textContent = c.dataset.link
|
|
|
|
}
|
2019-03-15 14:53:48 +00:00
|
|
|
menuItem.className = 'active'
|
2019-03-16 16:16:24 +00:00
|
|
|
menuVoices[c.dataset.link].noteOn()
|
2019-03-15 14:53:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
c.addEventListener('mouseout', () => {
|
|
|
|
menuItem.className = 'inactive'
|
2019-03-16 16:16:24 +00:00
|
|
|
menuVoices[c.dataset.link].noteOff()
|
2019-03-15 14:53:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
menuItem.addEventListener('transitionend', () => {
|
|
|
|
if (menuItem.className == 'inactive') {
|
|
|
|
menuItem.innerHTML = ''
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-03-18 22:18:52 +00:00
|
|
|
|
|
|
|
// --> SECONDARY NAVIGATION
|
|
|
|
//
|
|
|
|
if (activePage) {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(activePage)
|
2019-03-18 22:18:52 +00:00
|
|
|
for (let s of subContent(activePage).menu.children) {
|
|
|
|
s.addEventListener('click', () => {
|
2019-04-29 21:29:56 +00:00
|
|
|
// console.log(`sub menu click \: ${s.dataset.link}`)
|
2019-03-18 22:18:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|