/
BookReaderJSSimple.js
99 lines (85 loc) · 3.1 KB
/
BookReaderJSSimple.js
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
//
// This file shows the minimum you need to provide to BookReader to display a book
//
// Copyright(c)2008-2009 Internet Archive. Software license AGPL version 3.
// Create the BookReader object
br = new BookReader();
// Return the width of a given page. Here we assume all images are 800 pixels wide
br.getPageWidth = function(index) {
return 800;
}
// Return the height of a given page. Here we assume all images are 1200 pixels high
br.getPageHeight = function(index) {
return 1200;
}
// We load the images from archive.org -- you can modify this function to retrieve images
// using a different URL structure
br.getPageURI = function(index, reduce, rotate) {
// reduce and rotate are ignored in this simple implementation, but we
// could e.g. look at reduce and load images from a different directory
// or pass the information to an image server
var leafStr = '000';
var imgStr = (index+1).toString();
var re = new RegExp("0{"+imgStr.length+"}$");
var url = 'http://www.archive.org/download/BookReader/img/page'+leafStr.replace(re, imgStr) + '.jpg';
return url;
}
// Return which side, left or right, that a given page should be displayed on
br.getPageSide = function(index) {
if (0 == (index & 0x1)) {
return 'R';
} else {
return 'L';
}
}
// 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.
br.getSpreadIndices = function(pindex) {
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;
}
}
return spreadIndices;
}
// For a given "accessible page index" return the page number in the book.
//
// For example, index 5 might correspond to "Page 1" if there is front matter such
// as a title page and table of contents.
br.getPageNum = function(index) {
return index+1;
}
// Total number of leafs
br.numLeafs = 15;
// Book title and the URL used for the book title link
br.bookTitle= 'Open Library BookReader Presentation';
br.bookUrl = 'http://openlibrary.org';
// Override the path used to find UI images
br.imagesBaseURL = '../BookReader/images/';
br.getEmbedCode = function(frameWidth, frameHeight, viewParams) {
return "Embed code not supported in bookreader demo.";
}
// Let's go!
br.init();
// read-aloud and search need backend compenents and are not supported in the demo
$('#BRtoolbar').find('.read').hide();
$('#textSrch').hide();
$('#btnSrch').hide();