Cleanup: Store refs instance for switching translation source.

This commit is contained in:
Benjamin A. Shelton 2026-08-25 19:27:57 -06:00
commit c8f9132f92
Signed by: zancarius
GPG key ID: 8BD42DBD6C337E01

View file

@ -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);