Skip to content

Commit

Permalink
feat(embed): move /uv.html to options.embedTemplate for easier embedd…
Browse files Browse the repository at this point in the history
…ing when uv.html isn't in webroot.
  • Loading branch information
crhallberg committed Dec 12, 2024
1 parent d0f6303 commit 8c2e399
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,21 @@ export default class Extension
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
15 changes: 12 additions & 3 deletions src/content-handlers/iiif/extensions/uv-av-extension/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,25 @@ export default class Extension
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
c: this.helper.collectionIndex.toString(),
m: this.helper.manifestIndex.toString(),
cv: this.helper.canvasIndex.toString(),
rid: this.helper.rangeId?.toString() ?? ""
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}&rid=${this.helper.rangeId}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,24 @@ export default class Extension
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
c: this.helper.collectionIndex.toString(),
m: this.helper.manifestIndex.toString(),
cv: this.helper.canvasIndex.toString(),
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,22 @@ export default class Extension
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
cfi: this.cfiFragement,
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&cfi=${this.cfiFragement}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,24 @@ export default class Extension
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
c: this.helper.collectionIndex.toString(),
m: this.helper.manifestIndex.toString(),
cv: this.helper.canvasIndex.toString(),
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,24 @@ export default class ModelViewerExtension extends BaseExtension<Config> {
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
c: this.helper.collectionIndex.toString(),
m: this.helper.manifestIndex.toString(),
cv: this.helper.canvasIndex.toString(),
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,18 +1369,30 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
zoom: string,
rotation: number
): string {
const config: string = this.data.config!.uri || "";
const locales: string | null = this.getSerializedLocales();
const config: string = this.data.config?.uri ?? "";
const locales: string = this.getSerializedLocales() ?? "";
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
c: this.helper.collectionIndex.toString(),
m: this.helper.manifestIndex.toString(),
cv: this.helper.canvasIndex.toString(),
config: config,
locales: locales,
xywh: zoom,
r: rotation.toString(),
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}&config=${config}&locales=${locales}&xywh=${zoom}&r=${rotation}`;
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
"shareDialogue": {
"options": {
"embedEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareEnabled": true,
"shareFrameEnabled": true,
Expand Down
14 changes: 11 additions & 3 deletions src/content-handlers/iiif/extensions/uv-pdf-extension/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,24 @@ export default class Extension
}

getEmbedScript(template: string, width: number, height: number): string {
const hashParams = new URLSearchParams({
manifest: this.helper.manifestUri,
c: this.helper.collectionIndex.toString(),
m: this.helper.manifestIndex.toString(),
cv: this.helper.canvasIndex.toString(),
});

const appUri: string = this.getAppUri();
const title: string = this.helper.getLabel() || "";
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&cv=${this.helper.canvasIndex}`;
const title: string = this.helper.getLabel() ?? "";
const script: string = Strings.format(
template,
iframeSrc,
appUri,
hashParams.toString(),
width.toString(),
height.toString(),
title
);

return script;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
"options": {
"embedEnabled": true,
"shareEnabled": true,
"embedTemplate": "<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\" allowfullscreen frameborder=\"0\" title=\"{3}\"></iframe>",
"embedTemplate": "<iframe src=\"{0}/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>",
"instructionsEnabled": false,
"shareFrameEnabled": true,
"shareManifestsEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,8 @@ export class BaseExtension<T extends BaseConfig> implements IExtension {
}

getAppUri(): string {
const appUri: string =
window.location.protocol +
"//" +
window.location.hostname +
(window.location.port ? ":" + window.location.port : "");

return appUri + "/uv.html";
const port = window.location.port ? `:${window.location.port}` : "";
return `${window.location.protocol}//${window.location.hostname}${port}`;
}

getSettings(): ISettings {
Expand Down
5 changes: 5 additions & 0 deletions src/uv-iiif-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
"options": {
"downloadEnabled": true
}
},
"shareDialogue": {
"options": {
"embedTemplate": "<iframe src=\"{0}/assets/uv.html#?{1}\" width=\"{2}\" height=\"{3}\" allowfullscreen frameborder=\"0\" title=\"{4}\"></iframe>"
}
}
}
}

0 comments on commit 8c2e399

Please sign in to comment.