Commit c2bd71fd authored by Fatih Acet's avatar Fatih Acet

" '.

parent 20e6e0db
class @AwardsHandler class @AwardsHandler
constructor: -> constructor: ->
@aliases = emojiAliases() @aliases = emojiAliases()
$(document) $(document)
.off "click", ".js-add-award" .off 'click', '.js-add-award'
.on "click", ".js-add-award", (event) => .on 'click', '.js-add-award', (event) =>
event.stopPropagation() event.stopPropagation()
event.preventDefault() event.preventDefault()
@showEmojiMenu $(event.currentTarget) @showEmojiMenu $(event.currentTarget)
$("html").on 'click', (event) -> $('html').on 'click', (event) ->
if !$(event.target).closest(".emoji-menu").length unless $(event.target).closest('.emoji-menu').length
if $(".emoji-menu").is(":visible") if $('.emoji-menu').is(':visible')
$('.js-add-award.is-active').removeClass 'is-active' $('.js-add-award.is-active').removeClass 'is-active'
$(".emoji-menu").removeClass "is-visible" $('.emoji-menu').removeClass 'is-visible'
$(document) $(document)
.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) =>
...@@ -37,16 +39,16 @@ class @AwardsHandler ...@@ -37,16 +39,16 @@ class @AwardsHandler
if $menu.length if $menu.length
$holder = $addBtn.closest('.js-award-holder') $holder = $addBtn.closest('.js-award-holder')
if $menu.is ".is-visible" if $menu.is '.is-visible'
$addBtn.removeClass "is-active" $addBtn.removeClass 'is-active'
$menu.removeClass "is-visible" $menu.removeClass 'is-visible'
$("#emoji_search").blur() $('#emoji_search').blur()
else else
$addBtn.addClass "is-active" $addBtn.addClass 'is-active'
@positionMenu($menu, $addBtn) @positionMenu($menu, $addBtn)
$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'
url = $addBtn.data 'award-menu-url' url = $addBtn.data 'award-menu-url'
...@@ -81,10 +83,10 @@ class @AwardsHandler ...@@ -81,10 +83,10 @@ class @AwardsHandler
if position? and position is 'right' if position? and position is 'right'
css.left = "#{($addBtn.offset().left - $menu.outerWidth()) + 20}px" css.left = "#{($addBtn.offset().left - $menu.outerWidth()) + 20}px"
$menu.addClass "is-aligned-right" $menu.addClass 'is-aligned-right'
else else
css.left = "#{$addBtn.offset().left}px" css.left = "#{$addBtn.offset().left}px"
$menu.removeClass "is-aligned-right" $menu.removeClass 'is-aligned-right'
$menu.css(css) $menu.css(css)
...@@ -114,7 +116,7 @@ class @AwardsHandler ...@@ -114,7 +116,7 @@ class @AwardsHandler
else else
counter = $emojiBtn.find('.js-counter') counter = $emojiBtn.find('.js-counter')
counter.text(parseInt(counter.text()) + 1) counter.text(parseInt(counter.text()) + 1)
$emojiBtn.addClass("active") $emojiBtn.addClass('active')
@addMeToUserList(emoji) @addMeToUserList(emoji)
else else
@createEmoji(emoji) @createEmoji(emoji)
...@@ -137,8 +139,8 @@ class @AwardsHandler ...@@ -137,8 +139,8 @@ class @AwardsHandler
@addAward awardUrl, mutualVote, no if isAlreadyVoted @addAward awardUrl, mutualVote, no if isAlreadyVoted
isActive: ($emojiBtn) -> isActive: ($emojiBtn) -> $emojiBtn.hasClass 'active'
$emojiBtn.hasClass("active")
decrementCounter: ($emojiBtn, emoji) -> decrementCounter: ($emojiBtn, emoji) ->
isntNoteBody = $emojiBtn.closest('.note-body').length is 0 isntNoteBody = $emojiBtn.closest('.note-body').length is 0
...@@ -152,15 +154,15 @@ class @AwardsHandler ...@@ -152,15 +154,15 @@ class @AwardsHandler
if counterNumber > 1 if counterNumber > 1
counter.text(counterNumber - 1) counter.text(counterNumber - 1)
@removeMeFromUserList($emojiBtn, emoji) @removeMeFromUserList($emojiBtn, emoji)
else if (emoji == "thumbsup" || emoji == "thumbsdown") && isntNoteBody else if (emoji == 'thumbsup' || emoji == 'thumbsdown') && isntNoteBody
$emojiBtn.tooltip("destroy") $emojiBtn.tooltip('destroy')
counter.text('0') counter.text('0')
@removeMeFromUserList($emojiBtn, emoji) @removeMeFromUserList($emojiBtn, emoji)
else else
$emojiBtn.tooltip("destroy") $emojiBtn.tooltip('destroy')
$emojiBtn.remove() $emojiBtn.remove()
$emojiBtn.removeClass("active") $emojiBtn.removeClass('active')
getAwardTooltip: ($awardBlock) -> getAwardTooltip: ($awardBlock) ->
...@@ -194,19 +196,20 @@ class @AwardsHandler ...@@ -194,19 +196,20 @@ class @AwardsHandler
origTitle = @getAwardTooltip awardBlock origTitle = @getAwardTooltip awardBlock
users = [] users = []
if origTitle
if origTitle if origTitle
users = origTitle.trim().split(', ') users = origTitle.trim().split(', ')
users.push('me') users.push('me')
awardBlock.attr('title', users.join(", ")) awardBlock.attr('title', users.join(', '))
@resetTooltip(awardBlock) @resetTooltip(awardBlock)
resetTooltip: (award) -> resetTooltip: (award) ->
award.tooltip("destroy") award.tooltip('destroy')
# "destroy" call is asynchronous and there is no appropriate callback on it, this is why we need to set timeout. # 'destroy' call is asynchronous and there is no appropriate callback on it, this is why we need to set timeout.
setTimeout (-> setTimeout (->
award.tooltip() award.tooltip()
), 200 ), 200
...@@ -247,10 +250,10 @@ class @AwardsHandler ...@@ -247,10 +250,10 @@ class @AwardsHandler
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
unicodeName = emoji_icon.data("unicode-name") unicodeName = emoji_icon.data('unicode-name')
else else
# 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')
return "emoji-#{unicodeName}" return "emoji-#{unicodeName}"
...@@ -274,10 +277,10 @@ class @AwardsHandler ...@@ -274,10 +277,10 @@ class @AwardsHandler
addEmojiToFrequentlyUsedList: (emoji) -> addEmojiToFrequentlyUsedList: (emoji) ->
frequently_used_emojis = @getFrequentlyUsedEmojis() frequently_used_emojis = @getFrequentlyUsedEmojis()
frequently_used_emojis.push(emoji) frequently_used_emojis.push(emoji)
$.cookie('frequently_used_emojis', frequently_used_emojis.join(","), { expires: 365 }) $.cookie('frequently_used_emojis', frequently_used_emojis.join(','), { expires: 365 })
getFrequentlyUsedEmojis: -> getFrequentlyUsedEmojis: ->
frequently_used_emojis = ($.cookie('frequently_used_emojis') || "").split(",") frequently_used_emojis = ($.cookie('frequently_used_emojis') || '').split(',')
_.compact(_.uniq(frequently_used_emojis)) _.compact(_.uniq(frequently_used_emojis))
renderFrequentlyUsedBlock: -> renderFrequentlyUsedBlock: ->
...@@ -287,26 +290,26 @@ class @AwardsHandler ...@@ -287,26 +290,26 @@ class @AwardsHandler
ul = $("<ul class='clearfix emoji-menu-list'>") ul = $("<ul class='clearfix emoji-menu-list'>")
for emoji in frequently_used_emojis for emoji in frequently_used_emojis
$(".emoji-menu-content [data-emoji='#{emoji}']").closest("li").clone().appendTo(ul) $(".emoji-menu-content [data-emoji='#{emoji}']").closest('li').clone().appendTo(ul)
$("input.emoji-search").after(ul).after($("<h5>").text("Frequently used")) $('input.emoji-search').after(ul).after($('<h5>').text('Frequently used'))
setupSearch: -> setupSearch: ->
$("input.emoji-search").on 'keyup', (ev) => $('input.emoji-search').on 'keyup', (ev) =>
term = $(ev.target).val() term = $(ev.target).val()
# Clean previous search results # Clean previous search results
$("ul.emoji-menu-search, h5.emoji-search").remove() $('ul.emoji-menu-search, h5.emoji-search').remove()
if term if term
# Generate a search result block # Generate a search result block
h5 = $("<h5>").text("Search results").addClass("emoji-search") h5 = $('<h5>').text('Search results').addClass('emoji-search')
found_emojis = @searchEmojis(term).show() found_emojis = @searchEmojis(term).show()
ul = $("<ul>").addClass("emoji-menu-list emoji-menu-search").append(found_emojis) ul = $('<ul>').addClass('emoji-menu-list emoji-menu-search').append(found_emojis)
$(".emoji-menu-content ul, .emoji-menu-content h5").hide() $('.emoji-menu-content ul, .emoji-menu-content h5').hide()
$(".emoji-menu-content").append(h5).append(ul) $('.emoji-menu-content').append(h5).append(ul)
else else
$(".emoji-menu-content").children().show() $('.emoji-menu-content').children().show()
searchEmojis: (term)-> searchEmojis: (term)->
$(".emoji-menu-content [data-emoji*='#{term}']").closest("li").clone() $(".emoji-menu-content [data-emoji*='#{term}']").closest('li').clone()
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