Commit 85e9eece authored by Fatih Acet's avatar Fatih Acet

Fix displaying emoji only comments.

To render emoji in the emoji bar of an issue or MR we actually need the emoji unicode and unicode info is stored in the emoji menu widget. That widget could only be visible if user clicks the "Add" button and there may not be a widget when posting emoji only comments. So this change will check existence of the widget and create it before posting the emoji if it's not exist to render it correctly.
parent e8c8c9d7
...@@ -20,7 +20,9 @@ class @AwardsHandler ...@@ -20,7 +20,9 @@ class @AwardsHandler
.off "click", ".js-emoji-btn" .off "click", ".js-emoji-btn"
.on "click", ".js-emoji-btn", @handleClick .on "click", ".js-emoji-btn", @handleClick
handleClick: (e) => handleClick: (e) =>
e.preventDefault() e.preventDefault()
$emojiBtn = $(e.currentTarget) $emojiBtn = $(e.currentTarget)
$addAwardBtn = $('.js-add-award.is-active') $addAwardBtn = $('.js-add-award.is-active')
...@@ -31,14 +33,14 @@ class @AwardsHandler ...@@ -31,14 +33,14 @@ class @AwardsHandler
else if $votesBlock.length is 0 else if $votesBlock.length is 0
$votesBlock = $addAwardBtn.closest('.js-awards-block') $votesBlock = $addAwardBtn.closest('.js-awards-block')
$votesBlock.addClass 'js-awards-block-current' $votesBlock.addClass 'js-awards-block'
awardUrl = $votesBlock.data 'award-url' awardUrl = $votesBlock.data 'award-url'
emoji = $emojiBtn emoji = $emojiBtn.find('.icon').data('emoji')
.find(".icon")
.data "emoji"
@addAward awardUrl, emoji @addAward awardUrl, emoji
showEmojiMenu: ($addBtn) -> showEmojiMenu: ($addBtn) ->
$menu = $('.emoji-menu') $menu = $('.emoji-menu')
if $menu.length if $menu.length
...@@ -55,23 +57,29 @@ class @AwardsHandler ...@@ -55,23 +57,29 @@ class @AwardsHandler
$menu.addClass "is-visible" $menu.addClass "is-visible"
$("#emoji_search").focus() $("#emoji_search").focus()
else else
$addBtn.addClass "is-loading is-active" $addBtn.addClass 'is-loading is-active'
$.get $addBtn.data('award-menu-url'), (response) => url = $addBtn.data 'award-menu-url'
$addBtn.removeClass "is-loading"
$('body').append response
$menu = $(".emoji-menu")
@createEmojiMenu url, =>
$addBtn.removeClass 'is-loading'
$menu = $('.emoji-menu')
@positionMenu($menu, $addBtn) @positionMenu($menu, $addBtn)
@renderFrequentlyUsedBlock() @renderFrequentlyUsedBlock()
setTimeout => setTimeout =>
$menu.addClass "is-visible" $menu.addClass 'is-visible'
$("#emoji_search").focus() $('#emoji_search').focus()
@setupSearch() @setupSearch()
, 200 , 200
createEmojiMenu: (awardMenuUrl, callback) ->
$.get awardMenuUrl, (response) =>
$('body').append response
callback()
positionMenu: ($menu, $addBtn) -> positionMenu: ($menu, $addBtn) ->
position = $addBtn.data('position') position = $addBtn.data('position')
...@@ -170,8 +178,9 @@ class @AwardsHandler ...@@ -170,8 +178,9 @@ class @AwardsHandler
), 200 ), 200
createEmoji: (emoji) -> createEmoji_: (emoji) ->
emojiCssClass = @resolveNameToCssClass(emoji)
emojiCssClass = @resolveNameToCssClass emoji
buttonHtml = "<button class='btn award-control js-emoji-btn has-tooltip active' title='me' data-placement='bottom'> buttonHtml = "<button class='btn award-control js-emoji-btn has-tooltip active' title='me' data-placement='bottom'>
<div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div> <div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div>
...@@ -179,16 +188,28 @@ class @AwardsHandler ...@@ -179,16 +188,28 @@ class @AwardsHandler
</button>" </button>"
emoji_node = $(buttonHtml) emoji_node = $(buttonHtml)
.insertBefore(".js-awards-block-current .js-award-holder:not(.js-award-action-btn)") .insertBefore '.js-awards-block .js-award-holder:not(.js-award-action-btn)'
.find(".emoji-icon") .find '.emoji-icon'
.data("emoji", emoji) .data 'emoji', emoji
$('.award-control').tooltip() $('.award-control').tooltip()
$currentBlock = $('.js-awards-block-current') $currentBlock = $ '.js-awards-block'
if $currentBlock.is('.hidden')
if $currentBlock.is '.hidden'
$currentBlock.removeClass 'hidden' $currentBlock.removeClass 'hidden'
createEmoji: (emoji) ->
return @createEmoji_ emoji if $('.emoji-menu').length
awardMenuUrl = $('[data-award-menu-url]').data 'award-menu-url'
@createEmojiMenu awardMenuUrl, => @createEmoji emoji
resolveNameToCssClass: (emoji) -> resolveNameToCssClass: (emoji) ->
emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']") emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']")
if emoji_icon.length > 0 if emoji_icon.length > 0
...@@ -197,7 +218,8 @@ class @AwardsHandler ...@@ -197,7 +218,8 @@ class @AwardsHandler
# Find by alias # Find by alias
unicodeName = $(".emoji-menu-content [data-aliases*=':#{emoji}:']").data("unicode-name") unicodeName = $(".emoji-menu-content [data-aliases*=':#{emoji}:']").data("unicode-name")
"emoji-#{unicodeName}" return "emoji-#{unicodeName}"
postEmoji: (awardUrl, emoji, callback) -> postEmoji: (awardUrl, emoji, callback) ->
$.post awardUrl, { name: emoji }, (data) -> $.post awardUrl, { name: emoji }, (data) ->
...@@ -205,7 +227,7 @@ class @AwardsHandler ...@@ -205,7 +227,7 @@ class @AwardsHandler
callback.call() callback.call()
findEmojiIcon: (emoji) -> findEmojiIcon: (emoji) ->
$(".js-awards-block-current.awards > .js-emoji-btn [data-emoji='#{emoji}']") $(".js-awards-block.awards > .js-emoji-btn [data-emoji='#{emoji}']")
scrollToAwards: -> scrollToAwards: ->
$('body, html').animate({ $('body, html').animate({
......
...@@ -167,8 +167,8 @@ class @Notes ...@@ -167,8 +167,8 @@ class @Notes
return return
if note.award if note.award
awardsHandler.addAwardToEmojiBar(note.note) awards_handler.addAwardToEmojiBar(note.name)
awardsHandler.scrollToAwards() awards_handler.scrollToAwards()
# render note if it not present in loaded list # render note if it not present in loaded list
# or skip if rendered # or skip if rendered
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment