1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-20 08:44:55 +00:00
calibre-web/cps/static/js/reading/epub.js
Jonathan Rehm 374b5f4c6e Save ePub bookmarks to database
Save ePub bookmark to database. Also use library's built-in restore feature to restore all information from localStorage.
2017-08-23 08:55:40 -07:00

39 lines
1.1 KiB
JavaScript

/* global $, calibre, EPUBJS, ePubReader */
(function() {
"use strict";
EPUBJS.filePath = calibre.filePath;
EPUBJS.cssPath = calibre.cssPath;
var reader = ePubReader(calibre.bookUrl, {
restore: true,
bookmarks: [calibre.bookmark]
});
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
reader.on("reader:unbookmarked", updateBookmark.bind(reader, "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 !== 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);
});
}
})();