Skip to content

Commit

Permalink
Merge pull request #219 from esmero/ISSUE-197
Browse files Browse the repository at this point in the history
ISSUE-197: Clears BookReader/OSD and Annotorious cross dependencies
  • Loading branch information
DiegoPino authored Aug 11, 2022
2 parents 4bea464 + ee1cf7e commit 8f4a772
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 169 deletions.
2 changes: 1 addition & 1 deletion format_strawberryfield.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ iiif_iabookreader_strawberry:
- core/drupalSettings
- core/drupal.debounce
- core/modernizr
- format_strawberryfield/iiif_openseadragon_strawberry
- format_strawberryfield/iiif_openseadragon
- format_strawberryfield/iiif_iabookreader
pannellum:
version: 2.5.6
Expand Down
167 changes: 0 additions & 167 deletions js/iiif-openseadragon_strawberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@

$('.strawberry-media-item[data-iiif-infojson]').once('attache_osd')
.each(function (index, value) {

// Get the node uuid for this element
var element_id = $(this).attr("id");
var default_width = drupalSettings.format_strawberryfield.openseadragon[element_id]['width'];
Expand Down Expand Up @@ -656,169 +655,3 @@
}
};
})(jQuery, Drupal, window.OpenSeadragon.Annotorious, drupalSettings);

// override getTileUrl
OpenSeadragon.IIIFTileSource.prototype.getTileUrl = function( level, x, y ){
if(this.emulateLegacyImagePyramid) {
var url = null;
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
url = this.levels[ level ].url;
}
return url;
}

//# constants
var IIIF_ROTATION = '0',
//## get the scale (level as a decimal)
scale = Math.pow( 0.5, this.maxLevel - level ),

//# image dimensions at this level
levelWidth = Math.ceil( this.width * scale ),
levelHeight = Math.ceil( this.height * scale ),

//## iiif region
tileWidth,
tileHeight,
iiifTileSizeWidth,
iiifTileSizeHeight,
iiifRegion,
iiifTileX,
iiifTileY,
iiifTileW,
iiifTileH,
iiifSize,
iiifSizeW,
iiifSizeH,
iiifQuality,
uri;

tileWidth = this.getTileWidth(level);
tileHeight = this.getTileHeight(level);
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
if (this.version === 1) {
iiifQuality = "native." + this.tileFormat;
} else {
iiifQuality = "default." + this.tileFormat;
}
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
if ( this.version === 2 && levelWidth === this.width ) {
iiifSize = "full";
} else if ( this.version === 3 && levelWidth === this.width && levelHeight === this.height ) {
iiifSize = "max";
} else if ( this.version === 3 ) {
iiifSize = levelWidth + "," + levelHeight;
} else {
iiifSize = levelWidth + ",";
}
iiifRegion = 'full';
} else {
iiifTileX = x * iiifTileSizeWidth;
iiifTileY = y * iiifTileSizeHeight;
iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX );
iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY );
if ( x === 0 && y === 0 && iiifTileW === this.width && iiifTileH === this.height ) {
iiifRegion = "full";
} else {
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
}
iiifSizeW = Math.ceil( iiifTileW * scale );
iiifSizeH = Math.ceil( iiifTileH * scale );
if ( this.version === 2 && iiifSizeW === this.width ) {
iiifSize = "full";
} else if ( this.version === 3 && iiifSizeW === this.width && iiifSizeH === this.height ) {
iiifSize = "max";
} else if (this.version === 3) {
iiifSize = iiifSizeW + "," + iiifSizeH;
} else {
iiifSize = iiifSizeW + ",";
}
}

//OLD//uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
queryParams = this['@id'].match(/\?.*/);
tilesUrl = this['@id'].replace(queryParams, '');
uri = [ tilesUrl, iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
if (queryParams) {
uri += queryParams;
}

return uri;
};

// override configure
OpenSeadragon.IIIFTileSource.prototype.configure = function( data, url ){
// Try to deduce our version and fake it upwards if needed

queryParams = url.match(/\?.*/);
tilesUrl = url.replace(queryParams, '');

if ( !$.isPlainObject(data) ) {
var options = configureFromXml10( data );
options['@context'] = "http://iiif.io/api/image/1.0/context.json";

//OLD//options['@id'] = url.replace('/info.xml', '');
options['@id'] = tilesUrl.replace('/info.xml', '');
if (queryParams) {
options['@id'] += queryParams;
}

options.version = 1;
return options;
} else {
if ( !data['@context'] ) {
data['@context'] = 'http://iiif.io/api/image/1.0/context.json';

//OLD//data['@id'] = url.replace('/info.json', '');
data['@id'] = tilesUrl.replace('/info.xml', '');
if (queryParams) {
data['@id'] += queryParams;
}

data.version = 1;
} else {
var context = data['@context'];
if (Array.isArray(context)) {
for (var i = 0; i < context.length; i++) {
if (typeof context[i] === 'string' &&
( /^http:\/\/iiif\.io\/api\/image\/[1-3]\/context\.json$/.test(context[i]) ||
context[i] === 'http://library.stanford.edu/iiif/image-api/1.1/context.json' ) ) {
context = context[i];
break;
}
}
}
switch (context) {
case 'http://iiif.io/api/image/1/context.json':
case 'http://library.stanford.edu/iiif/image-api/1.1/context.json':
data.version = 1;
break;
case 'http://iiif.io/api/image/2/context.json':
data.version = 2;
break;
case 'http://iiif.io/api/image/3/context.json':
data.version = 3;
break;
default:
$.console.error('Data has a @context property which contains no known IIIF context URI.');
}
}
if ( !data['@id'] && data['id'] ) {
data['@id'] = data['id'];
}

if (queryParams) {
data['@id'] += queryParams;
}

if(data.preferredFormats) {
for (var f = 0; f < data.preferredFormats.length; f++ ) {
if ( OpenSeadragon.imageFormatSupported(data.preferredFormats[f]) ) {
data.tileFormat = data.preferredFormats[f];
break;
}
}
}
return data;
}
};
172 changes: 171 additions & 1 deletion js/plugin.iiif-iabookreader_strawberry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,177 @@
/**
* Strawberry Plugin which allows IIIF manifest parsing
* Strawberry Plugin which allows IIIF manifest parsing/OpenSeadragon Extensions
* Used by Bookreader. OpenSeadragon.IIIFTileSource.* used to be inside js/iiif-openseadragon_strawberry
* But because of cross dependencies we ended initializing a JS Web Worker Open CV on every book.
*/

