summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/common.js9
-rw-r--r--js/offline.js154
-rw-r--r--offline.html12
-rw-r--r--read.html5
-rw-r--r--worker.js4
5 files changed, 91 insertions, 93 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();
+ }
+ });
+ }
});
}
diff --git a/offline.html b/offline.html
index 0062518..d3fa1d5 100644
--- a/offline.html
+++ b/offline.html
@@ -45,7 +45,7 @@
<button type="submit" onclick="offline_clear()" class="btn btn-danger">Remove all</button>
</form>
- <form onsubmit="return offline_search(this)" class="navbar-form navbar-right">
+ <form class="navbar-form navbar-right">
<input type="text" class="form-control search_query" name="query" class="form-control"
value="">
<button type="submit" class="btn btn-default">Search</button>
@@ -67,12 +67,14 @@
});
}
- localforage.getItem("epube.search-query").then(function(query) {
+ var query = $.urlParam("query");
- if (query) $(".search_query").val(query);
+ console.log(query);
- populate_list();
- });
+ if (query)
+ $(".search_query").val(query);
+
+ populate_list();
});
</script>
diff --git a/read.html b/read.html
index aa29f15..ba7544f 100644
--- a/read.html
+++ b/read.html
@@ -213,11 +213,6 @@
var _pagination_stored = 0;
var _last_position_sync = 0;
- $.urlParam = function(name){
- var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
- return results[1] || 0;
- }
-
function cacheId(suffix) {
return "epube-book." + $.urlParam("b") + (suffix ? "." + suffix : "");
}
diff --git a/worker.js b/worker.js
index 2fe5677..158fc1c 100644
--- a/worker.js
+++ b/worker.js
@@ -63,6 +63,10 @@ this.addEventListener('fetch', function(event) {
return caches.match("read.html");
}
+ if (req.url.match("offline.html")) {
+ return caches.match("offline.html");
+ }
+
if (req.url.match("index.php")) {
return caches.match("offline.html");
}