diff --git a/src/utils/modal.js b/src/utils/modal.js index b0d5f77..292f026 100644 --- a/src/utils/modal.js +++ b/src/utils/modal.js @@ -1,17 +1,117 @@ import { aliases, defaulttx, meta, translations } from './meta.js'; import { hasLocalStorage } from './utils.js'; -export const modal = (el) => { - +const bookTransforms = { + 'oba': { + chapter: (ref) => { + return 1; + }, + verse: (ref) => { + return ref.getChapter(); + }, + }, + 'jud': { + chapter: (ref) => { + return 1; + }, + verse: (ref) => { + return ref.getChapter(); + }, + }, + 'psa': { + match: { + ts: 'LXX', + }, + chapter: (ref) => { + return 999; + } + } }; +class Refs { + constructor(book, chapter, verse, ts) { + this._book = aliases[book.toLowerCase()]; + this._chapter = chapter; + this._verse = verse; + this._ts = ['OT', 'NT']; + if (ts !== undefined) { + this._ts = ts; + } + } + fullTitle() { + let title = refdata.meta.title+' '; + title += refdata.chapter; + + if (refdata.verses?.start > 0) { + title += ':'+refdata.verses.start; + } + if (refdata.verses?.end > 0 && refdata.verses?.end > refdata.verses?.start) { + title += '-'+refdata.verses.end; + } + return title; + } + getChapter() { + if (typeof(this._chapter) === 'number' || (typeof(this._chapter) === 'string' && this._chapter.indexOf('-') == -1)) { + return parseInt(this._chapter); + } + return [parseInt(this._chapter.substr(0, this._chapter.indexOf('-'))), + parseInt(this._chapter.substr(this._chapter.indexOf('-')+1))]; + } + get chapter() { + if (this._book in bookTransforms) { + const bt = bookTransforms[this._book]; + if ('match' in bt) { + if ('ts' in bt.match && this._ts.indexOf(bt.match.ts) == -1) { + console.log('not matched'); + return this.getChapter(); + } + } + const tx = bt; + if ('chapter' in tx) { + return tx['chapter'](this); + } + } + return this.getChapter(); + } + getVerse() { + if (typeof(this._verse) === 'number' || (typeof(this._verse) === 'string' && this._verse.indexOf('-') == -1)) { + return parseInt(this._verse); + } + if (typeof(this._verse) === 'string' && this._verse.endsWidth('ff')) { + return [parseInt(this._verse.substr(0, this._verse.length-2)), 'ff']; + } + return [parseInt(this._verse.substr(0, this._verse.indexOf('-'))), + parseInt(this._verse.substr(this._verse.indexOf('-')+1))]; + } + get verse() { + if (this._book in bookTransforms) { + const tx = bookTransforms[this._book]; + if ('verse' in tx) { + return tx['verse'](this); + } + } + return this.getVerse(); + } + get meta() { + if (this._book in meta) { + return meta[this.book]; + } + return {}; + } +} + function parseRef(ref) { - ref = ref.replace(/%3[Aa]/, ':').replace(/\+/, ' '); - const m = ref.match(/((\d+(\+|\s))?[a-zA-Z]+)(\+|\s)?([0-9]+)?\:?([0-9]+(-?[0-9]+)?)?/); + ref = ref + // Limited URL decoding. + .replace(/%3[Aa]/, ':') + .replace(/\+/, ' ') + // Logos will helpfully replace "-" with "–" in its reference spec. + .replaceAll(/–/g, '-'); + const m = ref.match(/((\d+(\+|\s))?[a-zA-Z]+)(\+|\s)?([0-9]+[-0-9]*)?\:?([0-9]+(-?[0-9]+)?)?/); const book = m[1].toLowerCase(); const chapter = m[5]; - const verses = m[6]?.replaceAll(/–/g, '-'); + const verses = m[6]; if (book === undefined) { return {}; @@ -69,6 +169,8 @@ function parseRef(ref) { return refdata; } +window.Refs = Refs; +window.parseRef = parseRef; class RenderScripture { translation = 'BSB';