along with BookReader. If not, see <http://www.gnu.org/licenses/>.
*/
+header('Content-Type: application/javascript');
+
$id = $_REQUEST['id'];
$itemPath = $_REQUEST['itemPath'];
$subPrefix = $_REQUEST['subPrefix'];
$server = $_REQUEST['server'];
+// $$$mang this code has been refactored into BookReaderMeta.inc.php for use e.g. by
+// BookReaderPreview.php and BookReaderImages.php. The code below should be
+// taken out and replaced by calls into BookReaderMeta
+
// Check if we're on a dev vhost and point to JSIA in the user's public_html on the datanode
+
// $$$ TODO consolidate this logic
if (strpos($_SERVER["REQUEST_URI"], "/~mang") === 0) { // Serving out of home dir
$server .= ':80/~mang';
+} else if (strpos($_SERVER["REQUEST_URI"], "/~rkumar") === 0) { // Serving out of home dir
+ $server .= ':80/~rkumar';
} else if (strpos($_SERVER["REQUEST_URI"], "/~testflip") === 0) { // Serving out of home dir
$server .= ':80/~testflip';
}
}
}
+// Single images in the Internet Archive scandata.xml metadata are (somewhat incorrectly)
+// given a "leaf" number. Some of these images from the scanning process should not
+// be displayed in the BookReader (for example colour calibration cards). Since some
+// of the scanned images will not be displayed in the BookReader (those marked with
+// addToAccessFormats false in the scandata.xml) leaf numbers and BookReader page
+// indexes are generally not the same. This function returns the BookReader page
+// index given a scanned leaf number.
+//
+// This function is used, for example, to map between search results (that use the
+// leaf numbers) and the displayed pages in the BookReader.
br.leafNumToIndex = function(leafNum) {
for (var index = 0; index < this.leafMap.length; index++) {
if (this.leafMap[index] == leafNum) {
return "<iframe src='" + this.getEmbedURL() + "' width='480px' height='430px'></iframe>";
}
+// getOpenLibraryRecord
+br.getOpenLibraryRecord = function(callback) {
+ // Try looking up by ocaid first, then by source_record
+
+ var jsonURL = 'http://openlibrary.org/query.json?type=/type/edition&*=&ocaid=' + br.bookId;
+ $.ajax({
+ url: jsonURL,
+ success: function(data) {
+ if (data && data.length > 0) {
+ callback(br, data[0]);
+ } else {
+ // try sourceid
+ jsonURL = 'http://openlibrary.org/query.json?type=/type/edition&*=&source_records=ia:' + br.bookId;
+ $.ajax({
+ url: jsonURL,
+ success: function(data) {
+ if (data && data.length > 0) {
+ callback(br, data[0]);
+ }
+ },
+ dataType: 'jsonp'
+ });
+ }
+ },
+ dataType: 'jsonp'
+ });
+}
+
br.pageW = [
<?
$i=0;
# Load some values from meta.xml
if ('' != $metaData->{'page-progression'}) {
- echo "br.pageProgression = '" . $metaData->{"page-progression"} . "';";
+ echo "br.pageProgression = '" . $metaData->{"page-progression"} . "';\n";
} else {
// Assume page progression is Left To Right
- echo "br.pageProgression = 'lr';";
+ echo "br.pageProgression = 'lr';\n";
+}
+
+if ('browserlending' == $metaData->{'collection'}) {
+ echo "br.olAuth = true;\n";
+} else {
+ echo "br.olAuth = false; //" . $metaData->{'collection'} ."\n";
}
# Special cases
}
} // brConfig
-br.cleanupMetadata();
-br.init();
+function OLAuth() {
+ this.authUrl = 'http://openlibrary.org/ia_auth/' + br.bookId;
+ return this;
+}
+
+OLAuth.prototype.init = function() {
+ var htmlStr = '<p style="text-align:center;"><b>Authenticating in-browser loan with openlibrary.org!</b></p>';
+ htmlStr += '<p>Please wait...</p>';
+
+ this.showPopup("#ddd", "#000", htmlStr);
+ $.ajax({url:this.authUrl, dataType:'jsonp', jsonpCallback:'olAuth.initCallback'});
+}
+
+OLAuth.prototype.showPopup = function(bgColor, textColor, msg) {
+ this.popup = document.createElement("div");
+ $(this.popup).css({
+ position: 'absolute',
+ top: '20px',
+ left: ($('#BookReader').attr('clientWidth')-400)/2 + 'px',
+ width: '400px',
+ padding: "20px",
+ border: "3px double #999999",
+ zIndex: 3,
+ backgroundColor: bgColor,
+ color: textColor
+ }).appendTo('#BookReader');
+
+ this.popup.innerHTML = msg;
+
+}
+
+OLAuth.prototype.initCallback = function(obj) {
+ if (false == obj.success) {
+ $(this.popup).css({
+ backgroundColor: "#f00",
+ color: "#fff"
+ });
+
+ this.popup.innerHTML = obj.msg;
+ return;
+ }
+
+ //user is authenticated
+ this.setCookie(obj.token);
+ this.startPolling();
+ br.init();
+}
+
+OLAuth.prototype.callback = function(obj) {
+ if (false == obj.success) {
+ this.showPopup("#f00", "#fff", obj.msg);
+ clearInterval(this.poller);
+ this.ttsPoller = null;
+ } else {
+ this.setCookie(obj.token);
+ }
+}
+
+OLAuth.prototype.setCookie = function(value) {
+ var date = new Date();
+ date.setTime(date.getTime()+(24*60*60*1000)); //one day expiry
+ var expiry = date.toGMTString();
+ var cookie = 'loan-'+br.bookId+'='+value;
+ cookie += '; expires='+expiry;
+ cookie += '; path=/; domain=.archive.org;';
+ document.cookie = cookie;
+}
+
+OLAuth.prototype.startPolling = function () {
+ var self = this;
+ this.poller=setInterval(function(){
+ $.ajax({url:self.authUrl, dataType:'jsonp', jsonpCallback:'olAuth.callback'});
+ },300000);
+}
+
+br.cleanupMetadata();
+if (br.olAuth) {
+ var olAuth = new OLAuth();
+ olAuth.init();
+} else {
+ br.init();
+}
<?
}
?>
+