Skip to content

Commit da6470a

Browse files
author
Sebastian Flick
committed
dynamic iiif
1 parent e0ee283 commit da6470a

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

src/lib/components/IIIFViewer.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
let viewer;
1818
1919
const generateViewer = (/** @type {Element} */ node, /** @type {Object} */ iiif) => {
20-
const i = Number(node.id.split('-')[1]);
21-
if (!iiif) return;
2220
/** @type {ResizeObserver}*/
2321
let observer;
2422
const createViewer = () => {
@@ -84,13 +82,14 @@
8482
},
8583
sequenceMode: false
8684
});
87-
viewer.open(iiif);
8885
observer = new ResizeObserver((_entries) => {
8986
setTimeout(() => {
9087
viewer.viewport.goHome(false);
9188
}, 50);
9289
});
9390
observer.observe(node);
91+
if (!iiif) return;
92+
viewer.open(iiif);
9493
};
9594
if (!OpenSeadragon) {
9695
import('openseadragon').then((r) => {
@@ -106,6 +105,7 @@
106105
* @param {Promise<Object>} iiif
107106
*/
108107
update(iiif) {
108+
if (!viewer) return;
109109
viewer.open(iiif);
110110
},
111111
destroy() {

src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ export async function load({ fetch, params }) {
5151
entry.l.includes(`${thirties}.${verse}`)
5252
);
5353

54-
if (selectedIndex > 0) returnObjects.push(data[witnes][selectedIndex - 1] ?? {});
54+
if (selectedIndex > 0) {
55+
returnObjects.push(data[witnes][selectedIndex - 1] ?? {});
56+
}
5557
returnObjects.push(data[witnes][selectedIndex] ?? {});
56-
if (selectedIndex <= data[witnes].length - 1)
58+
if (selectedIndex <= data[witnes].length - 1) {
5759
returnObjects.push(data[witnes][selectedIndex + 1] ?? {});
60+
}
5861
} else {
5962
returnObjects = [data[witnes][0], data[witnes][1]];
6063
}

src/routes/textzeugen/[[sigla]]/[[thirties]]/[[verse]]/+page.svelte

+8-14
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@
6565
setTarget(`${data.thirties}.${data.verse}`);
6666
let localVerses = Array(data.content?.length).fill(`${data.thirties}.${data.verse}`);
6767
let localPages = Array(data.content?.length).fill([]);
68+
let currentIiif = Array(data.content?.length).fill({});
6869
//fill the data from the load-function into the localPages array
6970
data.content?.forEach((c, i) => {
7071
c.meta.then((meta) => {
7172
localPages[i] = [...localPages[i], ...meta];
73+
currentIiif[i] = meta[1]?.iiif;
7274
});
7375
});
7476
@@ -78,7 +80,9 @@
7880
/** @type {string} */ sigla
7981
) => {
8082
const indexCurrent = localPages[i].findIndex((p) => p.page === e.detail.id);
81-
83+
localPages[i][indexCurrent]?.iiif.then((iiif) => {
84+
currentIiif[i] = iiif;
85+
});
8286
const createObject = (/** @type {string} */ id) => {
8387
return {
8488
page: id,
@@ -162,19 +166,9 @@
162166
</section>
163167
{#if !($page.url.searchParams.get('iiif')?.split('-')[i] === 'true')}
164168
<section class="min-h-[40vh]">
165-
{#await localPages[i] then meta}
166-
{#if typeof meta === 'object' && typeof meta.tpData === 'object'}
167-
{#await meta.iiif}
168-
<p>Loading...</p>
169-
{:then iiif}
170-
{#if typeof iiif === 'object'}
171-
<IIIFViewer {iiif} />
172-
{/if}
173-
{:catch error}
174-
<p style="color: red">{error.message}</p>
175-
{/await}
176-
{/if}
177-
{/await}
169+
{#if typeof currentIiif[i] === 'object' && Object.keys(currentIiif[i]).length}
170+
<IIIFViewer iiif={currentIiif[i]} />
171+
{/if}
178172
</section>
179173
{/if}
180174
</article>

0 commit comments

Comments
 (0)