Commit ccca24ab authored by Robert Knight's avatar Robert Knight

Defer initial chapter load until `<mosaic-book>` element is connected

This doesn't actually matter at present as the `<mosaic-book>` element
is already present in the DOM, with the "book" attribute set, when the
MosaicBookElement constructor is called. However it would matter if the
element were programatically created in future.
parent 7ba89df5
...@@ -10,21 +10,7 @@ export class MosaicBookElement extends HTMLElement { ...@@ -10,21 +10,7 @@ export class MosaicBookElement extends HTMLElement {
super(); super();
this.attachShadow({ mode: 'open' }); this.attachShadow({ mode: 'open' });
const book = this.getAttribute('book'); this.chapterURLs = [];
if (book === 'little-women') {
this.chapterURLs = [
'/document/little-women-1',
'/document/little-women-2',
'/document/little-women-3',
];
} else if (book === 'test-pdf') {
this.chapterURLs = ['/document/vitalsource-pdf-page'];
} else {
console.warn(`Unknown VitalSource book "${book}"`);
this.chapterURLs = [];
}
this.chapterIndex = 0; this.chapterIndex = 0;
const styles = document.createElement('style'); const styles = document.createElement('style');
...@@ -50,6 +36,22 @@ export class MosaicBookElement extends HTMLElement { ...@@ -50,6 +36,22 @@ export class MosaicBookElement extends HTMLElement {
this.nextButton.textContent = 'Next chapter'; this.nextButton.textContent = 'Next chapter';
this.nextButton.onclick = () => this.setChapter(this.chapterIndex + 1); this.nextButton.onclick = () => this.setChapter(this.chapterIndex + 1);
controlBar.append(this.nextButton); controlBar.append(this.nextButton);
}
connectedCallback() {
const book = this.getAttribute('book');
if (book === 'little-women') {
this.chapterURLs = [
'/document/little-women-1',
'/document/little-women-2',
'/document/little-women-3',
];
} else if (book === 'test-pdf') {
this.chapterURLs = ['/document/vitalsource-pdf-page'];
} else {
console.warn(`Unknown VitalSource book "${book}"`);
}
this.setChapter(0, { initialLoad: true }); this.setChapter(0, { initialLoad: true });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment