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 = [ 2357,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2309,2373 ]; gb.pageH = [ 3884,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3589,3861 ]; gb.leafMap = [ 1,2,3,4,5,6,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,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396 ]; gb.pageNums = [ null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,'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',null,null,'27','28','29','30','31','32','33','34','35','36',null,null,'37','38','39','40','41','42',null,null,'43','44','45','46','47','48',null,null,'49','50','51','52','53','54','55','56','57','58',null,null,'59','60','61','62','63','64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79','80',null,null,'81','82','83','84','85','86','87','88','89','90','91','92','93','94','95','96',null,null,'97','98','99','100','101','102','103','104','105','106',null,null,'107','108','109','110','111','112','113','114','115','116','117','118','119','120','121','122','123','124','125','126','127','128','129','130','131','132','133','134','135','136','137','138','139','140','141','142',null,null,'143','144','145','146','147','148','149','150','151','152','153','154','155','156','157','158','159','160','161','162','163','164','165','166','167','168',null,null,'169','170','171','172','173','174','175','176','177','178','179','180','181','182','183','184','185','186','187','188','189','190','191','192','193','194','195','196','197','198','199','200','201','202','203','204','205','206','207','208',null,null,'209','210','211','212','213','214','215','216','217','218','219','220','221','222','223','224','225','226','227','228','229','230','231','232','233','234',null,null,'235','236','237','238','239','240',null,null,'241','242','243','244','245','246','247','248','249','250','251','252',null,null,'253','254','255','256','257','258','259','260','261','262','263','264','265','266','267','268','269','270','271','272','273','274','275','276','277','278','279','280','281','282','283','284','285','286','287','288',null,null,'289','290','291','292','293','294','295','296','297','298','299','300','301','302','303','304',null,null,'305','306','307','308','309','310','311','312','313','314','315','316','317','318','319','320','321','322','323','324','325','326','327','328','329','330','331','332','333','334','335','336','337','338','339','340','341','342','343','344',null,null,null,null ]; gb.numLeafs = gb.pageW.length; gb.bookId = 'dogsallaboutthem00leig'; gb.zip = '/2/items/dogsallaboutthem00leig/dogsallaboutthem00leig_jp2.zip'; gb.subPrefix = ''; gb.server = 'ia301540.us.archive.org'; gb.bookTitle= 'Dogs and all about them'; gb.bookPath = '/2/items/dogsallaboutthem00leig/dogsallaboutthem00leig'; gb.bookUrl = 'http://www.archive.org/details/dogsallaboutthem00leig'; 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();