From 0b45cf55dddb66b7c6328bc6d5233d023c031e5c Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 31 Mar 2016 10:55:37 +0100 Subject: Uses the same emoji-menu and just moves it around depending where it should be viewed # Conflicts: # app/assets/javascripts/awards_handler.coffee # app/assets/stylesheets/pages/notes.scss # app/helpers/issues_helper.rb # app/views/projects/notes/_note.html.haml --- app/assets/javascripts/awards_handler.coffee | 41 ++-- app/assets/javascripts/dispatcher.js.coffee | 2 + .../javascripts/lib/emoji_aliases.js.coffee.erb | 2 + app/assets/stylesheets/pages/awards.scss | 2 +- app/assets/stylesheets/pages/notes.scss | 249 +++++++++------------ app/views/emoji_awards/_awards_block.html.haml | 14 +- app/views/projects/notes/_note.html.haml | 23 +- 7 files changed, 155 insertions(+), 178 deletions(-) create mode 100644 app/assets/javascripts/lib/emoji_aliases.js.coffee.erb (limited to 'app') diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee index 105b0c34e95..9e3d9f09126 100644 --- a/app/assets/javascripts/awards_handler.coffee +++ b/app/assets/javascripts/awards_handler.coffee @@ -1,23 +1,23 @@ class @AwardsHandler - constructor: (@aliases) -> - $(".js-add-award").on "click", (event) => + constructor: -> + @aliases = emojiAliases() + + $(document).on "click", ".js-add-award", (event) => event.stopPropagation() event.preventDefault() - @showEmojiMenu() + @showEmojiMenu $(event.currentTarget) $("html").on 'click', (event) -> if !$(event.target).closest(".emoji-menu").length if $(".emoji-menu").is(":visible") $(".emoji-menu").removeClass "is-visible" - $(".awards") - .off "click" + $(document) + .off "click", ".js-emoji-btn" .on "click", ".js-emoji-btn", @handleClick - @renderFrequentlyUsedBlock() - - handleClick: (e) -> + handleClick: (e) => e.preventDefault() $emojiBtn = $(e.currentTarget) awardUrl = $emojiBtn.closest('.js-votes-block').data 'award-url' @@ -26,8 +26,13 @@ class @AwardsHandler .data "emoji" @addAward awardUrl, emoji - showEmojiMenu: -> + showEmojiMenu: ($addBtn) -> if $(".emoji-menu").length + $holder = $addBtn.closest('.js-award-holder') + + if $holder.find('.emoji-menu').length is 0 + $(".emoji-menu").detach().appendTo $holder + if $(".emoji-menu").is ".is-visible" $(".emoji-menu").removeClass "is-visible" $("#emoji_search").blur() @@ -35,10 +40,11 @@ class @AwardsHandler $(".emoji-menu").addClass "is-visible" $("#emoji_search").focus() else - $('.js-add-award').addClass "is-loading" - $.get "/emojis", (response) => - $('.js-add-award').removeClass "is-loading" - $(".js-award-holder").append response + $addBtn.addClass "is-loading" + $.get $addBtn.data('award-menu-url'), (response) => + $addBtn.removeClass "is-loading" + $addBtn.closest('.js-award-holder').append response + @renderFrequentlyUsedBlock() setTimeout => $(".emoji-menu").addClass "is-visible" $("#emoji_search").focus() @@ -128,7 +134,7 @@ class @AwardsHandler " emoji_node = $(buttonHtml) - .insertBefore(".js-award-holder") + .insertBefore(".js-award-holder:not(.js-award-action-btn)") .find(".emoji-icon") .data("emoji", emoji) $('.award-control').tooltip() @@ -173,16 +179,15 @@ class @AwardsHandler if $.cookie('frequently_used_emojis') frequently_used_emojis = @getFrequentlyUsedEmojis() - ul = $("