-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e39bc5c
Showing
78 changed files
with
8,280 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
// Bind to the BookReader object providing facilities to set the necessary | ||
// BookReader functions from a IIIF endpoint URL. | ||
|
||
(function(BR){ | ||
|
||
BR.prototype.IIIF = function (config) { | ||
// config should have the url of a sequence | ||
// within a passed-in manifest. | ||
var brInstance = this; | ||
brInstance.IIIFsequence = { | ||
title: null, | ||
imagesList: [], | ||
numPages: null, | ||
bookUrl: null | ||
}; | ||
oldInit = brInstance.init; | ||
oldMode = brInstance.mode; | ||
brInstance.init = function() { | ||
load(config); | ||
}; | ||
brInstance.mode = 2; | ||
|
||
function bindBRMethods(){ | ||
brInstance.getPageNum = function(index) { | ||
return index+1; | ||
}; | ||
|
||
brInstance.getSpreadIndices = function(pindex) { | ||
var spreadIndices = [null, null]; | ||
if ('rl' == brInstance.pageProgression) { | ||
// Right to Left | ||
if (brInstance.getPageSide(pindex) == 'R') { | ||
spreadIndices[1] = pindex; | ||
spreadIndices[0] = pindex + 1; | ||
} else { | ||
// Given index was LHS | ||
spreadIndices[0] = pindex; | ||
spreadIndices[1] = pindex - 1; | ||
} | ||
} else { | ||
// Left to right | ||
if (brInstance.getPageSide(pindex) == 'L') { | ||
spreadIndices[0] = pindex; | ||
spreadIndices[1] = pindex + 1; | ||
} else { | ||
// Given index was RHS | ||
spreadIndices[1] = pindex; | ||
spreadIndices[0] = pindex - 1; | ||
} | ||
} | ||
|
||
return spreadIndices; | ||
}; | ||
|
||
brInstance.getPageSide = function(index) { | ||
if (0 == (index & 0x1)) { | ||
return 'R'; | ||
} else { | ||
return 'L'; | ||
} | ||
}; | ||
|
||
brInstance.getPageHeight = function(index) { | ||
console.log(index); | ||
var fullWidth = brInstance.IIIFsequence.imagesList[index].width, | ||
fullHeight = brInstance.IIIFsequence.imagesList[index].height, | ||
scaleRatio = config.maxWidth/fullWidth; | ||
|
||
return fullHeight*scaleRatio; | ||
}; | ||
|
||
brInstance.getPageWidth = function(index) { | ||
var fullWidth = brInstance.IIIFsequence.imagesList[index].width, | ||
scaleRatio = config.maxWidth/fullWidth; | ||
|
||
return fullWidth*scaleRatio; | ||
}; | ||
|
||
brInstance.getPageURI = function(index) { | ||
// Finds the image info.json url | ||
// from the loaded sequence and returns the | ||
// IIIF-formatted url for the page image | ||
// based on the provided configuration object | ||
// (adjusting for width, etc.). | ||
var infoJsonUrl = brInstance.IIIFsequence.imagesList[index].imageUrl; | ||
var url = infoJsonUrl + "/full/" + config.maxWidth + ",/0/native.jpg"; | ||
return url; | ||
}; | ||
|
||
} | ||
|
||
function load(config) { | ||
|
||
endpointUrl = config.url, | ||
sequenceId = config.sequenceId; | ||
|
||
jQuery.ajax({ | ||
url: endpointUrl.replace(/^\s+|\s+$/g, ''), | ||
dataType: 'json', | ||
async: true, | ||
|
||
success: function(jsonLd) { | ||
brInstance.jsonLd = jsonLd; | ||
brInstance.bookTitle = jsonLd.label; | ||
brInstance.bookUrl = '#'; | ||
parseSequence(sequenceId); | ||
bindBRMethods(); | ||
|
||
// Call the old initialisation after | ||
// the urls are finished. A better implementation | ||
// would be to employ promises (Likely by including | ||
// the Q Promises/A+ implementation. See issue #1 at | ||
// github. | ||
oldInit.call(brInstance); | ||
|
||
// // The following is an attrocious hack and must not | ||
// // be allowed to persist. See issue #2 at github.com | ||
// setTimeout(function() { jQuery(window).trigger('resize'); console.log("resize event fired")}, 2500); | ||
}, | ||
|
||
error: function() { | ||
console.log('Failed loading ' + brInstance.uri); | ||
} | ||
|
||
}); | ||
|
||
} | ||
|
||
function parseSequence(sequenceId) { | ||
|
||
jQuery.each(brInstance.jsonLd.sequences, function(index, sequence) { | ||
if (sequence['@id'] === sequenceId) { | ||
brInstance.IIIFsequence.title = "here's a sequence"; | ||
brInstance.numLeafs = 515; | ||
brInstance.IIIFsequence.bookUrl = "http://iiif.io"; | ||
brInstance.IIIFsequence.imagesList = getImagesList(sequence); | ||
} | ||
}); | ||
|
||
delete brInstance.jsonLd; | ||
|
||
} | ||
|
||
function getImagesList(sequence) { | ||
var imagesList = []; | ||
|
||
jQuery.each(sequence.canvases, function(index, canvas) { | ||
var imageObj; | ||
|
||
if (canvas['@type'] === 'sc:Canvas') { | ||
var images = canvas.resources || canvas.images; | ||
|
||
jQuery.each(images, function(index, image) { | ||
if (image['@type'] === 'oa:Annotation') { | ||
imageObj = getImageObject(image); | ||
imageObj.canvasWidth = canvas.width; | ||
imageObj.canvasHeight = canvas.height; | ||
|
||
if (!(/#xywh/).test(image.on)) { | ||
imagesList.push(imageObj); | ||
} | ||
} | ||
}); | ||
|
||
} | ||
}); | ||
|
||
return imagesList; | ||
} | ||
|
||
function getImageObject (image) { | ||
var resource = image.resource; | ||
|
||
if (resource.hasOwnProperty('@type') && resource['@type'] === 'oa:Choice') { | ||
var imageObj = getImageProperties(resource.default); | ||
} else { | ||
imageObj = getImageProperties(resource); | ||
} | ||
|
||
return(imageObj); | ||
} | ||
|
||
function getImageProperties(image) { | ||
var imageObj = { | ||
height: image.height || 0, | ||
width: image.width || 0, | ||
imageUrl: image.service['@id'].replace(/\/$/, ''), | ||
}; | ||
|
||
imageObj.aspectRatio = (imageObj.width / imageObj.height) || 1; | ||
|
||
return imageObj; | ||
} | ||
|
||
}; | ||
|
||
})(BookReader); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# IIIF Adapter for the OpenLibrary BookReader | ||
## Introduction | ||
The following simple plugin is designed to extend the Internet Archive's [ BookReader javascript library ](https://github.com/openlibrary/bookreader), part of their [ OpenLibrary ](https://openlibrary.org/) project, so that IABookReader instances can consume images served from a IIIF-compatible backend. Many of the world's top universities, libraries, museums, and repositories have made thousands of previously inaccessible, rare resources freely and interoperably available using the IIIF API specifications. For more information, explore the documentation on [iiif.io](https://www.iiif.io). | ||
|
||
## Usage | ||
For a simple usage example, have a look in the [example directory](), or view the source of the available [live demo](). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Custom overrides for BookReader Demo. | ||
*/ | ||
|
||
/* Hide print and embed functionality */ | ||
#BRtoolbar .embed, .print { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
|
||
<html> | ||
<head> | ||
<title>bookreader demo</title> | ||
|
||
<link rel="stylesheet" type="text/css" href="js/lib/BookReader/BookReader.css"/> | ||
<!-- Custom CSS overrides --> | ||
<link rel="stylesheet" type="text/css" href="css/main.css"/> | ||
|
||
<script type="text/javascript" src="http://www.archive.org/includes/jquery-1.4.2.min.js"></script> | ||
<script type="text/javascript" src="http://www.archive.org/bookreader/jquery-ui-1.8.5.custom.min.js"></script> | ||
|
||
<script type="text/javascript" src="http://www.archive.org/bookreader/dragscrollable.js"></script> | ||
<script type="text/javascript" src="http://www.archive.org/bookreader/jquery.colorbox-min.js"></script> | ||
<script type="text/javascript" src="http://www.archive.org/bookreader/jquery.ui.ipad.js"></script> | ||
<script type="text/javascript" src="http://www.archive.org/bookreader/jquery.bt.min.js"></script> | ||
|
||
<script type="text/javascript" src="js/lib/BookReader/BookReader.js"></script> | ||
</head> | ||
<body style="background-color: ##939598;"> | ||
|
||
<div id="BookReader"> | ||
Internet Archive BookReader Demo <br/> | ||
|
||
<noscript> | ||
<p> | ||
The BookReader requires JavaScript to be enabled. Please check that your browser supports JavaScript and that it is enabled in the browser settings. You can also try one of the <a href="http://www.archive.org/details/goodytwoshoes00newyiala"> other formats of the book</a>. | ||
</p> | ||
</noscript> | ||
</div> | ||
|
||
<script type="text/javascript" src="js/lib/IIIFBookReader.js"></script> | ||
<script type="text/javascript" src="js/main.js"></script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.