Merge branch 'newui' of git@github.com:rajbot/bookreader into newui
[bookreader.git] / BookReaderDemo / BookReaderJSSimple.js
1 // 
2 // This file shows the minimum you need to provide to BookReader to display a book
3 //
4 // Copyright(c)2008-2009 Internet Archive. Software license AGPL version 3.
5
6 // Create the BookReader object
7 br = new BookReader();
8
9 // Return the width of a given page.  Here we assume all images are 800 pixels wide
10 br.getPageWidth = function(index) {
11     return 800;
12 }
13
14 // Return the height of a given page.  Here we assume all images are 1200 pixels high
15 br.getPageHeight = function(index) {
16     return 1200;
17 }
18
19 // We load the images from archive.org -- you can modify this function to retrieve images
20 // using a different URL structure
21 br.getPageURI = function(index, reduce, rotate) {
22     // reduce and rotate are ignored in this simple implementation, but we
23     // could e.g. look at reduce and load images from a different directory
24     // or pass the information to an image server
25     var leafStr = '000';            
26     var imgStr = (index+1).toString();
27     var re = new RegExp("0{"+imgStr.length+"}$");
28     var url = 'http://www.archive.org/download/BookReader/img/page'+leafStr.replace(re, imgStr) + '.jpg';
29     return url;
30 }
31
32 // Return which side, left or right, that a given page should be displayed on
33 br.getPageSide = function(index) {
34     if (0 == (index & 0x1)) {
35         return 'R';
36     } else {
37         return 'L';
38     }
39 }
40
41 // This function returns the left and right indices for the user-visible
42 // spread that contains the given index.  The return values may be
43 // null if there is no facing page or the index is invalid.
44 br.getSpreadIndices = function(pindex) {   
45     var spreadIndices = [null, null]; 
46     if ('rl' == this.pageProgression) {
47         // Right to Left
48         if (this.getPageSide(pindex) == 'R') {
49             spreadIndices[1] = pindex;
50             spreadIndices[0] = pindex + 1;
51         } else {
52             // Given index was LHS
53             spreadIndices[0] = pindex;
54             spreadIndices[1] = pindex - 1;
55         }
56     } else {
57         // Left to right
58         if (this.getPageSide(pindex) == 'L') {
59             spreadIndices[0] = pindex;
60             spreadIndices[1] = pindex + 1;
61         } else {
62             // Given index was RHS
63             spreadIndices[1] = pindex;
64             spreadIndices[0] = pindex - 1;
65         }
66     }
67     
68     return spreadIndices;
69 }
70
71 // For a given "accessible page index" return the page number in the book.
72 //
73 // For example, index 5 might correspond to "Page 1" if there is front matter such
74 // as a title page and table of contents.
75 br.getPageNum = function(index) {
76     return index+1;
77 }
78
79 // Total number of leafs
80 br.numLeafs = 15;
81
82 // Book title and the URL used for the book title link
83 br.bookTitle= 'Open Library BookReader Presentation';
84 br.bookUrl  = 'http://openlibrary.org';
85
86 // Override the path used to find UI images
87 br.imagesBaseURL = '../BookReader/images/';
88
89 br.getEmbedCode = function(frameWidth, frameHeight, viewParams) {
90     return "Embed code not supported in bookreader demo.";
91 }
92
93 // Let's go!
94 br.init();
95
96 // read-aloud and search need backend compenents and are not supported in the demo
97 $('#BRtoolbar').find('.read').hide();
98 $('#textSrch').hide();
99 $('#btnSrch').hide();