2017-08-23 17:52:52 +02:00
|
|
|
/* global $, calibre, EPUBJS, ePubReader */
|
|
|
|
|
2019-12-22 15:24:22 +01:00
|
|
|
var reader;
|
|
|
|
|
2017-08-23 17:52:52 +02:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
EPUBJS.filePath = calibre.filePath;
|
|
|
|
EPUBJS.cssPath = calibre.cssPath;
|
|
|
|
|
2019-12-22 15:24:22 +01:00
|
|
|
reader = ePubReader(calibre.bookUrl, {
|
2017-08-23 17:52:52 +02:00
|
|
|
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
|
|
|
|
2021-01-24 14:19:46 +01:00
|
|
|
// Enable swipe support
|
|
|
|
// I have no idea why swiperRight/swiperLeft from plugins is not working, events just don't get fired
|
|
|
|
var touchStart = 0;
|
|
|
|
var touchEnd = 0;
|
|
|
|
|
|
|
|
reader.rendition.on('touchstart', function(event) {
|
|
|
|
touchStart = event.changedTouches[0].screenX;
|
|
|
|
});
|
|
|
|
reader.rendition.on('touchend', function(event) {
|
|
|
|
touchEnd = event.changedTouches[0].screenX;
|
|
|
|
if (touchStart < touchEnd) {
|
|
|
|
if(reader.book.package.metadata.direction === "rtl") {
|
|
|
|
reader.rendition.next();
|
|
|
|
} else {
|
|
|
|
reader.rendition.prev();
|
|
|
|
}
|
|
|
|
// Swiped Right
|
|
|
|
}
|
|
|
|
if (touchStart > touchEnd) {
|
|
|
|
if(reader.book.package.metadata.direction === "rtl") {
|
|
|
|
reader.rendition.prev();
|
|
|
|
} else {
|
|
|
|
reader.rendition.next();
|
|
|
|
}
|
|
|
|
// Swiped Left
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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));
|
|
|
|
}
|
2021-12-01 05:24:34 +01:00
|
|
|
|
|
|
|
var csrftoken = $("input[name='csrf_token']").val();
|
2017-08-23 17:52:52 +02:00
|
|
|
|
|
|
|
// Save to database
|
|
|
|
$.ajax(calibre.bookmarkUrl, {
|
|
|
|
method: "post",
|
2021-12-01 05:24:34 +01:00
|
|
|
data: { bookmark: location || "" },
|
|
|
|
headers: { "X-CSRFToken": csrftoken }
|
2017-08-23 17:52:52 +02:00
|
|
|
}).fail(function (xhr, status, error) {
|
|
|
|
alert(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})();
|
2021-01-24 14:19:46 +01:00
|
|
|
|
|
|
|
|