summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-11-29 15:04:27 +0300
committerAndrew Dolgov <[email protected]>2018-11-29 15:04:27 +0300
commitb026d16edeaebd6dbeba66198644ee4a2ce02dae (patch)
treed7cb860f3e1166b3310c8722a24f926f98c6d834 /js
parente906fd5d3ac3085e54a5f82abdd83430f741239c (diff)
some eslint-related fixes
Diffstat (limited to 'js')
-rw-r--r--js/common.js6
-rw-r--r--js/dict.js2
-rw-r--r--js/index.js31
-rw-r--r--js/offline.js48
-rw-r--r--js/read.js79
5 files changed, 83 insertions, 83 deletions
diff --git a/js/common.js b/js/common.js
index 8367034..b42491d 100644
--- a/js/common.js
+++ b/js/common.js
@@ -2,7 +2,7 @@
$.urlParam = function(name){
try {
- var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
+ const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
return decodeURIComponent(results[1].replace(/\+/g, " ")) || 0;
} catch (e) {
return 0;
@@ -13,8 +13,8 @@ function offline_remove(id, callback) {
if (confirm("Remove download?")) {
- var cacheId = "epube-book." + id;
- var promises = [];
+ const cacheId = "epube-book." + id;
+ const promises = [];
console.log("offline remove: " + id);
diff --git a/js/dict.js b/js/dict.js
index 8db1718..88bd154 100644
--- a/js/dict.js
+++ b/js/dict.js
@@ -4,7 +4,7 @@ $(document).ready(function() {
$(window).on("mouseup touchend", function() {
if (!navigator.onLine) return;
- var sel = getSelection().toString().trim();
+ const sel = getSelection().toString().trim();
if (sel.match(/^\w+$/)) {
parent.dict_lookup(sel, function() {
diff --git a/js/index.js b/js/index.js
index b16a742..c0f2e84 100644
--- a/js/index.js
+++ b/js/index.js
@@ -1,11 +1,13 @@
'use strict';
-var _dl_progress_timeout;
+/* global localforage */
+
+let _dl_progress_timeout;
function cache_refresh(force) {
if ('serviceWorker' in navigator) {
localforage.getItem("epube.cache-timestamp").then(function(stamp) {
- var ts = parseInt(new Date().getTime()/1000);
+ const ts = parseInt(new Date().getTime()/1000);
if (force || !stamp || ts - stamp > 3600 * 24 * 7) {
console.log('asking worker to refresh cache');
@@ -20,13 +22,13 @@ function cache_refresh(force) {
}
function toggle_fav(elem) {
- var bookId = elem.getAttribute("data-book-id");
+ const bookId = elem.getAttribute("data-book-id");
if (elem.getAttribute("data-is-fav") == "0" || confirm("Remove favorite?")) {
$.post("backend.php", {op: "togglefav", id: bookId}, function(data) {
if (data) {
- var msg = "[Error]";
+ let msg = "[Error]";
if (data.status == 0) {
msg = "Add to favorites";
@@ -48,8 +50,8 @@ function toggle_fav(elem) {
function mark_offline(elem) {
- var bookId = elem.getAttribute("data-book-id");
- var cacheId = "epube-book." + bookId;
+ const bookId = elem.getAttribute("data-book-id");
+ const cacheId = "epube-book." + bookId;
localforage.getItem(cacheId).then(function(book) {
if (book) {
@@ -77,7 +79,7 @@ function mark_offline(elem) {
}
function mark_offline_books() {
- var elems = $(".offline_dropitem");
+ const elems = $(".offline_dropitem");
$.each(elems, function (i, elem) {
mark_offline(elem);
@@ -90,13 +92,13 @@ function offline_cache(bookId, callback) {
$.post("backend.php", {op: "getinfo", id: bookId}, function(data) {
if (data) {
- var cacheId = 'epube-book.' + bookId;
+ const cacheId = 'epube-book.' + bookId;
localforage.setItem(cacheId, data).then(function(data) {
console.log(cacheId + ' got data');
- var promises = [];
+ const promises = [];
promises.push(fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
if (resp.status == 200) {
@@ -158,11 +160,11 @@ function offline_cache(bookId, callback) {
}
function show_summary(elem) {
- var id = elem.getAttribute("data-book-id");
+ const id = elem.getAttribute("data-book-id");
$.post("backend.php", {op: 'getinfo', id: id}, function(data) {
- var comment = data.comment ? data.comment : 'No description available';
+ const comment = data.comment ? data.comment : 'No description available';
$("#summary-modal .modal-title").html(data.title);
$("#summary-modal .book-summary").html(comment);
@@ -179,12 +181,12 @@ function offline_get_all() {
if (confirm("Download all books on this page?")) {
$(".index_cell").each(function (i, row) {
- var bookId = $(row).attr("id").replace("cell-", "");
- var dropitem = $(row).find(".offline_dropitem")[0];
+ const bookId = $(row).attr("id").replace("cell-", "");
+ const dropitem = $(row).find(".offline_dropitem")[0];
if (bookId) {
- var cacheId = 'epube-book.' + bookId;
+ const cacheId = 'epube-book.' + bookId;
localforage.getItem(cacheId).then(function(book) {
if (!book) {
@@ -200,4 +202,3 @@ function offline_get_all() {
}
}
-
diff --git a/js/offline.js b/js/offline.js
index a7c8dcf..6fd3ddd 100644
--- a/js/offline.js
+++ b/js/offline.js
@@ -1,7 +1,9 @@
'use strict';
-function offline_search(form) {
- var query = $(".search_query").val();
+/* global localforage, Holder */
+
+function offline_search() {
+ const query = $(".search_query").val();
localforage.setItem("epube.search-query", query).then(function() {
populate_list();
@@ -11,7 +13,7 @@ function offline_search(form) {
}
function offline_remove2(elem) {
- var bookId = elem.getAttribute("data-book-id");
+ const bookId = elem.getAttribute("data-book-id");
return offline_remove(bookId, function() {
$("#cell-" + bookId).remove();
@@ -22,9 +24,9 @@ function offline_clear() {
if (confirm("Remove all offline data?")) {
- var promises = [];
+ const promises = [];
- localforage.iterate(function(value, key, i) {
+ localforage.iterate(function(value, key/*, i*/) {
if (key.match("epube-book")) {
promises.push(localforage.removeItem(key));
@@ -42,14 +44,14 @@ function offline_clear() {
function populate_list() {
- var query = $.urlParam("query");
+ let query = $.urlParam("query");
if (query) query = query.toLowerCase();
- var books = $("#books_container");
+ const books = $("#books_container");
books.html("");
- localforage.iterate(function(value, key, i) {
+ localforage.iterate(function(value, key/*, i*/) {
if (key.match(/epube-book\.\d{1,}$/)) {
Promise.all([
@@ -60,10 +62,10 @@ function populate_list() {
]).then(function(results) {
if (results[0] && results[3]) {
- var info = results[0];
+ const info = results[0];
if (query) {
- var match =
+ const match =
(info.series_name && info.series_name.toLowerCase().match(query)) ||
(info.title && info.title.toLowerCase().match(query)) ||
(info.author_sort && info.author_sort.toLowerCase().match(query));
@@ -72,26 +74,26 @@ function populate_list() {
}
- var cover = false;
+ let cover = false;
if (results && results[1]) {
cover = URL.createObjectURL(results[1]);
}
- var in_progress = false;
- var is_read = false;
+ let in_progress = false;
+ let is_read = false;
- var lastread = results[2];
+ const lastread = results[2];
if (lastread) {
in_progress = lastread.page > 0;
is_read = lastread.total > 0 && lastread.total - lastread.page < 5;
}
- var cell = "<div class='col-xs-6 col-sm-3 col-md-2 index_cell' id=\"cell-"+info.id+"\">";
+ let cell = "<div class='col-xs-6 col-sm-3 col-md-2 index_cell' id=\"cell-"+info.id+"\">";
- var cover_read = is_read ? "read" : "";
- var title_class = in_progress ? "in_progress" : "";
+ const cover_read = is_read ? "read" : "";
+ const title_class = in_progress ? "in_progress" : "";
cell += "<div class=\"thumb "+cover_read+"\">";
cell += "<a href=\"read.html?id="+info.epub_id+"&b="+info.id+"\"><img data-src=\"holder.js/120x180\"></a>";
@@ -100,7 +102,7 @@ function populate_list() {
cell += "<div><a class=\""+title_class+"\" href=\"read.html?id="+info.epub_id+"&b="+info.id+"\">" +
info.title + "</a></div>";
- cell += "<div><a href=\#\" class=\"author_link\">" + info.author_sort + "</a></div>";
+ cell += "<div><a href=\"#\" class=\"author_link\">" + info.author_sort + "</a></div>";
if (info.series_name) {
cell += "<div><a href=\"\" class=\"series_link\">" +
@@ -111,7 +113,7 @@ function populate_list() {
cell += "<div class=\"dropdown\" style=\"white-space : nowrap\">";
cell += "<a href=\"#\" data-toggle=\"dropdown\" role=\"button\">" +
- "More..." + "<span class=\"caret\"></span></a>";
+ "More...<span class=\"caret\"></span></a>";
cell += "<ul class=\"dropdown-menu\">";
cell += "<li><a href=\"#\" data-book-id=\""+info.id+"\" onclick=\"return show_summary(this)\">Summary</a></li>";
@@ -123,7 +125,7 @@ function populate_list() {
cell += "</div>";
cell += "</div>";
- var cell = $(cell);
+ cell = $(cell);
if (cover) {
@@ -150,11 +152,11 @@ function populate_list() {
}
function show_summary(elem) {
- var bookId = elem.getAttribute("data-book-id");
+ const bookId = elem.getAttribute("data-book-id");
localforage.getItem("epube-book." + bookId).then(function(data) {
- var comment = data.comment ? data.comment : 'No description available';
+ const comment = data.comment ? data.comment : 'No description available';
$("#summary-modal .modal-title").html(data.title);
$("#summary-modal .book-summary").html(comment);
@@ -165,5 +167,3 @@ function show_summary(elem) {
return false;
}
-
-
diff --git a/js/read.js b/js/read.js
index 6c960cf..f82fc8d 100644
--- a/js/read.js
+++ b/js/read.js
@@ -1,15 +1,16 @@
'use strict';
-var _store_position = 0;
+/* global localforage, book, cacheId */
function toggle_fullscreen() {
- var element = document.documentElement;
+ const element = document.documentElement;
+ const isFullscreen = document.webkitIsFullScreen || document.mozFullScreen || false;
- var isFullscreen = document.webkitIsFullScreen || document.mozFullScreen || false;
+ element.requestFullScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen ||
+ function () { return false; };
- element.requestFullScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || function () { return false; };
-
- document.cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || function () { return false; };
+ document.cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen ||
+ function () { return false; };
isFullscreen ? document.cancelFullScreen() : element.requestFullScreen();
}
@@ -120,20 +121,17 @@ function hotkey_handler(e) {
e.preventDefault();
show_ui(true);
}
-
-
} catch (e) {
console.warn(e);
}
}
function resize_side_columns() {
- var width = $("#reader").position().left;
-
- var iframe = $("#reader iframe")[0];
+ let width = $("#reader").position().left;
+ const iframe = $("#reader iframe")[0];
if (iframe && iframe.contentWindow.$)
- width += parseInt(iframe.contentWindow.$("body").css("padding-left"), 10);
+ width += parseInt(iframe.contentWindow.$("body").css("padding-left"));
$("#left, #right").width(width);
}
@@ -143,18 +141,18 @@ $(document).ready(function() {
hotkey_handler(e);
});
- $("#left").on("mouseup", function(evt) {
+ $("#left").on("mouseup", function() {
prev_page();
});
- $("#right").on("mouseup", function(evt) {
+ $("#right").on("mouseup", function() {
next_page();
});
});
function apply_line_height(elem) {
- var height = elem[elem.selectedIndex].value;
+ const height = $(elem).val();
localforage.setItem("epube.lineHeight", height).then(function() {
apply_styles();
@@ -162,7 +160,7 @@ function apply_line_height(elem) {
}
function apply_font(elem) {
- var font = elem[elem.selectedIndex].value;
+ const font = $(elem).val();
localforage.setItem("epube.fontFamily", font).then(function() {
apply_styles();
@@ -171,7 +169,7 @@ function apply_font(elem) {
}
function apply_font_size(elem) {
- var size = elem[elem.selectedIndex].value;
+ const size = $(elem).val();
localforage.setItem("epube.fontSize", size).then(function() {
apply_styles();
@@ -186,10 +184,10 @@ function apply_styles() {
localforage.getItem("epube.lineHeight"),
localforage.getItem("epube.theme")
]).then(function(res) {
- var fontSize = res[0] ? res[0] + "px" : DEFAULT_FONT_SIZE + "px";
- var fontFamily = res[1] ? res[1] : DEFAULT_FONT_FAMILY;
- var lineHeight = res[2] ? res[2] + "%" : DEFAULT_LINE_HEIGHT + "%";
- var themeName = res[3] ? res[3] : false;
+ const fontSize = res[0] ? res[0] + "px" : DEFAULT_FONT_SIZE + "px";
+ const fontFamily = res[1] ? res[1] : DEFAULT_FONT_FAMILY;
+ const lineHeight = res[2] ? res[2] + "%" : DEFAULT_LINE_HEIGHT + "%";
+ //const themeName = res[3] ? res[3] : false;
$.each(window.book.rendition.getContents(), function(i, c) {
c.css("font-size", fontSize);
@@ -204,7 +202,7 @@ function apply_styles() {
function clear_lastread() {
if (confirm("Clear stored last read location?")) {
- var total = window.book.locations.length();
+ const total = window.book.locations.length();
if (navigator.onLine) {
$.post("backend.php", { op: "storelastread", page: -1, cfi: "", id: $.urlParam("id") }, function(data) {
@@ -220,8 +218,8 @@ function clear_lastread() {
function mark_as_read() {
if (confirm("Mark book as read?")) {
- var total = 100;
- var lastCfi = window.book.locations.cfiFromPercentage(1);
+ const total = 100;
+ const lastCfi = window.book.locations.cfiFromPercentage(1);
if (navigator.onLine) {
$.post("backend.php", { op: "storelastread", page: total, cfi: lastCfi, id: $.urlParam("id") }, function(data) {
@@ -236,18 +234,18 @@ function mark_as_read() {
}
function save_and_close() {
- var location = window.book.rendition.currentLocation();
+ const location = window.book.rendition.currentLocation();
- var currentCfi = location.start.cfi;
- var currentPage = parseInt(window.book.locations.percentageFromCfi(currentCfi) * 100);
- var totalPages = 100;
+ const currentCfi = location.start.cfi;
+ const currentPage = parseInt(window.book.locations.percentageFromCfi(currentCfi) * 100);
+ const totalPages = 100;
localforage.setItem(cacheId("lastread"),
{cfi: currentCfi, page: currentPage, total: totalPages});
if (navigator.onLine) {
$.post("backend.php", { op: "storelastread", id: $.urlParam("id"), page: currentPage,
- cfi: currentCfi }, function(data) {
+ cfi: currentCfi }, function() {
window.location = $.urlParam("rt") ? "index.php?mode=" + $.urlParam("rt") : "index.php";
})
.fail(function() {
@@ -259,7 +257,8 @@ function save_and_close() {
}
function change_theme(elem) {
- var theme = $(elem).val();
+ const theme = $(elem).val();
+
localforage.setItem("epube.theme", theme).then(function() {
apply_styles();
});
@@ -269,11 +268,10 @@ function apply_theme() {
localforage.getItem("epube.theme").then(function(theme) {
console.log('theme', theme);
- var base_url = window.location.href.match(/^.*\//)[0];
+ const base_url = window.location.href.match(/^.*\//)[0];
if (!theme) theme = 'default';
-
- var theme_url = base_url + "themes/" + theme + ".css";
+ const theme_url = base_url + "themes/" + theme + ".css";
$("#theme_css").attr("href", theme_url);
@@ -285,23 +283,24 @@ function apply_theme() {
}
function search() {
- var query = $(".search_input").val();
- var list = $(".search_results");
+ const query = $(".search_input").val();
+ const list = $(".search_results");
list.html("");
if (query) {
+ /* eslint-disable prefer-spread */
Promise.all(
book.spine.spineItems.map(
- item => item.load(book.load.bind(book))
+ (item) => item.load(book.load.bind(book))
.then(item.find.bind(item, query))
.finally(item.unload.bind(item)))
- )
- .then(results => Promise.resolve([].concat.apply([], results)))
+ )
+ .then((results) => Promise.resolve([].concat.apply([], results)))
.then(function(results) {
$.each(results, function (i, row) {
- var a = $("<a>")
+ const a = $("<a>")
.attr('href', '#')
.html("<b class='pull-right'>" + window.book.locations.locationFromCfi(row.cfi) + "</b>" + row.excerpt)
.attr('data-cfi', row.cfi)
@@ -330,7 +329,7 @@ function dict_lookup(word, callback) {
}
function open_previous_location(elem) {
- var cfi = $(elem).attr("data-location-cfi");
+ const cfi = $(elem).attr("data-location-cfi");
if (cfi) {
window.book.rendition.display(cfi);