Compare commits
No commits in common. "4255b002b9558a0cc932e445c7659661e7f17b2d" and "6edd1bcb3ed8ab572cdbdcdfd137109c3d0542ed" have entirely different histories.
4255b002b9
...
6edd1bcb3e
2 changed files with 22 additions and 15 deletions
|
|
@ -9,7 +9,8 @@ export const modal = content => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Display {
|
export class Display {
|
||||||
constructor(dispatch, target) {
|
constructor(baseUrl, dispatch, target) {
|
||||||
|
this.baseUrl = baseUrl
|
||||||
this.target = target
|
this.target = target
|
||||||
const findA = target => {
|
const findA = target => {
|
||||||
while (target.nodeName !== 'A') {
|
while (target.nodeName !== 'A') {
|
||||||
|
|
@ -18,13 +19,6 @@ export class Display {
|
||||||
}
|
}
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
target.addEventListener('click', e => {
|
|
||||||
let target = findA(e.target)
|
|
||||||
if (!target) return
|
|
||||||
window.history.pushState(null, "", target.href)
|
|
||||||
dispatch(target.getAttribute('href'))
|
|
||||||
e.preventDefault()
|
|
||||||
})
|
|
||||||
target.addEventListener('dragstart', e => {
|
target.addEventListener('dragstart', e => {
|
||||||
let target = findA(e.target)
|
let target = findA(e.target)
|
||||||
if (!target || !target.draggable) return
|
if (!target || !target.draggable) return
|
||||||
|
|
@ -57,9 +51,6 @@ export class Display {
|
||||||
0.5 // Damping
|
0.5 // Damping
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
renderIntro(intro) {
|
|
||||||
this.target.appendChild(modal(intro))
|
|
||||||
}
|
|
||||||
render(state) {
|
render(state) {
|
||||||
const target = document.createElement('div')
|
const target = document.createElement('div')
|
||||||
target.className = 'wrapper'
|
target.className = 'wrapper'
|
||||||
|
|
|
||||||
24
src/index.js
24
src/index.js
|
|
@ -1,6 +1,8 @@
|
||||||
import {Display} from './display.js'
|
import {modal, Display} from './display.js'
|
||||||
import intro from './intro.js'
|
import intro from './intro.js'
|
||||||
|
|
||||||
|
const target = document.createElement('div')
|
||||||
|
|
||||||
const state = {items: [], show: null, links: [] }
|
const state = {items: [], show: null, links: [] }
|
||||||
|
|
||||||
import {items} from './data.js'
|
import {items} from './data.js'
|
||||||
|
|
@ -49,9 +51,23 @@ const dispatch = target => {
|
||||||
window.onpopstate = e => {
|
window.onpopstate = e => {
|
||||||
dispatch(document.location.search)
|
dispatch(document.location.search)
|
||||||
}
|
}
|
||||||
const target = document.createElement('div')
|
const findA = target => {
|
||||||
display = new Display(dispatch, target)
|
while (target.nodeName !== 'A') {
|
||||||
|
target = target.parentNode
|
||||||
|
if (!target) return
|
||||||
|
}
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
document.body.addEventListener('click', e => {
|
||||||
|
let target = findA(e.target)
|
||||||
|
if (!target) return
|
||||||
|
window.history.pushState(null, "", target.href)
|
||||||
|
dispatch(target.getAttribute('href'))
|
||||||
|
e.preventDefault()
|
||||||
|
})
|
||||||
|
display = new Display('', dispatch, target)
|
||||||
|
|
||||||
if (document.location.search) dispatch(document.location.search)
|
if (document.location.search) dispatch(document.location.search)
|
||||||
else display.renderIntro(intro)
|
else document.body.appendChild(modal(intro))
|
||||||
document.body.appendChild(target)
|
document.body.appendChild(target)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue