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.

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