diff --git a/src/utils/modal.js b/src/utils/modal.js index adfc6e7..8a548ab 100644 --- a/src/utils/modal.js +++ b/src/utils/modal.js @@ -80,11 +80,21 @@ class RenderScripture { constructor(dialog) { this.dialog = dialog; - /*history.replaceState({dialog: false}, ''); + //history.replaceState({dialog: false}, ''); window.addEventListener('popstate', (evt) => { - console.log("popState", evt); - this.closeDialog(); - });*/ + if (this.dialog[0]?.open) { + this.closeDialog(); + } + }); + this.dialog[0]?.addEventListener('close', () => { + if (history.state && history.state.dialog) { + history.back(); + } + }); + this.dialog[0]?.addEventListener('cancel', (evt) => { + evt.preventDefault(); + history.back(); + }); if (hasLocalStorage()) { this.ls = true; @@ -109,8 +119,11 @@ class RenderScripture { } }); this.dialog[0]?.querySelector('button[data-close]')?.addEventListener('click', (evt) => { - evt.preventDefault(); - this.closeDialog(); + if (history.state?.dialog) { + history.back(); + } else { + this.closeDialog(); + } }); } @@ -128,12 +141,11 @@ class RenderScripture { .classList.remove('hidden'); this.buildTranslationList(this.sel); this.readScripture(refs); - //console.log("pushState()"); - /*history.pushState({ + history.pushState({ dialog: true, scripture: scripture.value, tx: this.translation - }, '', '#dialog');*/ + }, '', '#dialog'); } buildTranslationList(sel) {