Cleanup: Store refs instance for switching translation source.
This commit is contained in:
parent
5929d54605
commit
c8f9132f92
1 changed files with 17 additions and 15 deletions
|
|
@ -34,7 +34,7 @@ const bookTransforms = {
|
||||||
},
|
},
|
||||||
/*'psa': {
|
/*'psa': {
|
||||||
match: {
|
match: {
|
||||||
dn: 'lxx',
|
ts: 'LXX',
|
||||||
},
|
},
|
||||||
chapter: (ref) => {
|
chapter: (ref) => {
|
||||||
return 999;
|
return 999;
|
||||||
|
|
@ -50,7 +50,7 @@ class Refs {
|
||||||
this._chapter = chapter;
|
this._chapter = chapter;
|
||||||
this._verse = verse;
|
this._verse = verse;
|
||||||
// Default source numbering is the Masoretic Text.
|
// Default source numbering is the Masoretic Text.
|
||||||
this._options = {'sn': 'mt'};
|
this._options = {'sn': 'mt', 'dn': 'mt'};
|
||||||
if (options !== undefined) {
|
if (options !== undefined) {
|
||||||
this._options = options;
|
this._options = options;
|
||||||
}
|
}
|
||||||
|
|
@ -98,6 +98,7 @@ class Refs {
|
||||||
if (this._book in bookTransforms) {
|
if (this._book in bookTransforms) {
|
||||||
const bt = bookTransforms[this._book];
|
const bt = bookTransforms[this._book];
|
||||||
if ('match' in bt) {
|
if ('match' in bt) {
|
||||||
|
|
||||||
if ('dn' in bt.match && this._options.sn == bt.match.dn) {
|
if ('dn' in bt.match && this._options.sn == bt.match.dn) {
|
||||||
return this.getChapter();
|
return this.getChapter();
|
||||||
}
|
}
|
||||||
|
|
@ -137,6 +138,9 @@ class Refs {
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
setOption(opt, val) {
|
||||||
|
this._options[opt] = val;
|
||||||
|
}
|
||||||
inVerseSpan(num) {
|
inVerseSpan(num) {
|
||||||
const verses = this.verse;
|
const verses = this.verse;
|
||||||
// If verse isn't set, we'll read the whole chapter.
|
// If verse isn't set, we'll read the whole chapter.
|
||||||
|
|
@ -243,7 +247,7 @@ class RenderScripture {
|
||||||
buildTranslationList(sel) {
|
buildTranslationList(sel) {
|
||||||
sel?.replaceChildren();
|
sel?.replaceChildren();
|
||||||
for (const tx in translations) {
|
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) {
|
if (translations[tx][2].indexOf(testament) == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -266,15 +270,14 @@ class RenderScripture {
|
||||||
}
|
}
|
||||||
|
|
||||||
openDialog(scripture, hash) {
|
openDialog(scripture, hash) {
|
||||||
const refs = parseRef(scripture);
|
this.refs = parseRef(scripture);
|
||||||
this.ref = refs;
|
|
||||||
this.dialog[0]?.showModal();
|
this.dialog[0]?.showModal();
|
||||||
this.dialog[0]?.setAttribute('data-scripture', scripture);
|
this.dialog[0]?.setAttribute('data-scripture', scripture);
|
||||||
this.dialog[0]?.classList.remove("hidden");
|
this.dialog[0]?.classList.remove("hidden");
|
||||||
this.dialog[0]?.querySelector('.spinner svg')
|
this.dialog[0]?.querySelector('.spinner svg')
|
||||||
.classList.remove('hidden');
|
.classList.remove('hidden');
|
||||||
this.buildTranslationList(this.sel);
|
this.buildTranslationList(this.sel);
|
||||||
this.readScripture(refs);
|
this.readScripture();
|
||||||
history.pushState({
|
history.pushState({
|
||||||
dialog: true,
|
dialog: true,
|
||||||
scripture: scripture.value,
|
scripture: scripture.value,
|
||||||
|
|
@ -288,21 +291,20 @@ class RenderScripture {
|
||||||
if (this.ls) {
|
if (this.ls) {
|
||||||
localStorage.setItem('__translation', tx);
|
localStorage.setItem('__translation', tx);
|
||||||
}
|
}
|
||||||
const refs = parseRef(this.dialog[0]?.getAttribute('data-scripture'));
|
|
||||||
this.dialog[0]?.querySelector('article')?.replaceChildren();
|
this.dialog[0]?.querySelector('article')?.replaceChildren();
|
||||||
this.dialog[0]?.querySelector('.spinner svg')
|
this.dialog[0]?.querySelector('.spinner svg')
|
||||||
.classList.remove('hidden');
|
.classList.remove('hidden');
|
||||||
this.readScripture(refs);
|
this.readScripture();
|
||||||
}
|
}
|
||||||
|
|
||||||
readScripture(refs) {
|
readScripture() {
|
||||||
// Current translation.
|
// Current translation.
|
||||||
let tx = this.translation;
|
let tx = this.translation;
|
||||||
// Previous translation.
|
// Previous translation.
|
||||||
const px = this.translation;
|
const px = this.translation;
|
||||||
|
|
||||||
const book = refs.book;
|
const book = this.refs.book;
|
||||||
const chapter = refs.chapter;
|
const chapter = this.refs.chapter;
|
||||||
const testament = meta[book].ts;
|
const testament = meta[book].ts;
|
||||||
|
|
||||||
// If the current translation doesn't contain the testament, switch to
|
// If the current translation doesn't contain the testament, switch to
|
||||||
|
|
@ -323,7 +325,7 @@ class RenderScripture {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.render(response, refs);
|
this.render(response);
|
||||||
this.dialog[0]?.querySelector('.spinner svg')
|
this.dialog[0]?.querySelector('.spinner svg')
|
||||||
.classList.add('hidden');
|
.classList.add('hidden');
|
||||||
// Switch translation back if it's forced to a different
|
// 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;
|
const content = response?.chapter?.content;
|
||||||
let inSpan = false;
|
let inSpan = false;
|
||||||
|
|
||||||
|
|
@ -348,7 +350,7 @@ class RenderScripture {
|
||||||
|
|
||||||
const heading = document.createElement('h1');
|
const heading = document.createElement('h1');
|
||||||
heading.insertAdjacentText('beforeend',
|
heading.insertAdjacentText('beforeend',
|
||||||
`${refs.fullTitle()}`);
|
`${this.refs.fullTitle()}`);
|
||||||
article.insertAdjacentElement('beforeend', heading);
|
article.insertAdjacentElement('beforeend', heading);
|
||||||
|
|
||||||
for (const c of content) {
|
for (const c of content) {
|
||||||
|
|
@ -369,7 +371,7 @@ class RenderScripture {
|
||||||
if (!('number' in c)) {
|
if (!('number' in c)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (refs.inVerseSpan(c.number)) {
|
if (this.refs.inVerseSpan(c.number)) {
|
||||||
verse.insertAdjacentText('beforeend', c.number);
|
verse.insertAdjacentText('beforeend', c.number);
|
||||||
verse.classList.add('verse');
|
verse.classList.add('verse');
|
||||||
para.insertAdjacentElement('beforeend', verse);
|
para.insertAdjacentElement('beforeend', verse);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue