mirror of
https://github.com/JonathanHerrewijnen/calibre-web.git
synced 2024-11-14 15:14:07 +00:00
b586a32843
Improvement for #925 (Next/Prev buttons are bigger)
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
/* global $, calibre, EPUBJS, ePubReader */
|
|
|
|
var reader;
|
|
|
|
(function() {
|
|
"use strict";
|
|
|
|
EPUBJS.filePath = calibre.filePath;
|
|
EPUBJS.cssPath = calibre.cssPath;
|
|
|
|
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);
|
|
});
|
|
}
|
|
})();
|