summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/awards_handler.coffee
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-12-17 14:29:55 +0200
committerValery Sizov <vsv2711@gmail.com>2015-12-22 23:12:23 +0200
commita48dd40a926fdeddfdd76cea5db468a82096c7f4 (patch)
tree523151bfaa5c0f8f554b0029ae8dd5ae3a7ddc86 /app/assets/javascripts/awards_handler.coffee
parent3b61dc47ec377b857b66f9b2a81a183276163f4e (diff)
downloadgitlab-ce-a48dd40a926fdeddfdd76cea5db468a82096c7f4.tar.gz
base implementation of emoji picker [ci skip]
Diffstat (limited to 'app/assets/javascripts/awards_handler.coffee')
-rw-r--r--app/assets/javascripts/awards_handler.coffee39
1 files changed, 24 insertions, 15 deletions
diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee
index 3ff9ba77dfc..f3fdd46cf52 100644
--- a/app/assets/javascripts/awards_handler.coffee
+++ b/app/assets/javascripts/awards_handler.coffee
@@ -1,12 +1,23 @@
class @AwardsHandler
constructor: (@post_emoji_url, @noteable_type, @noteable_id, @aliases) ->
+ $(".add-award").click (event)->
+ event.stopPropagation()
+ event.preventDefault()
+ $(".emoji-menu").show()
+
+ $("html").click ->
+ if !$(event.target).closest(".emoji-menu").length
+ if $(".emoji-menu").is(":visible")
+ $(".emoji-menu").hide()
addAward: (emoji) ->
emoji = @normilizeEmojiName(emoji)
@postEmoji emoji, =>
@addAwardToEmojiBar(emoji)
+
+ $(".emoji-menu").hide()
- addAwardToEmojiBar: (emoji, custom_path = '') ->
+ addAwardToEmojiBar: (emoji) ->
emoji = @normilizeEmojiName(emoji)
if @exist(emoji)
if @isActive(emoji)
@@ -17,7 +28,7 @@ class @AwardsHandler
counter.parent().addClass("active")
@addMeToAuthorList(emoji)
else
- @createEmoji(emoji, custom_path)
+ @createEmoji(emoji)
exist: (emoji) ->
@findEmojiIcon(emoji).length > 0
@@ -54,31 +65,29 @@ class @AwardsHandler
resetTooltip: (award) ->
award.tooltip("destroy")
- # "destroy" call is asynchronous, this is why we need to set timeout.
+ # "destroy" call is asynchronous and there is no appropriate callnack on it, this is why we need to set timeout.
setTimeout (->
award.tooltip()
), 200
- createEmoji: (emoji, custom_path) ->
+ createEmoji: (emoji) ->
+ emojiCssClass = @resolveNameToCssClass(emoji)
+
nodes = []
nodes.push("<div class='award active' title='me'>")
- nodes.push("<div class='icon' data-emoji='" + emoji + "'>")
- nodes.push(@getImage(emoji, custom_path))
+ nodes.push("<div class='icon emoji-icon " + emojiCssClass + "' data-emoji='" + emoji + "'></div>")
+ nodes.push("<div class='counter'>1</div>")
nodes.push("</div>")
- nodes.push("<div class='counter'>1")
- nodes.push("</div></div>")
- $(".awards-controls").before(nodes.join("\n"))
+ emoji_node = $(nodes.join("\n")).insertBefore(".awards-controls").find(".emoji-icon").data("emoji", emoji)
$(".award").tooltip()
- getImage: (emoji, custom_path) ->
- if custom_path
- $("<img>").attr({src: custom_path, width: 20, height: 20}).wrap("<div>").parent().html()
- else
- $("li[data-emoji='" + emoji + "']").html()
+ resolveNameToCssClass: (emoji) ->
+ unicodeName = $(".emoji-menu-content [data-emoji='?']".replace("?", emoji)).data("unicode-name")
+ "emoji-" + unicodeName
postEmoji: (emoji, callback) ->
$.post @post_emoji_url, { note: {
@@ -90,7 +99,7 @@ class @AwardsHandler
callback.call()
findEmojiIcon: (emoji) ->
- $(".icon[data-emoji='" + emoji + "']")
+ $(".award [data-emoji='" + emoji + "']")
scrollToAwards: ->
$('body, html').animate({