2 // This file shows the minimum you need to provide to GnuBook to display a book
4 // Copyright(c)2008-2009 Internet Archive. Software license AGPL version 3.
6 // Create the GnuBook object
9 // Return the width of a given page. Here we assume all images are 800 pixels wide
10 gb.getPageWidth = function(index) {
14 // Return the height of a given page. Here we assume all images are 1200 pixels high
15 gb.getPageHeight = function(index) {
19 // We load the images from archive.org -- you can modify this function to retrieve images
20 // using a different URL structure
21 gb.getPageURI = function(index) {
23 var imgStr = (index+1).toString();
24 var re = new RegExp("0{"+imgStr.length+"}$");
25 var url = 'http://www.archive.org/download/GnuBook/img/page'+leafStr.replace(re, imgStr) + '.jpg';
29 // Return which side, left or right, that a given page should be displayed on
30 gb.getPageSide = function(index) {
31 if (0 == (index & 0x1)) {
38 // This function returns the left and right indices for the user-visible
39 // spread that contains the given index. The return values may be
40 // null if there is no facing page or the index is invalid.
41 gb.getSpreadIndices = function(pindex) {
42 var spreadIndices = [null, null];
43 if ('rl' == this.pageProgression) {
45 if (this.getPageSide(pindex) == 'R') {
46 spreadIndices[1] = pindex;
47 spreadIndices[0] = pindex + 1;
49 // Given index was LHS
50 spreadIndices[0] = pindex;
51 spreadIndices[1] = pindex - 1;
55 if (this.getPageSide(pindex) == 'L') {
56 spreadIndices[0] = pindex;
57 spreadIndices[1] = pindex + 1;
59 // Given index was RHS
60 spreadIndices[1] = pindex;
61 spreadIndices[0] = pindex - 1;
68 // For a given "accessible page index" return the page number in the book.
70 // For example, index 5 might correspond to "Page 1" if there is front matter such
71 // as a title page and table of contents.
72 gb.getPageNum = function(index) {
76 // Total number of leafs
79 // Book title and the URL used for the book title link
80 gb.bookTitle= 'Open Library Bookreader Presentation';
81 gb.bookUrl = 'http://openlibrary.org';