From f5d0077521b36d12e56a5a04e62fcd745c473d1c Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Sun, 20 Sep 2020 23:14:52 +0200 Subject: [PATCH 1/2] Move intro rendering to display --- src/display.js | 10 ++++++++++ src/index.js | 22 +++------------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/display.js b/src/display.js index 0c438b3..c204d81 100644 --- a/src/display.js +++ b/src/display.js @@ -19,6 +19,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 +58,9 @@ export class Display { 0.5 // Damping ) } + renderIntro(intro) { + this.target.appendChild(modal(intro)) + } render(state) { const target = document.createElement('div') target.className = 'wrapper' diff --git a/src/index.js b/src/index.js index 41da339..fc00b71 100644 --- a/src/index.js +++ b/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() -}) +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) - From 4255b002b9558a0cc932e445c7659661e7f17b2d Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Sun, 20 Sep 2020 23:15:21 +0200 Subject: [PATCH 2/2] Remove unused baseUrl parameter --- src/display.js | 3 +-- src/index.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/display.js b/src/display.js index c204d81..5ea43c6 100644 --- a/src/display.js +++ b/src/display.js @@ -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') { diff --git a/src/index.js b/src/index.js index fc00b71..ef6aa1b 100644 --- a/src/index.js +++ b/src/index.js @@ -50,7 +50,7 @@ window.onpopstate = e => { dispatch(document.location.search) } const target = document.createElement('div') -display = new Display('', dispatch, target) +display = new Display(dispatch, target) if (document.location.search) dispatch(document.location.search) else display.renderIntro(intro)