diff options
Diffstat (limited to 'js/offline.js')
-rw-r--r-- | js/offline.js | 154 |
1 files changed, 71 insertions, 83 deletions
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(); + } + }); + } }); } |