summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php3
-rw-r--r--js/index.js29
2 files changed, 19 insertions, 13 deletions
diff --git a/index.php b/index.php
index bfb5fe8..f7bf169 100644
--- a/index.php
+++ b/index.php
@@ -318,8 +318,10 @@
if ($found_id) {
$toggle_fav_prompt = "Remove from favorites";
+ $fav_attr = "1";
} else {
$toggle_fav_prompt = "Add to favorites";
+ $fav_attr = "0";
}
?>
@@ -327,6 +329,7 @@
data-book-id="<?php echo $line["id"] ?>">Summary</a></li>
<li><a href="#" onclick="return toggle_fav(this)"
+ data-is-fav="<?php echo $fav_attr ?>"
class="fav_item" data-book-id="<?php echo $line["id"] ?>">
<?php echo $toggle_fav_prompt ?></a></li>
diff --git a/js/index.js b/js/index.js
index 301f619..28e1227 100644
--- a/js/index.js
+++ b/js/index.js
@@ -18,23 +18,26 @@ function cache_refresh(force) {
function toggle_fav(elem) {
var bookId = elem.getAttribute("data-book-id");
- $.post("backend.php", {op: "togglefav", id: bookId}, function(data) {
- if (data) {
- var msg = "[Error]";
+ if (elem.getAttribute("data-is-fav") == "0" || confirm("Remove favorite?")) {
- if (data.status == 0) {
- msg = "Add to favorites";
- } else if (data.status == 1) {
- msg = "Remove from favorites";
- }
+ $.post("backend.php", {op: "togglefav", id: bookId}, function(data) {
+ if (data) {
+ var msg = "[Error]";
- $(elem).html(msg);
+ if (data.status == 0) {
+ msg = "Add to favorites";
+ } else if (data.status == 1) {
+ msg = "Remove from favorites";
+ }
- if (index_mode == "favorites" && data.status == 0) {
- $("#cell-" + bookId).remove();
+ $(elem).html(msg).attr('data-is-fav', data.status);
+
+ if (index_mode == "favorites" && data.status == 0) {
+ $("#cell-" + bookId).remove();
+ }
}
- }
- });
+ });
+ }
return false;
}