2017-08-23 17:52:52 +02:00
|
|
|
/* global $, calibre, EPUBJS, ePubReader */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
EPUBJS.filePath = calibre.filePath;
|
|
|
|
EPUBJS.cssPath = calibre.cssPath;
|
|
|
|
|
|
|
|
var reader = ePubReader(calibre.bookUrl, {
|
|
|
|
restore: true,
|
2017-09-11 00:38:24 +02:00
|
|
|
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
|
2017-08-23 17:52:52 +02:00
|
|
|
});
|
2017-09-30 19:51:20 +02: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 17:52:52 +02: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-11 00:38:24 +02:00
|
|
|
return bookmark && bookmark !== location;
|
2017-08-23 17:52:52 +02: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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})();
|