mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
parent
131bf48b98
commit
1a782d0bd4
24 changed files with 415 additions and 532 deletions
|
@ -9,13 +9,6 @@ EPUBJS.reader.plugins = {}; //-- Attach extra Controllers as plugins (like searc
|
|||
return new EPUBJS.Reader(path, options);
|
||||
};
|
||||
|
||||
_.extend(ePubReader, {
|
||||
noConflict : function() {
|
||||
root.ePubReader = previousReader;
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
//exports to multiple environments
|
||||
if (typeof define === 'function' && define.amd)
|
||||
//AMD
|
||||
|
@ -34,15 +27,15 @@ EPUBJS.Reader = function(bookPath, _options) {
|
|||
var search = window.location.search;
|
||||
var parameters;
|
||||
|
||||
this.settings = _.defaults(_options || {}, {
|
||||
this.settings = EPUBJS.core.defaults(_options || {}, {
|
||||
bookPath : bookPath,
|
||||
restore : true,
|
||||
reload : false,
|
||||
bookmarks : null,
|
||||
annotations : null,
|
||||
contained : null,
|
||||
bookKey : null,
|
||||
styles : null,
|
||||
bookmarks : undefined,
|
||||
annotations : undefined,
|
||||
contained : undefined,
|
||||
bookKey : undefined,
|
||||
styles : undefined,
|
||||
sidebarReflow: false,
|
||||
generatePagination: false,
|
||||
history: true
|
||||
|
@ -60,7 +53,7 @@ EPUBJS.Reader = function(bookPath, _options) {
|
|||
}
|
||||
|
||||
this.setBookKey(this.settings.bookPath); //-- This could be username + path or any unique string
|
||||
|
||||
|
||||
if(this.settings.restore && this.isSaved()) {
|
||||
this.applySavedSettings();
|
||||
}
|
||||
|
@ -68,27 +61,19 @@ EPUBJS.Reader = function(bookPath, _options) {
|
|||
this.settings.styles = this.settings.styles || {
|
||||
fontSize : "100%"
|
||||
};
|
||||
|
||||
this.book = book = new EPUBJS.Book({
|
||||
bookPath: this.settings.bookPath,
|
||||
restore: this.settings.restore,
|
||||
reload: this.settings.reload,
|
||||
contained: this.settings.contained,
|
||||
bookKey: this.settings.bookKey,
|
||||
styles: this.settings.styles,
|
||||
withCredentials: this.settings.withCredentials
|
||||
});
|
||||
|
||||
|
||||
this.book = book = new EPUBJS.Book(this.settings);
|
||||
|
||||
if(this.settings.previousLocationCfi) {
|
||||
book.gotoCfi(this.settings.previousLocationCfi);
|
||||
}
|
||||
|
||||
|
||||
this.offline = false;
|
||||
this.sidebarOpen = false;
|
||||
if(!this.settings.bookmarks) {
|
||||
this.settings.bookmarks = [];
|
||||
}
|
||||
|
||||
|
||||
if(!this.settings.annotations) {
|
||||
this.settings.annotations = [];
|
||||
}
|
||||
|
@ -98,21 +83,21 @@ EPUBJS.Reader = function(bookPath, _options) {
|
|||
}
|
||||
|
||||
book.renderTo("viewer");
|
||||
|
||||
|
||||
reader.ReaderController = EPUBJS.reader.ReaderController.call(reader, book);
|
||||
reader.SettingsController = EPUBJS.reader.SettingsController.call(reader, book);
|
||||
reader.ControlsController = EPUBJS.reader.ControlsController.call(reader, book);
|
||||
reader.SidebarController = EPUBJS.reader.SidebarController.call(reader, book);
|
||||
reader.BookmarksController = EPUBJS.reader.BookmarksController.call(reader, book);
|
||||
reader.NotesController = EPUBJS.reader.NotesController.call(reader, book);
|
||||
|
||||
|
||||
// Call Plugins
|
||||
for(plugin in EPUBJS.reader.plugins) {
|
||||
if(EPUBJS.reader.plugins.hasOwnProperty(plugin)) {
|
||||
reader[plugin] = EPUBJS.reader.plugins[plugin].call(reader, book);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
book.ready.all.then(function() {
|
||||
reader.ReaderController.hideLoader();
|
||||
});
|
||||
|
@ -124,16 +109,16 @@ EPUBJS.Reader = function(bookPath, _options) {
|
|||
book.getToc().then(function(toc) {
|
||||
reader.TocController = EPUBJS.reader.TocController.call(reader, toc);
|
||||
});
|
||||
|
||||
|
||||
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
||||
|
||||
|
||||
window.addEventListener("hashchange", this.hashChanged.bind(this), false);
|
||||
|
||||
document.addEventListener('keydown', this.adjustFontSize.bind(this), false);
|
||||
|
||||
|
||||
book.on("renderer:keydown", this.adjustFontSize.bind(this));
|
||||
book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this));
|
||||
|
||||
|
||||
book.on("renderer:selected", this.selectedRange.bind(this));
|
||||
|
||||
return this;
|
||||
|
@ -146,19 +131,19 @@ EPUBJS.Reader.prototype.adjustFontSize = function(e) {
|
|||
var MINUS = 189;
|
||||
var ZERO = 48;
|
||||
var MOD = (e.ctrlKey || e.metaKey );
|
||||
|
||||
|
||||
if(!this.settings.styles) return;
|
||||
|
||||
|
||||
if(!this.settings.styles.fontSize) {
|
||||
this.settings.styles.fontSize = "100%";
|
||||
}
|
||||
|
||||
|
||||
fontSize = parseInt(this.settings.styles.fontSize.slice(0, -1));
|
||||
|
||||
if(MOD && e.keyCode == PLUS) {
|
||||
e.preventDefault();
|
||||
this.book.setStyle("fontSize", (fontSize + interval) + "%");
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(MOD && e.keyCode == MINUS){
|
||||
|
@ -166,7 +151,7 @@ EPUBJS.Reader.prototype.adjustFontSize = function(e) {
|
|||
e.preventDefault();
|
||||
this.book.setStyle("fontSize", (fontSize - interval) + "%");
|
||||
}
|
||||
|
||||
|
||||
if(MOD && e.keyCode == ZERO){
|
||||
e.preventDefault();
|
||||
this.book.setStyle("fontSize", "100%");
|
||||
|
@ -178,22 +163,22 @@ EPUBJS.Reader.prototype.addBookmark = function(cfi) {
|
|||
if(present > -1 ) return;
|
||||
|
||||
this.settings.bookmarks.push(cfi);
|
||||
|
||||
|
||||
this.trigger("reader:bookmarked", cfi);
|
||||
};
|
||||
|
||||
EPUBJS.Reader.prototype.removeBookmark = function(cfi) {
|
||||
var bookmark = this.isBookmarked(cfi);
|
||||
if( bookmark === -1 ) return;
|
||||
|
||||
|
||||
this.settings.bookmarks.splice(bookmark, 1);
|
||||
|
||||
|
||||
this.trigger("reader:unbookmarked", bookmark);
|
||||
};
|
||||
|
||||
EPUBJS.Reader.prototype.isBookmarked = function(cfi) {
|
||||
var bookmarks = this.settings.bookmarks;
|
||||
|
||||
|
||||
return bookmarks.indexOf(cfi);
|
||||
};
|
||||
|
||||
|
@ -202,7 +187,7 @@ EPUBJS.Reader.prototype.searchBookmarked = function(cfi) {
|
|||
var bookmarks = this.settings.bookmarks,
|
||||
len = bookmarks.length,
|
||||
i;
|
||||
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
if (bookmarks[i]['cfi'] === cfi) return i;
|
||||
}
|
||||
|
@ -242,11 +227,11 @@ EPUBJS.Reader.prototype.setBookKey = function(identifier){
|
|||
//-- Checks if the book setting can be retrieved from localStorage
|
||||
EPUBJS.Reader.prototype.isSaved = function(bookPath) {
|
||||
var storedSettings;
|
||||
|
||||
|
||||
if(!localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
storedSettings = localStorage.getItem(this.settings.bookKey);
|
||||
|
||||
if(storedSettings === null) {
|
||||
|
@ -260,13 +245,13 @@ EPUBJS.Reader.prototype.removeSavedSettings = function() {
|
|||
if(!localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
localStorage.removeItem(this.settings.bookKey);
|
||||
};
|
||||
|
||||
EPUBJS.Reader.prototype.applySavedSettings = function() {
|
||||
var stored;
|
||||
|
||||
|
||||
if(!localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
@ -276,9 +261,14 @@ EPUBJS.Reader.prototype.applySavedSettings = function() {
|
|||
} catch (e) { // parsing error of localStorage
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(stored) {
|
||||
this.settings = _.defaults(this.settings, stored);
|
||||
// Merge styles
|
||||
if(store.styles) {
|
||||
this.settings.styles = EPUBJS.core.defaults(this.settings.styles, store.styles);
|
||||
}
|
||||
// Merge the rest
|
||||
this.settings = EPUBJS.core.defaults(this.settings, stored);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue