WIP modal support.
This commit is contained in:
parent
79b5c9246b
commit
d59dd67812
1 changed files with 74 additions and 7 deletions
|
|
@ -19,10 +19,15 @@ function parseRef(ref) {
|
|||
return {};
|
||||
}
|
||||
|
||||
let refdata = {
|
||||
book: _map[book],
|
||||
meta: books[_map[book]]
|
||||
};
|
||||
let refdata = {};
|
||||
if (book in books) {
|
||||
refdata.book = book;
|
||||
} else if (book in _map) {
|
||||
refdata.book = _map[book];
|
||||
}
|
||||
refdata.meta = books[refdata.book];
|
||||
|
||||
console.log('refdata:', refdata, book, _map);
|
||||
|
||||
if (chapter !== undefined) {
|
||||
refdata['chapter'] = chapter;
|
||||
|
|
@ -38,6 +43,7 @@ function parseRef(ref) {
|
|||
};
|
||||
}
|
||||
}
|
||||
console.log(refdata, book);
|
||||
|
||||
if ('verses' in refdata) {
|
||||
if (refdata.verses.start < 1) {
|
||||
|
|
@ -55,12 +61,74 @@ function parseRef(ref) {
|
|||
if (refdata.verses.start > refdata.verses.end) {
|
||||
refdata.verses.end = refdata.verses.start;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return refdata;
|
||||
}
|
||||
|
||||
function render(dialog, response) {
|
||||
const content = response?.chapter?.content;
|
||||
const refs = parseRef('gen+1:1-4');
|
||||
let inSpan = false;
|
||||
|
||||
if (dialog === null || dialog === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const section = document.createElement('section');
|
||||
|
||||
for (const c of content) {
|
||||
if (c.type === 'heading') {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (c.type) {
|
||||
case 'line_break':
|
||||
if (inSpan) {
|
||||
console.log('line break');
|
||||
section.insertAdjacentElement('beforeend', document.createElement('br'));
|
||||
}
|
||||
break;
|
||||
case 'verse':
|
||||
if (!('number' in c)) {
|
||||
continue;
|
||||
}
|
||||
if (c.number >= refs.verses.start && c.number <= refs.verses.end) {
|
||||
inSpan = true;
|
||||
} else {
|
||||
inSpan = false;
|
||||
}
|
||||
if (inSpan) {
|
||||
for (const v of c.content) {
|
||||
if (typeof(v) === 'string') {
|
||||
console.log("string:", v);
|
||||
section.insertAdjacentText('beforebegin', document.createTextNode(v));
|
||||
continue
|
||||
}
|
||||
if ('lineBreak' in v) {
|
||||
section.insertAdjacentElement('beforeend', document.createElement('br'));
|
||||
}
|
||||
if ('text' in v) {
|
||||
console.log('adding text:', v.text);
|
||||
const span = document.createElement('span');
|
||||
span.insertAdjacentText(v.text);
|
||||
if ('poem' in v) {
|
||||
span.classList.add('poem-'+v.poem);
|
||||
section.insertAdjacentElement('beforeend', span);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log('unhandled type:', c.type);
|
||||
}
|
||||
console.log(c);
|
||||
}
|
||||
|
||||
dialog?.querySelector('article').insertAdjacentElement('beforeend', section);
|
||||
}
|
||||
|
||||
export const bindModals = () => {
|
||||
const elems = document.querySelectorAll('a[data-scripture]');
|
||||
const dialog = document.querySelectorAll('dialog[data-scripture]');
|
||||
|
|
@ -81,8 +149,7 @@ export const bindModals = () => {
|
|||
return response.json();
|
||||
})
|
||||
.then((response) => {
|
||||
const content = response?.chapter?.content;
|
||||
console.log(content);
|
||||
render(dialog[0], response);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue