gb = new GnuBook(); gb.titleLeaf = 9; gb.getPageWidth = function(index) { return this.pageW[index]; } gb.getPageHeight = function(index) { return this.pageH[index]; } // Returns true if page image is available rotated gb.canRotatePage = function(index) { return 'jp2' == this.imageFormat; // Assume single format for now } // reduce defaults to 1 (no reduction) // rotate defaults to 0 (no rotation) gb.getPageURI = function(index, reduce, rotate) { var _reduce; var _rotate; if ('undefined' == typeof(reduce)) { _reduce = 1; } else { _reduce = reduce; } if ('undefined' == typeof(rotate)) { _rotate = 0; } else { _rotate = rotate; } var file = this._getPageFile(index); // $$$ add more image stack formats here if (1==this.mode) { var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+file+'&scale='+_reduce+'&rotate='+_rotate; } else { if ('undefined' == typeof(reduce)) { // reduce not passed in var ratio = this.getPageHeight(index) / this.twoPage.height; var scale; // $$$ we make an assumption here that the scales are available pow2 (like kakadu) if (ratio < 2) { scale = 1; } else if (ratio < 4) { scale = 2; } else if (ratio < 8) { scale = 4; } else if (ratio < 16) { scale = 8; } else if (ratio < 32) { scale = 16; } else { scale = 32; } _reduce = scale; } var url = 'http://'+this.server+'/GnuBook/GnuBookImages.php?zip='+this.zip+'&file='+file+'&scale='+_reduce+'&rotate='+_rotate; } return url; } gb._getPageFile = function(index) { var leafStr = '0000'; var imgStr = this.leafMap[index].toString(); var re = new RegExp("0{"+imgStr.length+"}$"); var insideZipPrefix = this.subPrefix.match('[^/]+$'); var file = insideZipPrefix + '_' + this.imageFormat + '/' + insideZipPrefix + '_' + leafStr.replace(re, imgStr) + '.' + this.imageFormat; return file; } gb.getPageSide = function(index) { //assume the book starts with a cover (right-hand leaf) //we should really get handside from scandata.xml // $$$ we should get this from scandata instead of assuming the accessible // leafs are contiguous if ('rl' != this.pageProgression) { // If pageProgression is not set RTL we assume it is LTR if (0 == (index & 0x1)) { // Even-numbered page return 'R'; } else { // Odd-numbered page return 'L'; } } else { // RTL if (0 == (index & 0x1)) { return 'L'; } else { return 'R'; } } } gb.getPageNum = function(index) { var pageNum = this.pageNums[index]; if (pageNum) { return pageNum; } else { return 'n' + index; } } gb.leafNumToIndex = function(leafNum) { var index = jQuery.inArray(leafNum, this.leafMap); if (-1 == index) { return null; } else { return index; } } // This function returns the left and right indices for the user-visible // spread that contains the given index. The return values may be // null if there is no facing page or the index is invalid. gb.getSpreadIndices = function(pindex) { // $$$ we could make a separate function for the RTL case and // only bind it if necessary instead of always checking // $$$ we currently assume there are no gaps var spreadIndices = [null, null]; if ('rl' == this.pageProgression) { // Right to Left if (this.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 (this.getPageSide(pindex) == 'L') { spreadIndices[0] = pindex; spreadIndices[1] = pindex + 1; } else { // Given index was RHS spreadIndices[1] = pindex; spreadIndices[0] = pindex - 1; } } //console.log(" index %d mapped to spread %d,%d", pindex, spreadIndices[0], spreadIndices[1]); return spreadIndices; } // Remove the page number assertions for all but the highest index page with // a given assertion. Ensures there is only a single page "{pagenum}" // e.g. the last page asserted as page 5 retains that assertion. gb.uniquifyPageNums = function() { var seen = {}; for (var i = gb.pageNums.length - 1; i--; i >= 0) { var pageNum = gb.pageNums[i]; if ( !seen[pageNum] ) { seen[pageNum] = true; } else { gb.pageNums[i] = null; } } } gb.cleanupMetadata = function() { gb.uniquifyPageNums(); } // getEmbedURL //________ // Returns a URL for an embedded version of the current book gb.getEmbedURL = function() { // We could generate a URL hash fragment here but for now we just leave at defaults var url = 'http://' + window.location.host + '/stream/'+this.bookId; if (this.subPrefix != this.bookId) { // Only include if needed url += '/' + this.subPrefix; } url += '?ui=embed'; return url; } // getEmbedCode //________ // Returns the embed code HTML fragment suitable for copy and paste gb.getEmbedCode = function() { return ""; } gb.pageW = [ 2416,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2256,2416 ]; gb.pageH = [ 3563,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3354,3584 ]; gb.leafMap = [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112 ]; gb.pageNums = [ null,null,null,null,null,null,null,null,null,null,null,null,null,'6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59','60','61','62','63','64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79','80','81','82','83','84','85','86','87','88','89','90','91','92','93','94','95',null,null,null,null,null,null,null,null,null ]; gb.numLeafs = gb.pageW.length; gb.bookId = 'essaysirishameri00yeat'; gb.zip = '/2/items/essaysirishameri00yeat/essaysirishameri00yeat_jp2.zip'; gb.subPrefix = ''; gb.server = 'ia301503.us.archive.org'; gb.bookTitle= 'Essays, Irish and American.'; gb.bookPath = '/2/items/essaysirishameri00yeat/essaysirishameri00yeat'; gb.bookUrl = 'http://www.archive.org/details/essaysirishameri00yeat'; gb.imageFormat = 'jp2'; gb.pageProgression = 'lr'; // Check for config object // $$$ change this to use the newer params object if (typeof(gbConfig) != 'undefined') { if (typeof(gbConfig["ui"]) != 'undefined') { gb.ui = gbConfig["ui"]; } if (gbConfig['mode'] == 1) { gb.mode = 1; if (typeof(gbConfig['reduce'] != 'undefined')) { gb.reduce = gbConfig['reduce']; } } else if (gbConfig['mode'] == 2) { gb.mode = 2; } } // gbConfig gb.cleanupMetadata(); gb.init();