function offline_search(form) { var query = $(".search_query").val(); localforage.setItem("epube.search-query", query).then(function() { populate_list(); }); return false; } function offline_remove2(elem) { var bookId = elem.getAttribute("data-book-id"); return offline_remove(bookId, function() { $("#cell-" + bookId).remove(); }); } function offline_clear() { if (confirm("Remove all offline data?")) { var promises = []; localforage.iterate(function(value, key, i) { if (key.match("epube-book")) { promises.push(localforage.removeItem(key)); } }); Promise.all(promises).then(function() { window.setTimeout(function() { populate_list(); }, 500); }); } } function populate_list() { var query = $.urlParam("query"); if (query) query = query.toLowerCase(); var books = $("#books_container"); books.html(""); 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)); if (!match) return; } var cover = false; if (results && results[1]) { cover = URL.createObjectURL(results[1]); } 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; } var cell = "
"; var cover_read = is_read ? "read" : ""; var title_class = in_progress ? "in_progress" : ""; cell += "
"; cell += ""; cell += "
"; cell += "
" + info.title + "
"; cell += "
" + info.author_sort + "
"; if (info.series_name) { cell += "
" + info.series_name + " [" + info.series_index + "]
"; } cell += "
"; cell += "
"; cell += "" + "More..." + ""; cell += ""; cell += "
"; cell += "
"; cell += "
"; var cell = $(cell); if (cover) { cell.find("img").attr("src", cover).qtip({ position: { target: 'mouse', adjust: { mouse: false } }, style: { classes: 'qtip-light qtip-custom' }, show: { delay: 1000 }, hide: 'unfocus mouseleave', content: { text: info.comment ? info.comment : "No description available", title: info.title } }); cell.find(".series_link") .attr("title", info.series_name + " [" + info.series_index + "]") .attr("href", "offline.html?query=" + encodeURIComponent(info.series_name)); cell.find(".author_link") .attr("title", info.author_sort) .attr("href", "offline.html?query=" + encodeURIComponent(info.author_sort)); } books.append(cell); Holder.run(); } }); } }); }