Skip to content

Commit

Permalink
More consistent parsing of IIIF Info JSON for IABookreader page source
Browse files Browse the repository at this point in the history
for zoom see #467
  • Loading branch information
DiegoPino committed Sep 19, 2024
1 parent 663ceea commit 11fa9bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 5 additions & 3 deletions js/iiif-iabookreader_strawberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ BookReader.prototype.buildViewpageDiv = function(jViewpageDiv) {
var index = this.currentIndex();
//OLD//var tilesourceUri = this.getPageURI(index, 1, 0).replace(/full.*/, "info.json");
//var tilesourceUri = this.getPageProp(index, 'infojson');
var tilesourceUri = this.getPageURI(index, 1, 0).replace(/full.*/, "info.json") + getURLArgument(this.getPageURI(index, 1, 0));
var tilesourceUri = this.getIIIFInfoJsonFromURL(this.getPageURI(index, 1, 0)) ;
var dosd = $(osd_common.replace(/\[ID\]/g, "osd_s").replace('[TS]', tilesourceUri));
jViewpageDiv.html(dosd);
}
Expand All @@ -346,7 +346,8 @@ BookReader.prototype.buildViewpageDiv = function(jViewpageDiv) {
if (typeof this.getPageURI(indices[0], 1, 0) != 'undefined') {
//OLD//var tilesourceUri_left = this.getPageURI(indices[0], 1, 0).replace(/full.*/, "info.json");
//var tilesourceUri_left = this.getPageProp(indices[0], 'infojson');
var tilesourceUri_left = this.getPageURI(indices[0], 1, 0).replace(/full.*/, "info.json") + getURLArgument(this.getPageURI(indices[0], 1, 0));

var tilesourceUri_left = this.getIIIFInfoJsonFromURL(this.getPageURI(indices[0], 1, 0)) ;
var osd_left = osd_common.replace(/\[ID\]/g, "osd_l").replace('[TS]', tilesourceUri_left);
}
else {
Expand All @@ -358,7 +359,8 @@ BookReader.prototype.buildViewpageDiv = function(jViewpageDiv) {
if (typeof this.getPageURI(indices[1], 1, 0) != 'undefined') {
//OLD//var tilesourceUri_right = this.getPageURI(indices[1], 1, 0).replace(/full.*/, "info.json");
//var tilesourceUri_right = this.getPageProp(indices[1], 'infojson');
var tilesourceUri_right = this.getPageURI(indices[1], 1, 0).replace(/full.*/, "info.json") + getURLArgument(this.getPageURI(indices[1], 1, 0));

var tilesourceUri_right = this.getIIIFInfoJsonFromURL(this.getPageURI(indices[1], 1, 0)) ;
var osd_right = osd_common.replace(/\[ID\]/g, "osd_r").replace('[TS]', tilesourceUri_right);
}
else {
Expand Down
30 changes: 29 additions & 1 deletion js/plugin.iiif-iabookreader_strawberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,37 @@ BookReader.prototype.parseSequence = function (sequenceId) {

return url.search
}

};



BookReader.prototype.getIIIFInfoJsonFromURL = function(string){
let url;

try {
url = new URL(string);
} catch (_) {
return '';
}
let path = url.pathname;
// IIIF will have id/crop/size/rotation/filename So we will split and reverse
if (path !== '/') {
let path_parts = path.split("/");
if (path_parts.length >= 5) {
path_parts = path_parts.reverse();
path_parts = path_parts.slice(4);
//reverse again
path_parts = path_parts.reverse();
path = path_parts.join('/') + '/info.json';
url.pathname = path;
return url.toString();
}
}
else {
return string;
}
}

/**
* @param {number} index
* @return {Number|undefined}
Expand Down

0 comments on commit 11fa9bb

Please sign in to comment.