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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. import {Display} from './display.js'
  2. const target = document.createElement('div')
  3. const state = {items: [], show: null, links: [] }
  4. const imgs = ['Dienstmädchen2.svg', 'Rucksack2.svg', 'Theater2.svg', 'UnskilledLabour2.svg', 'weben.svg']
  5. for (let i = 0; i < imgs.length; ++i) {
  6. state.items.push({id: i, state: 'face-down', img: imgs[i]})
  7. }
  8. class Actions {
  9. flip(id) {
  10. state.items[id].state = 'face-up'
  11. }
  12. show(id) {
  13. state.show = id
  14. }
  15. reset() {
  16. state.show = null
  17. }
  18. link(from, to) {
  19. state.links.push({id: state.links.length, from, to})
  20. }
  21. }
  22. const actions = new Actions
  23. let display
  24. const dispatch = target => {
  25. if (target.action) {
  26. actions[target.action](target.from, target.to)
  27. } else {
  28. const match = target.match(/\/([^/]+)\/([^/]+)/)
  29. if (match && Object.hasOwnProperty.call(Actions.prototype, match[2])) {
  30. actions[match[2]](match[1])
  31. } else actions.reset()
  32. }
  33. display.render(state)
  34. }
  35. window.onpopstate = e => {
  36. dispatch(document.location.search)
  37. }
  38. display = new Display('', dispatch, target)
  39. dispatch(document.location.search)
  40. document.body.appendChild(target)