From c8f9132f92818e6eb50e264f2a0fe196009fa5a7 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Tue, 25 Aug 2026 19:27:57 -0600 Subject: [PATCH] Cleanup: Store refs instance for switching translation source. --- src/utils/modal.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/utils/modal.js b/src/utils/modal.js index 0bbb89b..00226a2 100644 --- a/src/utils/modal.js +++ b/src/utils/modal.js @@ -34,7 +34,7 @@ const bookTransforms = { }, /*'psa': { match: { - dn: 'lxx', + ts: 'LXX', }, chapter: (ref) => { return 999; @@ -50,7 +50,7 @@ class Refs { this._chapter = chapter; this._verse = verse; // Default source numbering is the Masoretic Text. - this._options = {'sn': 'mt'}; + this._options = {'sn': 'mt', 'dn': 'mt'}; if (options !== undefined) { this._options = options; } @@ -98,6 +98,7 @@ class Refs { if (this._book in bookTransforms) { const bt = bookTransforms[this._book]; if ('match' in bt) { + if ('dn' in bt.match && this._options.sn == bt.match.dn) { return this.getChapter(); } @@ -137,6 +138,9 @@ class Refs { } return {}; } + setOption(opt, val) { + this._options[opt] = val; + } inVerseSpan(num) { const verses = this.verse; // If verse isn't set, we'll read the whole chapter. @@ -243,7 +247,7 @@ class RenderScripture { buildTranslationList(sel) { sel?.replaceChildren(); for (const tx in translations) { - const testament = meta[this.ref.book].ts; + const testament = meta[this.refs.book].ts; if (translations[tx][2].indexOf(testament) == -1) { continue; } @@ -266,15 +270,14 @@ class RenderScripture { } openDialog(scripture, hash) { - const refs = parseRef(scripture); - this.ref = refs; + this.refs = parseRef(scripture); this.dialog[0]?.showModal(); this.dialog[0]?.setAttribute('data-scripture', scripture); this.dialog[0]?.classList.remove("hidden"); this.dialog[0]?.querySelector('.spinner svg') .classList.remove('hidden'); this.buildTranslationList(this.sel); - this.readScripture(refs); + this.readScripture(); history.pushState({ dialog: true, scripture: scripture.value, @@ -288,21 +291,20 @@ class RenderScripture { if (this.ls) { localStorage.setItem('__translation', tx); } - const refs = parseRef(this.dialog[0]?.getAttribute('data-scripture')); this.dialog[0]?.querySelector('article')?.replaceChildren(); this.dialog[0]?.querySelector('.spinner svg') .classList.remove('hidden'); - this.readScripture(refs); + this.readScripture(); } - readScripture(refs) { + readScripture() { // Current translation. let tx = this.translation; // Previous translation. const px = this.translation; - const book = refs.book; - const chapter = refs.chapter; + const book = this.refs.book; + const chapter = this.refs.chapter; const testament = meta[book].ts; // If the current translation doesn't contain the testament, switch to @@ -323,7 +325,7 @@ class RenderScripture { return response.json(); }) .then((response) => { - this.render(response, refs); + this.render(response); this.dialog[0]?.querySelector('.spinner svg') .classList.add('hidden'); // Switch translation back if it's forced to a different @@ -334,7 +336,7 @@ class RenderScripture { }); } - render(response, refs) { + render(response) { const content = response?.chapter?.content; let inSpan = false; @@ -348,7 +350,7 @@ class RenderScripture { const heading = document.createElement('h1'); heading.insertAdjacentText('beforeend', - `${refs.fullTitle()}`); + `${this.refs.fullTitle()}`); article.insertAdjacentElement('beforeend', heading); for (const c of content) { @@ -369,7 +371,7 @@ class RenderScripture { if (!('number' in c)) { continue; } - if (refs.inVerseSpan(c.number)) { + if (this.refs.inVerseSpan(c.number)) { verse.insertAdjacentText('beforeend', c.number); verse.classList.add('verse'); para.insertAdjacentElement('beforeend', verse);