You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.1 KiB

import {Display} from './display.js'
const target = document.createElement('div')
const state = {items: [], show: null, links: [] }
const imgs = ['Dienstmädchen2.svg', 'Rucksack2.svg', 'Theater2.svg', 'UnskilledLabour2.svg', 'weben.svg']
for (let i = 0; i < imgs.length; ++i) {
state.items.push({id: i, state: 'face-down', img: imgs[i]})
}
class Actions {
flip(id) {
state.items[id].state = 'face-up'
}
show(id) {
state.show = id
}
reset() {
state.show = null
}
link(from, to) {
state.links.push({id: state.links.length, from, to})
}
}
const actions = new Actions
let display
const dispatch = target => {
if (target.action) {
actions[target.action](target.from, target.to)
} else {
const match = target.match(/\/([^/]+)\/([^/]+)/)
if (match && Object.hasOwnProperty.call(Actions.prototype, match[2])) {
actions[match[2]](match[1])
} else actions.reset()
}
display.render(state)
}
window.onpopstate = e => {
dispatch(document.location.search)
}
display = new Display('', dispatch, target)
dispatch(document.location.search)
document.body.appendChild(target)