JSFiddle - React, Tailwind, and code Playground
by Shaun Ellis
JavaScript
(function($){
$.Manifest = function(manifestUri, location) {
jQuery.extend(true, this, {
jsonLd: null,
location: location,
uri: manifestUri,
request: null
});
this.init(manifestUri);
};
$.Manifest.prototype = {
init: function(manifestUri) {
var _this = this;
this.request = jQuery.ajax({
url: manifestUri,
dataType: 'json',
async: true
});
this.request.done(function(jsonLd) {
_this.jsonLd = jsonLd;
});
},
getThumbnailForCanvas : function(canvas, width) {
var version = "1.1",
service,
thumbnailUrl;
// Ensure width is an integer...
width = parseInt(width, 10);
// Respecting the Model...
if (canvas.hasOwnProperty('thumbnail')) {
// use the thumbnail image, prefer via a service
if (typeof(canvas.thumbnail) == 'string') {
thumbnailUrl = canvas.thumbnail;
} else if (canvas.thumbnail.hasOwnProperty('service')) {
// Get the IIIF Image API via the @context
service = canvas.thumbnail.service;
if (service.hasOwnProperty('@context')) {
version = $.Iiif.getVersionFromContext(service['@context']);
}
thumbnailUrl = $.Iiif.makeUriWithWidth(service['@id'], width, version);
} else {
thumbnailUrl = canvas.thumbnail['@id'];
}
} else {
// No thumbnail, use main image
var resource = canvas.images[0].resource;
service = resource['default'] ? resource['default'].service : resource.service;
if (service.hasOwnProperty('@context')) {
version = $.Iiif.getVersionFromContext(service['@context']);
}
thumbnailUrl = $.Iiif.makeUriWithWidth(service['@id'], width, version);
}
return thumbnailUrl;
},
getCanvases : function() {
var _this = this;
return _this.jsonLd.sequences[0].canvases;
},
...