Updated drop-down and renderer for more testament-centry logic.
In the case of the drop-down, if a translation doesn't contain the visible testament (e.g. the LXX while opening a NT passage), it will be excluded from the list. In the case of opening a link that is not contained in the currently configured translation, a reasonable default will be selected instead.
This commit is contained in:
parent
2f15176981
commit
9e368526c4
1 changed files with 32 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { aliases, meta, translations } from './meta.js';
|
import { aliases, defaulttx, meta, translations } from './meta.js';
|
||||||
import { hasLocalStorage } from './utils.js';
|
import { hasLocalStorage } from './utils.js';
|
||||||
|
|
||||||
export const modal = (el) => {
|
export const modal = (el) => {
|
||||||
|
|
@ -73,7 +73,9 @@ function parseRef(ref) {
|
||||||
class RenderScripture {
|
class RenderScripture {
|
||||||
translation = 'BSB';
|
translation = 'BSB';
|
||||||
dialog = null;
|
dialog = null;
|
||||||
|
sel = null;
|
||||||
ls = false;
|
ls = false;
|
||||||
|
ref = {};
|
||||||
|
|
||||||
constructor(dialog) {
|
constructor(dialog) {
|
||||||
this.dialog = dialog;
|
this.dialog = dialog;
|
||||||
|
|
@ -90,10 +92,10 @@ class RenderScripture {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const sel = this.dialog[0]?.querySelector('select.translation');
|
const sel = this.dialog[0]?.querySelector('select.translation');
|
||||||
this.buildTranslationList(sel);
|
|
||||||
sel?.addEventListener('change', (evt) => {
|
sel?.addEventListener('change', (evt) => {
|
||||||
this.txnOnChange(evt)
|
this.txnOnChange(evt)
|
||||||
});
|
});
|
||||||
|
this.sel = sel;
|
||||||
|
|
||||||
this.dialog[0]?.addEventListener('click', (evt) => {
|
this.dialog[0]?.addEventListener('click', (evt) => {
|
||||||
if (evt.target === this.dialog[0]) {
|
if (evt.target === this.dialog[0]) {
|
||||||
|
|
@ -111,18 +113,24 @@ class RenderScripture {
|
||||||
const scripture = evt.target.attributes.getNamedItem('data-scripture');
|
const scripture = evt.target.attributes.getNamedItem('data-scripture');
|
||||||
const refs = parseRef(scripture.value);
|
const refs = parseRef(scripture.value);
|
||||||
const tx = refs.meta?.tx || 'BSB';
|
const tx = refs.meta?.tx || 'BSB';
|
||||||
|
this.ref = refs;
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
this.dialog[0]?.showModal();
|
this.dialog[0]?.showModal();
|
||||||
this.dialog[0]?.setAttribute('data-scripture', scripture.value);
|
this.dialog[0]?.setAttribute('data-scripture', scripture.value);
|
||||||
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.readScripture(refs);
|
this.readScripture(refs);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
if (translations[tx][2].indexOf(testament) == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
opt.setAttribute('value', tx);
|
opt.setAttribute('value', tx);
|
||||||
opt.insertAdjacentText('beforeend', translations[tx][0]);
|
opt.insertAdjacentText('beforeend', translations[tx][0]);
|
||||||
|
|
@ -153,7 +161,23 @@ class RenderScripture {
|
||||||
}
|
}
|
||||||
|
|
||||||
readScripture(refs) {
|
readScripture(refs) {
|
||||||
const uri = `https://bible.helloao.org/api/${this.translation}/${refs.book.toUpperCase()}/${refs.chapter}.json`;
|
// Current translation.
|
||||||
|
let tx = this.translation;
|
||||||
|
// Previous translation.
|
||||||
|
const px = this.translation;
|
||||||
|
|
||||||
|
const book = refs.book;
|
||||||
|
const chapter = refs.chapter;
|
||||||
|
const testament = meta[book].ts;
|
||||||
|
|
||||||
|
// If the current translation doesn't contain the testament, switch to
|
||||||
|
// the default translation that does.
|
||||||
|
if (translations[tx][2].indexOf(testament) == -1) {
|
||||||
|
tx = defaulttx[testament];
|
||||||
|
this.translation = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uri = `https://bible.helloao.org/api/${tx}/${book.toUpperCase()}/${chapter}.json`;
|
||||||
fetch(uri)
|
fetch(uri)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
@ -167,6 +191,11 @@ class RenderScripture {
|
||||||
this.render(response, refs);
|
this.render(response, refs);
|
||||||
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
|
||||||
|
// translation from book availability.
|
||||||
|
if (this.translation != px) {
|
||||||
|
this.translation = px;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue