2017-08-23 15:52:52 +00:00
|
|
|
/* global $, calibre, EPUBJS, ePubReader */
|
|
|
|
|
2019-12-22 14:28:43 +00:00
|
|
|
var reader;
|
|
|
|
|
2017-08-23 15:52:52 +00:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
EPUBJS.filePath = calibre.filePath;
|
|
|
|
EPUBJS.cssPath = calibre.cssPath;
|
|
|
|
|
2019-12-22 14:28:43 +00:00
|
|
|
reader = ePubReader(calibre.bookUrl, {
|
2017-08-23 15:52:52 +00:00
|
|
|
restore: true,
|
2017-09-10 22:38:24 +00:00
|
|
|
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
|
2017-08-23 15:52:52 +00:00
|
|
|
});
|
2017-09-30 17:51:20 +00:00
|
|
|
|
|
|
|
if (calibre.useBookmarks) {
|
|
|
|
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
|
|
|
|
reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove"));
|
|
|
|
} else {
|
|
|
|
$("#bookmark, #show-Bookmarks").remove();
|
|
|
|
}
|
2017-08-23 15:52:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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) {
|
2017-09-10 22:38:24 +00:00
|
|
|
return bookmark && bookmark !== location;
|
2017-08-23 15:52:52 +00:00
|
|
|
}).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
|
2017-08-23 15:52:52 +00:00
|
|
|
})();
|