1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-30 12:00:31 +00:00
calibre-web/cps/static/js/reading/epub.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

/* global $, calibre, EPUBJS, ePubReader */
2019-12-22 14:28:43 +00:00
var reader;
(function() {
"use strict";
EPUBJS.filePath = calibre.filePath;
EPUBJS.cssPath = calibre.cssPath;
2019-12-22 14:28:43 +00:00
reader = ePubReader(calibre.bookUrl, {
restore: true,
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
});
if (calibre.useBookmarks) {
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove"));
} else {
$("#bookmark, #show-Bookmarks").remove();
}
/**
* @param {string} action - Add or remove bookmark
* @param {string|int} location - Location or zero
*/
function updateBookmark(action, location) {
// Remove other bookmarks (there can only be one)
if (action === "add") {
this.settings.bookmarks.filter(function (bookmark) {
return bookmark && bookmark !== location;
}).map(function (bookmark) {
this.removeBookmark(bookmark);
}.bind(this));
}
// Save to database
$.ajax(calibre.bookmarkUrl, {
method: "post",
data: { bookmark: location || "" }
}).fail(function (xhr, status, error) {
alert(error);
});
}
2019-12-22 14:28:43 +00:00
// reader.book.package.metadata.direction= "rtl"; wait for reader reader before changing reading direction
})();