From 59a179fa1525f5fce819f4185362673dafb93c2f Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 25 Apr 2017 01:50:14 -0500 Subject: [PATCH] /posts: add shift+F to unfavorite hotkey. --- app/assets/javascripts/posts.js | 33 ++++++++++++-------- app/views/static/keyboard_shortcuts.html.erb | 1 + 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index 21ede5674e4..2ba3c2320d0 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -175,19 +175,8 @@ Danbooru.keydown("a", "prev_page", Danbooru.Post.nav_prev); Danbooru.keydown("d", "next_page", Danbooru.Post.nav_next); - - Danbooru.keydown("f", "favorite", function(e) { - if ($("#add-to-favorites").is(":visible")) { - $("#add-to-favorites").click(); - } else { - if (Danbooru.meta("current-user-id") == "") { - Danbooru.notice("You must be logged in to favorite posts"); - } else { - Danbooru.notice("You have already favorited this post"); - } - } - e.preventDefault(); - }); + Danbooru.keydown("f", "favorite", Danbooru.Post.favorite); + Danbooru.keydown("shift+f", "unfavorite", Danbooru.Post.unfavorite); } } @@ -537,6 +526,24 @@ }); } + Danbooru.Post.favorite = function (e) { + if ($("#add-to-favorites").is(":visible")) { + $("#add-to-favorites").click(); + } else { + if (Danbooru.meta("current-user-id") == "") { + Danbooru.notice("You must be logged in to favorite posts"); + } else { + Danbooru.notice("You have already favorited this post"); + } + } + }; + + Danbooru.Post.unfavorite = function (e) { + $.ajax("/favorites/" + Danbooru.meta("post-id") + ".js", { + type: "DELETE" + }); + }; + Danbooru.Post.initialize_saved_searches = function() { $("#saved_search_labels").autocomplete({ minLength: 2, diff --git a/app/views/static/keyboard_shortcuts.html.erb b/app/views/static/keyboard_shortcuts.html.erb index c77644f3ea5..45884884999 100644 --- a/app/views/static/keyboard_shortcuts.html.erb +++ b/app/views/static/keyboard_shortcuts.html.erb @@ -29,6 +29,7 @@
  • a Previous post
  • d Next post
  • f Favorite post
  • +
  • shift+f Unfavorite post
  • g Add post to favorite group
  • 1, 2, 3... Add post to favorite group #N
  • r Go to random post