This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepubreader.js
84 lines (71 loc) · 2.08 KB
/
epubreader.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
/*
* @overview EPUB reader module
* @copyright Copyright (c) 2015 Borislav Sapundzhiev <[email protected]>
* @license Licensed under MIT license
* See https://opensource.org/licenses/MIT
*/
define(function(require, exports, module) {
"use strict";
var ePub = require("ext/viewerEPUB/epubjs/epub");
var book, rendered;
var bookFileName;
var defaultBookStyle = {
"font-size": "1.2em",
"text-align": "justify"
};
var options = {
bookPath : null,
version: 1, // Changing will cause stored Book information to be reloaded
restore: true,// Skips parsing epub contents, loading from localstorage instead
storage: false, // true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
spreads: false, // Displays two columns
fixedLayout : true, //-- Will turn off pagination
styles : {}, // Styles to be applied to epub
width : false,
height: false,
};
function loadBook(filePath, renderID) {
bookFileName = filePath;
book = ePub(filePath, options);
setStyle(defaultBookStyle);
rendered = book.renderTo(renderID);
book.on('renderer:locationChanged', function(locationCfi) {
storeLastPage(locationCfi);
});
book.on('book:pageChanged', function(location) {
console.log("pageChanged", location);
});
book.on('book:ready', function() {
if (options.restore) {
restoreLastPage();
}
});
}
function restoreLastPage() {
var locationCfi = storeLastPage();
book.displayChapter(locationCfi);
}
function storeLastPage(storeData) {
if (storeData) {
localStorage.setItem(bookFileName, storeData);
} else {
return localStorage.getItem(bookFileName);
}
}
function prevPage() {
book.prevPage();
}
function nextPage() {
book.nextPage();
}
function setStyle (obj) {
for (var key in obj) {
book.setStyle(key, obj[key]);
}
}
exports.options = options;
exports.loadBook = loadBook;
exports.prevPage = prevPage;
exports.nextPage = nextPage;
exports.setStyle = setStyle;
});