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