From 8ac530a909fa56d99fa0b5973bad785c2c373e80 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Wed, 12 Dec 2018 11:39:54 -0800 Subject: [PATCH] fixes #4006: Bring back the "edit tags" button to the sidebar fixes #4011: Comment input field under posts is too big, goes slightly beyond view boundaries fixes #4010: Incorrect dynamic tag counts --- app/javascript/src/javascripts/posts.js.erb | 7 ++++--- app/javascript/src/javascripts/related_tag.js | 3 +++ app/javascript/src/styles/specific/posts.scss | 5 ++++- app/views/posts/partials/show/_options.html.erb | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index a6c23b72e..5a7f6807d 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -41,7 +41,7 @@ Post.initialize_all = function() { var $fields_multiple = $('[data-autocomplete="tag-edit"]'); $fields_multiple.on("keypress.danbooru", Post.update_tag_count); - Post.update_tag_count(); + $fields_multiple.on("click", Post.update_tag_count); $(window).on('danbooru:initialize_saved_seraches', () => { Post.initialize_saved_searches(); @@ -421,7 +421,7 @@ Post.initialize_excerpt = function() { } Post.initialize_post_sections = function() { - $("#post-sections li a").on("click.danbooru", function(e) { + $("#post-sections li a,#side-edit-link").on("click.danbooru", function(e) { if (e.target.hash === "#comments") { $("#comments").show(); $("#edit").hide(); @@ -432,6 +432,7 @@ Post.initialize_post_sections = function() { $("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight); $("#recommended").hide(); $(document).trigger("danbooru:open-post-edit-tab"); + Post.update_tag_count({target: $("#post_tag_string")}); } else if (e.target.hash === "#recommended") { $("#comments").hide(); $("#edit").hide(); @@ -607,7 +608,7 @@ Post.update_tag_count = function(event) { let count = 0; if (event) { - let tags = $(event.target).val().match(/\S+/g); + let tags = [...new Set($(event.target).val().match(/\S+/g))]; if (tags) { count = tags.length; string = (count == 1) ? (count + " tag") : (count + " tags") diff --git a/app/javascript/src/javascripts/related_tag.js b/app/javascript/src/javascripts/related_tag.js index 2b34c5d17..7591d6565 100644 --- a/app/javascript/src/javascripts/related_tag.js +++ b/app/javascript/src/javascripts/related_tag.js @@ -1,5 +1,6 @@ import Uploads from './uploads'; import Utility from './utility'; +import Post from './posts.js.erb'; let RelatedTag = {}; @@ -121,6 +122,8 @@ RelatedTag.toggle_tag = function(e) { // The timeout is needed on Chrome since it will clobber the field attribute otherwise setTimeout(function () { $field.prop('selectionStart', $field.val().length);}, 100); e.preventDefault(); + + Post.update_tag_count({ target: $field }); } RelatedTag.show = function(e) { diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index 14d5f27a5..31c7c8afa 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -343,10 +343,13 @@ div#c-posts { } textarea { - width: 100%; margin-bottom: 0.25em; } + #edit textarea { + width: 100%; + } + #favlist { margin-left: 1em; word-wrap: break-word; diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb index 5a9a1b425..44522f69c 100644 --- a/app/views/posts/partials/show/_options.html.erb +++ b/app/views/posts/partials/show/_options.html.erb @@ -4,6 +4,7 @@ <% if CurrentUser.is_member? %>
  • <%= link_to "Favorite", favorites_path(:post_id => post.id), :remote => true, :method => :post, :id => "add-to-favorites", :"data-shortcut" => "f", style: ("display: none;" if @post.is_favorited?) %>
  • <%= link_to "Unfavorite", favorite_path(post), :remote => true, :method => :delete, :id => "remove-from-favorites", :"data-shortcut" => "shift+f", style: ("display: none;" if !@post.is_favorited?) %>
  • +
  • <%= link_to "Edit", "#edit", :id => "side-edit-link" %>
  • <%= link_to_if post.visible?, "Download", post.tagged_file_url + "?download=1", download: post.presenter.filename_for_download %>
  • <%= link_to "Add to pool", "#", :id => "pool" %>
  • <% if post.is_note_locked? %>