diff options
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | js/index.js | 48 |
2 files changed, 27 insertions, 23 deletions
@@ -159,7 +159,7 @@ $cover_read = $is_read ? "read" : ""; - print "<div class='col-xs-6 col-sm-3 col-md-2 index_cell'>"; + print "<div class='col-xs-6 col-sm-3 col-md-2 index_cell' id=\"cell-".$line["id"]."\">"; print "<div class=\"thumb $cover_read\">"; if ($read_link) print "<a href=\"$read_link\">"; diff --git a/js/index.js b/js/index.js index 87279c2..c5f8926 100644 --- a/js/index.js +++ b/js/index.js @@ -1,32 +1,36 @@ -function mark_offline_books() { - var elems = $(".offline_dropitem"); +function mark_offline(elem) { - $.each(elems, function (i, elem) { - var bookId = elem.getAttribute("data-book-id"); - var cacheId = "epube-book." + bookId; + var bookId = elem.getAttribute("data-book-id"); + var cacheId = "epube-book." + bookId; - localforage.getItem(cacheId).then(function(book) { - if (book) { + localforage.getItem(cacheId).then(function(book) { + if (book) { + elem.onclick = function() { + offline_remove(bookId, function() { + mark_offline(elem); + }); + }; - elem.onclick = function() { - offline_remove(bookId, function() { - mark_offline_books(); - }); - }; + elem.innerHTML = "Remove offline data"; - elem.innerHTML = "Remove offline data"; + } else { + elem.onclick = function() { + offline_cache(bookId, function() { + mark_offline(elem); + }); + }; - } else { - elem.onclick = function() { - offline_cache(bookId, function() { - mark_offline_books(); - }); - }; + elem.innerHTML = "Make available offline"; + } + }); +} - elem.innerHTML = "Make available offline"; - } - }); +function mark_offline_books() { + var elems = $(".offline_dropitem"); + + $.each(elems, function (i, elem) { + mark_offline(elem); }); } |