// override getTileUrl
OpenSeadragon.IIIFTileSource.prototype.getTileUrl = function( level, x, y ){
if(this.emulateLegacyImagePyramid) {
var url = null;
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
url = this.levels[ level ].url;
}
return url;
}

//# constants
var IIIF_ROTATION = '0',
//## get the scale (level as a decimal)
scale = Math.pow( 0.5, this.maxLevel - level ),

//# image dimensions at this level
levelWidth = Math.ceil( this.width * scale ),
levelHeight = Math.ceil( this.height * scale ),

//## iiif region
tileWidth,
tileHeight,
iiifTileSizeWidth,
iiifTileSizeHeight,
iiifRegion,
iiifTileX,
iiifTileY,
iiifTileW,
iiifTileH,
iiifSize,
iiifSizeW,
iiifSizeH,
iiifQuality,
uri;

tileWidth = this.getTileWidth(level);
tileHeight = this.getTileHeight(level);
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
if (this.version === 1) {
iiifQuality = "native." + this.tileFormat;
} else {
iiifQuality = "default." + this.tileFormat;
}
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
if ( this.version === 2 && levelWidth === this.width ) {
iiifSize = "full";
} else if ( this.version === 3 && levelWidth === this.width && levelHeight === this.height ) {
iiifSize = "max";
} else if ( this.version === 3 ) {
iiifSize = levelWidth + "," + levelHeight;
} else {
iiifSize = levelWidth + ",";
}
iiifRegion = 'full';
} else {
iiifTileX = x * iiifTileSizeWidth;
iiifTileY = y * iiifTileSizeHeight;
iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX );
iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY );
if ( x === 0 && y === 0 && iiifTileW === this.width && iiifTileH === this.height ) {
iiifRegion = "full";
} else {
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
}
iiifSizeW = Math.ceil( iiifTileW * scale );
iiifSizeH = Math.ceil( iiifTileH * scale );
if ( this.version === 2 && iiifSizeW === this.width ) {
iiifSize = "full";
} else if ( this.version === 3 && iiifSizeW === this.width && iiifSizeH === this.height ) {
iiifSize = "max";
} else if (this.version === 3) {
iiifSize = iiifSizeW + "," + iiifSizeH;
} else {
iiifSize = iiifSizeW + ",";
}
}

//OLD//uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
queryParams = this['@id'].match(/\?.*/);
tilesUrl = this['@id'].replace(queryParams, '');
uri = [ tilesUrl, iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
if (queryParams) {
uri += queryParams;
}

return uri;
};

// override configure
OpenSeadragon.IIIFTileSource.prototype.configure = function( data, url ){
// Try to deduce our version and fake it upwards if needed

queryParams = url.match(/\?.*/);
tilesUrl = url.replace(queryParams, '');

if ( !$.isPlainObject(data) ) {
var options = configureFromXml10( data );
options['@context'] = "http://iiif.io/api/image/1.0/context.json";

//OLD//options['@id'] = url.replace('/info.xml', '');
options['@id'] = tilesUrl.replace('/info.xml', '');
if (queryParams) {
options['@id'] += queryParams;
}

options.version = 1;
return options;
} else {
if ( !data['@context'] ) {
data['@context'] = 'http://iiif.io/api/image/1.0/context.json';

//OLD//data['@id'] = url.replace('/info.json', '');
data['@id'] = tilesUrl.replace('/info.xml', '');
if (queryParams) {
data['@id'] += queryParams;
}

data.version = 1;
} else {
var context = data['@context'];
if (Array.isArray(context)) {
for (var i = 0; i < context.length; i++) {
if (typeof context[i] === 'string' &&
( /^http:\/\/iiif\.io\/api\/image\/[1-3]\/context\.json$/.test(context[i]) ||
context[i] === 'http://library.stanford.edu/iiif/image-api/1.1/context.json' ) ) {
context = context[i];
break;
}
}
}
switch (context) {
case 'http://iiif.io/api/image/1/context.json':
case 'http://library.stanford.edu/iiif/image-api/1.1/context.json':
data.version = 1;
break;
case 'http://iiif.io/api/image/2/context.json':
data.version = 2;
break;
case 'http://iiif.io/api/image/3/context.json':
data.version = 3;
break;
default:
$.console.error('Data has a @context property which contains no known IIIF context URI.');
}
}
if ( !data['@id'] && data['id'] ) {
data['@id'] = data['id'];
}

if (queryParams) {
data['@id'] += queryParams;
}

if(data.preferredFormats) {
for (var f = 0; f < data.preferredFormats.length; f++ ) {
if ( OpenSeadragon.imageFormatSupported(data.preferredFormats[f]) ) {
data.tileFormat = data.preferredFormats[f];
break;
}
}
}
return data;
}
};

/* Book Reader Overrides/extensions */

jQuery.extend(BookReader.defaultOptions, {
iiifmanifesturl: '',
iiifmanifest: null,
Expand Down

0 comments on commit 8f4a772

Please sign in to comment.