summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-28 09:17:27 +0300
committerAndrew Dolgov <[email protected]>2017-02-28 09:17:27 +0300
commit27ef6e89501371b58b92a3b805ab31ba8fc79260 (patch)
treefea8f3daece8b5e30218497362051cae79fda456 /js
parent16d52ac49f7318620d3a84e172cf18917d70de1b (diff)
fix .urlParam(); make offline search/reset work similarly to online version
Diffstat (limited to 'js')
-rw-r--r--js/common.js9
-rw-r--r--js/offline.js154
2 files changed, 80 insertions, 83 deletions
diff --git a/js/common.js b/js/common.js
index a400a17..9843c59 100644
--- a/js/common.js
+++ b/js/common.js
@@ -1,3 +1,12 @@
+$.urlParam = function(name){
+ try {
+ var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
+ return decodeURIComponent(results[1].replace(/\+/g, " ")) || 0;
+ } catch (e) {
+ return 0;
+ }
+}
+
function offline_remove(id, callback) {
if (confirm("Remove download?")) {
diff --git a/js/offline.js b/js/offline.js
index 0bcd447..540fc60 100644
--- a/js/offline.js
+++ b/js/offline.js
@@ -40,121 +40,109 @@ function offline_clear() {
function populate_list() {
- localforage.getItem("epube.search-query").then(function(query) {
+ var query = $.urlParam("query");
- if (query) query = query.toLowerCase();
+ if (query) query = query.toLowerCase();
- var books = $("#books_container");
- books.html("");
+ console.log(query);
- localforage.iterate(function(value, key, i) {
- if (key.match(/epube-book\.\d{1,}$/)) {
-
- Promise.all([
- localforage.getItem(key),
- localforage.getItem(key + ".cover"),
- localforage.getItem(key + ".lastread"),
- localforage.getItem(key + ".book")
- ]).then(function(results) {
-
- if (results[0] && results[3]) {
- var info = results[0];
-
- if (query) {
- var 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));
+ var books = $("#books_container");
+ books.html("");
- if (!match) return;
- }
+ localforage.iterate(function(value, key, i) {
+ if (key.match(/epube-book\.\d{1,}$/)) {
+ Promise.all([
+ localforage.getItem(key),
+ localforage.getItem(key + ".cover"),
+ localforage.getItem(key + ".lastread"),
+ localforage.getItem(key + ".book")
+ ]).then(function(results) {
- var cover = false;
+ if (results[0] && results[3]) {
+ var info = results[0];
- if (results && results[1]) {
- cover = URL.createObjectURL(results[1]);
- }
+ if (query) {
+ var 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));
- var in_progress = false;
- var is_read = false;
-
- var lastread = results[2];
- if (lastread) {
-
- in_progress = lastread.page > 0;
- is_read = lastread.total > 0 && lastread.total - lastread.page < 5;
- }
+ if (!match) return;
+ }
- var 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" : "";
+ var cover = false;
- 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>";
+ if (results && results[1]) {
+ cover = URL.createObjectURL(results[1]);
+ }
- cell += "<div class=\"caption\">";
- cell += "<div><a class=\""+title_class+"\" href=\"read.html?id="+info.epub_id+"&b="+info.id+"\">" +
- info.title + "</a></div>";
+ var in_progress = false;
+ var is_read = false;
- cell += "<div><a href=\#\" class=\"author_link\">" + info.author_sort + "</a></div>";
+ var lastread = results[2];
+ if (lastread) {
- if (info.series_name) {
- cell += "<div><a href=\"\" class=\"series_link\">" +
- info.series_name + " [" + info.series_index + "]</a></div>";
- }
+ in_progress = lastread.page > 0;
+ is_read = lastread.total > 0 && lastread.total - lastread.page < 5;
+ }
- cell += "</div>";
+ var cell = "<div class='col-xs-6 col-sm-3 col-md-2 index_cell' id=\"cell-"+info.id+"\">";
- cell += "<div class=\"dropdown\" style=\"white-space : nowrap\">";
- cell += "<a href=\"#\" data-toggle=\"dropdown\" role=\"button\">" +
- "More..." + "<span class=\"caret\"></span></a>";
+ var cover_read = is_read ? "read" : "";
+ var title_class = in_progress ? "in_progress" : "";
- cell += "<ul class=\"dropdown-menu\">";
- cell += "<li><a href=\"#\" data-book-id=\""+info.id+"\" onclick=\"offline_remove2(this)\">Remove offline data</a></li>";
- cell += "</ul>";
+ 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>";
- cell += "</div>";
+ cell += "<div class=\"caption\">";
+ cell += "<div><a class=\""+title_class+"\" href=\"read.html?id="+info.epub_id+"&b="+info.id+"\">" +
+ info.title + "</a></div>";
- cell += "</div>";
- cell += "</div>";
+ cell += "<div><a href=\#\" class=\"author_link\">" + info.author_sort + "</a></div>";
- var cell = $(cell);
+ if (info.series_name) {
+ cell += "<div><a href=\"\" class=\"series_link\">" +
+ info.series_name + " [" + info.series_index + "]</a></div>";
+ }
- if (cover) {
- cell.find("img").attr("src", cover);
+ cell += "</div>";
- cell.find(".series_link")
- .attr("title", info.series_name + " [" + info.series_index + "]")
- .click(function() {
+ cell += "<div class=\"dropdown\" style=\"white-space : nowrap\">";
+ cell += "<a href=\"#\" data-toggle=\"dropdown\" role=\"button\">" +
+ "More..." + "<span class=\"caret\"></span></a>";
- $(".search_query").val(info.series_name);
- offline_search();
+ cell += "<ul class=\"dropdown-menu\">";
+ cell += "<li><a href=\"#\" data-book-id=\""+info.id+"\" onclick=\"offline_remove2(this)\">Remove offline data</a></li>";
+ cell += "</ul>";
- return false;
- });
+ cell += "</div>";
- cell.find(".author_link")
- .attr("title", info.author_sort)
- .click(function() {
+ cell += "</div>";
+ cell += "</div>";
- $(".search_query").val(info.author_sort);
- offline_search();
+ var cell = $(cell);
- return false;
- });
+ if (cover) {
+ cell.find("img").attr("src", cover);
- }
+ cell.find(".series_link")
+ .attr("title", info.series_name + " [" + info.series_index + "]")
+ .attr("href", "offline.html?query=" + encodeURIComponent(info.series_name));
- books.append(cell);
+ cell.find(".author_link")
+ .attr("title", info.author_sort)
+ .attr("href", "offline.html?query=" + encodeURIComponent(info.author_sort));
- Holder.run();
}
- });
- }
- });
+ books.append(cell);
+
+ Holder.run();
+ }
+ });
+ }
});
}