Skip to content

Commit

Permalink
Merge pull request #28 from Riksarkivet/bugfix/18984-lank_for_bild_mm…
Browse files Browse the repository at this point in the history
…_funkar_inte

Fixed functionality with Riksarkivet legacy URLs.
  • Loading branch information
ra-catrine authored Sep 19, 2024
2 parents fc62979 + c84b9c8 commit 99216d0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { OpenSeadragonCenterPanel } from "../../modules/uv-openseadragoncenterpa
import { SettingsDialogue } from "./SettingsDialogue";
import { ShareDialogue } from "./ShareDialogue";
import { Bools, Maths, Strings } from "@edsilv/utils";
import { Riksarkivet } from "../../modules/uv-shared-module/Riksarkivet"
import {
IIIFResourceType,
ExternalResourceType,
Expand Down Expand Up @@ -96,11 +97,13 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
shareDialogue: ShareDialogue;
defaultConfig: Config = defaultConfig;
searchHits: SearchHit[];
riksarkivet: Riksarkivet;

create(): void {
super.create();

this.store = createStore();
this.riksarkivet = new Riksarkivet();

this.store.subscribe((_state) => {
this.renderDownloadDialogue();
Expand All @@ -124,6 +127,10 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
this.previousAnnotationRect = null;
this.currentAnnotationRect = null;
this.changeCanvas(canvasIndex);
if (this.getSettings().useRiksarkivetLegacyURLs) { // This is a special for us at Riksarkivet, and it's set to false as default.
let canvas = this.helper.getCanvasByIndex(canvasIndex);
this.riksarkivet.UpdateUrl(canvas)
}
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ interface ISettings {
brightnessPercent?: number;
saturationPercent?: number;
rememberSettings?: boolean;
useRiksarkivetLegacyURLs?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"tokenStorage": "session",
"useArrowKeysToNavigate": false,
"zoomToSearchResultEnabled": true,
"zoomToBoundsEnabled": true
"zoomToBoundsEnabled": true,
"useRiksarkivetLegacyURLs": true
},
"modules": {
"leftPanel": {
Expand Down
54 changes: 54 additions & 0 deletions src/content-handlers/iiif/modules/uv-shared-module/Riksarkivet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Canvas } from "manifesto.js";

export class Riksarkivet {
public UpdateUrl(canvas: Canvas) {
var imageId: string | null = this.GetImageIdFromCanvas(canvas);
if (imageId !== null) {
this.SetUrlAfter("/", imageId, parent.document);
}
}

public GetImageIdFromCanvas(canvas: Canvas) {
var imageId = canvas.id.split('/')[3];
var datasource = imageId.split('!')[0];
if (datasource === "arkis") {
datasource = "";
}
else {
datasource = datasource.substr(0, 1).toUpperCase() + datasource.substr(1) + "_";
}
imageId = datasource + imageId.substr(imageId.indexOf("!") + 1);
return imageId;
}

public SetUrlAfter(searchvalue, value, doc) {
if (!doc) {
doc = window.document;
}
var url = doc.URL;
var searchIndex = url.lastIndexOf(searchvalue);
if (searchIndex === -1) {
return;
}
var startUrl = url.substr(0, searchIndex);
var endUrl = url.substr(searchIndex);
var indexAfter = endUrl.indexOf("#");
if (indexAfter === -1) {
indexAfter = endUrl.indexOf("?");
}
if (indexAfter === -1) {
indexAfter = endUrl.indexOf("&");
}
if (indexAfter !== -1) {
endUrl = endUrl.substr(indexAfter);
}
else {
endUrl = "";
}
if (window.top !== null) {
if (window.top.history.replaceState) {
window.top.history.replaceState(null, "", startUrl + searchvalue + value + endUrl);
}
}
};
}

0 comments on commit 99216d0

Please sign in to comment.