Commit 2bbe781d authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

revert front end changes

parent 4558b5b9
class @AwardsHandler class @AwardsHandler
constructor: -> constructor: (@getEmojisUrl, @postEmojiUrl, @noteableType, @noteableId, @unicodes) ->
@aliases = emojiAliases() $('.js-add-award').on 'click', (event) =>
event.stopPropagation()
event.preventDefault()
$(document) @showEmojiMenu()
.off "click", ".js-add-award"
.on "click", ".js-add-award", (event) =>
event.stopPropagation()
event.preventDefault()
@showEmojiMenu $(event.currentTarget) $('html').on 'click', (event) ->
if !$(event.target).closest('.emoji-menu').length
if $('.emoji-menu').is(':visible')
$('.emoji-menu').removeClass 'is-visible'
$("html").on 'click', (event) -> $('.awards')
if !$(event.target).closest(".emoji-menu").length .off 'click'
if $(".emoji-menu").is(":visible") .on 'click', '.js-emoji-btn', @handleClick
$('.js-add-award.is-active').removeClass 'is-active'
$(".emoji-menu").removeClass "is-visible"
$(document) @renderFrequentlyUsedBlock()
.off "click", ".js-emoji-btn"
.on "click", ".js-emoji-btn", @handleClick
handleClick: (e) => handleClick: (e) ->
e.preventDefault() e.preventDefault()
$emojiBtn = $(e.currentTarget) emoji = $(this)
$addAwardBtn = $('.js-add-award.is-active') .find('.icon')
$votesBlock = $($addAwardBtn.closest('.js-award-holder').data('target')) .data 'emoji'
if $addAwardBtn.length is 0
$votesBlock = $emojiBtn.closest('.js-awards-block')
else if $votesBlock.length is 0
$votesBlock = $addAwardBtn.closest('.js-awards-block')
$votesBlock.addClass 'js-awards-block-current'
awardUrl = $votesBlock.data 'award-url'
emoji = $emojiBtn
.find(".icon")
.data "emoji"
@addAward awardUrl, emoji
showEmojiMenu: ($addBtn) ->
$menu = $('.emoji-menu')
if $menu.length
$holder = $addBtn.closest('.js-award-holder')
if $menu.is ".is-visible"
$addBtn.removeClass "is-active"
$menu.removeClass "is-visible"
$("#emoji_search").blur()
else
$addBtn.addClass "is-active"
@positionMenu($menu, $addBtn)
$menu.addClass "is-visible" if emoji is 'thumbsup' and awardsHandler.didUserClickEmoji $(this), 'thumbsdown'
$("#emoji_search").focus() awardsHandler.addAward 'thumbsdown'
else
$addBtn.addClass "is-loading is-active"
$.get $addBtn.data('award-menu-url'), (response) =>
$addBtn.removeClass "is-loading"
$('body').append response
$menu = $(".emoji-menu") else if emoji is 'thumbsdown' and awardsHandler.didUserClickEmoji $(this), 'thumbsup'
awardsHandler.addAward 'thumbsup'
@positionMenu($menu, $addBtn) awardsHandler.addAward emoji
@renderFrequentlyUsedBlock() $(this).trigger 'blur'
didUserClickEmoji: (that, emoji) ->
if $(that).siblings("button:has([data-emoji=#{emoji}])").attr('data-original-title')
$(that).siblings("button:has([data-emoji=#{emoji}])").attr('data-original-title').indexOf('me') > -1
showEmojiMenu: ->
if $('.emoji-menu').length
if $('.emoji-menu').is '.is-visible'
$('.emoji-menu').removeClass 'is-visible'
$('#emoji_search').blur()
else
$('.emoji-menu').addClass 'is-visible'
$('#emoji_search').focus()
else
$('.js-add-award').addClass 'is-loading'
$.get @getEmojisUrl, (response) =>
$('.js-add-award').removeClass 'is-loading'
$('.js-award-holder').append response
setTimeout => setTimeout =>
$menu.addClass "is-visible" $('.emoji-menu').addClass 'is-visible'
$("#emoji_search").focus() $('#emoji_search').focus()
@setupSearch() @setupSearch()
, 200 , 200
positionMenu: ($menu, $addBtn) -> addAward: (emoji) ->
position = $addBtn.data('position') @postEmoji emoji, =>
# The menu could potentially be off-screen or in a hidden overflow element
# So we position the element absolute in the body
css =
top: "#{$addBtn.offset().top + $addBtn.outerHeight()}px"
if position? and position is 'right'
css.left = "#{($addBtn.offset().left - $menu.outerWidth()) + 20}px"
$menu.addClass "is-aligned-right"
else
css.left = "#{$addBtn.offset().left}px"
$menu.removeClass "is-aligned-right"
$menu.css(css)
addAward: (awardUrl, emoji) ->
emoji = @normalizeEmojiName(emoji)
@postEmoji awardUrl, emoji, =>
@addAwardToEmojiBar(emoji) @addAwardToEmojiBar(emoji)
$('.js-awards-block-current').removeClass 'js-awards-block-current' $('.emoji-menu').removeClass 'is-visible'
$(".emoji-menu").removeClass "is-visible"
addAwardToEmojiBar: (emoji) -> addAwardToEmojiBar: (emoji) ->
@addEmojiToFrequentlyUsedList(emoji) @addEmojiToFrequentlyUsedList(emoji)
emoji = @normalizeEmojiName(emoji) if @exist(emoji)
$emojiBtn = @findEmojiIcon(emoji).parent() if @isActive(emoji)
@decrementCounter(emoji)
if $emojiBtn.length > 0
if @isActive($emojiBtn)
@decrementCounter($emojiBtn, emoji)
else else
$counter = $emojiBtn.find('.js-counter') counter = @findEmojiIcon(emoji).siblings('.js-counter')
$counter.text(parseInt($counter.text()) + 1) counter.text(parseInt(counter.text()) + 1)
$emojiBtn.addClass("active") counter.parent().addClass('active')
@addMeToUserList(emoji) @addMeToAuthorList(emoji)
else else
@createEmoji(emoji) @createEmoji(emoji)
isActive: ($emojiBtn) -> exist: (emoji) ->
$emojiBtn.hasClass("active") @findEmojiIcon(emoji).length > 0
decrementCounter: ($emojiBtn, emoji) -> isActive: (emoji) ->
$awardsBlock = $emojiBtn.closest('.js-awards-block') @findEmojiIcon(emoji).parent().hasClass('active')
isntNoteBody = $emojiBtn.closest('.note-body').length is 0
counter = $('.js-counter', $emojiBtn) decrementCounter: (emoji) ->
counterNumber = parseInt(counter.text()) counter = @findEmojiIcon(emoji).siblings('.js-counter')
emojiIcon = counter.parent()
if counterNumber > 1 if parseInt(counter.text()) > 1
counter.text(counterNumber - 1) counter.text(parseInt(counter.text()) - 1)
@removeMeFromUserList($emojiBtn, emoji) emojiIcon.removeClass('active')
else if (emoji == "thumbsup" || emoji == "thumbsdown") && isntNoteBody @removeMeFromAuthorList(emoji)
$emojiBtn.tooltip("destroy") else if emoji == 'thumbsup' || emoji == 'thumbsdown'
counter.text('0') emojiIcon.tooltip('destroy')
@removeMeFromUserList($emojiBtn, emoji) counter.text(0)
emojiIcon.removeClass('active')
@removeMeFromAuthorList(emoji)
else else
$emojiBtn.tooltip("destroy") emojiIcon.tooltip('destroy')
$emojiBtn.remove() emojiIcon.remove()
$emojiBtn.removeClass("active") removeMeFromAuthorList: (emoji) ->
awardBlock = @findEmojiIcon(emoji).parent()
if !isntNoteBody and $awardsBlock.children('.js-emoji-btn').length is 0 authors = awardBlock
# If this is a note body, we just hide the award emoji row like the initial state .attr('data-original-title')
$awardsBlock.addClass 'hidden' .split(', ')
authors.splice(authors.indexOf('me'),1)
removeMeFromUserList: ($emojiBtn, emoji) -> awardBlock
award_block = $emojiBtn .closest('.js-emoji-btn')
authors = award_block .attr('data-original-title', authors.join(', '))
.attr("data-original-title") @resetTooltip(awardBlock)
.split(", ")
authors.splice(authors.indexOf("me"),1) addMeToAuthorList: (emoji) ->
award_block awardBlock = @findEmojiIcon(emoji).parent()
.closest(".js-emoji-btn") origTitle = awardBlock.attr('data-original-title').trim()
.attr("data-original-title", authors.join(", ")) authors = []
@resetTooltip(award_block)
addMeToUserList: (emoji) ->
award_block = @findEmojiIcon(emoji).parent()
origTitle = award_block.attr("data-original-title").trim()
users = []
if origTitle if origTitle
users = origTitle.split(', ') authors = origTitle.split(', ')
users.push("me") authors.push('me')
award_block.attr("title", users.join(", ")) awardBlock.attr('data-original-title', authors.join(', '))
@resetTooltip(award_block) @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 (->
...@@ -174,84 +131,85 @@ class @AwardsHandler ...@@ -174,84 +131,85 @@ class @AwardsHandler
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'> nodes = []
<div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div> nodes.push(
<span class='award-control-text js-counter'>1</span> "<button class='btn award-control js-emoji-btn has-tooltip active' data-original-title='me'>",
</button>" "<div class='icon emoji-icon #{emojiCssClass}' data-emoji='#{emoji}'></div>",
"<span class='award-control-text js-counter'>1</span>",
emoji_node = $(buttonHtml) "</button>"
.insertBefore(".js-awards-block-current .js-award-holder:not(.js-award-action-btn)") )
.find(".emoji-icon")
.data("emoji", emoji) $(nodes.join("\n"))
.insertBefore('.js-award-holder')
.find('.emoji-icon')
.data('emoji', emoji)
$('.award-control').tooltip() $('.award-control').tooltip()
$currentBlock = $('.js-awards-block-current')
if $currentBlock.is('.hidden')
$currentBlock.removeClass 'hidden'
resolveNameToCssClass: (emoji) -> resolveNameToCssClass: (emoji) ->
emoji_icon = $(".emoji-menu-content [data-emoji='#{emoji}']") emojiIcon = $(".emoji-menu-content [data-emoji='#{emoji}']")
if emoji_icon.length > 0 if emojiIcon.length > 0
unicodeName = emoji_icon.data("unicode-name") unicodeName = emojiIcon.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')
"emoji-#{unicodeName}" "emoji-#{unicodeName}"
postEmoji: (awardUrl, emoji, callback) -> postEmoji: (emoji, callback) ->
$.post awardUrl, { name: emoji }, (data) -> $.post @postEmojiUrl, { note: {
note: ":#{emoji}:"
noteable_type: @noteableType
noteable_id: @noteableId
}},(data) ->
if data.ok if data.ok
callback.call() callback.call()
findEmojiIcon: (emoji) -> findEmojiIcon: (emoji) ->
$(".js-awards-block-current.awards > .js-emoji-btn [data-emoji='#{emoji}']") $(".awards > .js-emoji-btn [data-emoji='#{emoji}']")
scrollToAwards: -> scrollToAwards: ->
$('body, html').animate({ $('body, html').animate({
scrollTop: $('.awards').offset().top - 80 scrollTop: $('.awards').offset().top - 80
}, 200) }, 200)
normalizeEmojiName: (emoji) ->
@aliases[emoji] || emoji
addEmojiToFrequentlyUsedList: (emoji) -> addEmojiToFrequentlyUsedList: (emoji) ->
frequently_used_emojis = @getFrequentlyUsedEmojis() frequentlyUsedEmojis = @getFrequentlyUsedEmojis()
frequently_used_emojis.push(emoji) frequentlyUsedEmojis.push(emoji)
$.cookie('frequently_used_emojis', frequently_used_emojis.join(","), { expires: 365 }) $.cookie('frequently_used_emojis', frequentlyUsedEmojis.join(','), { expires: 365 })
getFrequentlyUsedEmojis: -> getFrequentlyUsedEmojis: ->
frequently_used_emojis = ($.cookie('frequently_used_emojis') || "").split(",") frequentlyUsedEmojis = ($.cookie('frequently_used_emojis') || '').split(',')
_.compact(_.uniq(frequently_used_emojis)) _.compact(_.uniq(frequentlyUsedEmojis))
renderFrequentlyUsedBlock: -> renderFrequentlyUsedBlock: ->
if $.cookie('frequently_used_emojis') if $.cookie('frequently_used_emojis')
frequently_used_emojis = @getFrequentlyUsedEmojis() frequentlyUsedEmojis = @getFrequentlyUsedEmojis()
ul = $("<ul class='clearfix emoji-menu-list'>") ul = $('<ul>')
for emoji in frequently_used_emojis for emoji in frequentlyUsedEmojis
$(".emoji-menu-content [data-emoji='#{emoji}']").closest("li").clone().appendTo(ul) do (emoji) ->
$(".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').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() foundEmojis = @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(foundEmojis)
$(".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()
...@@ -23,7 +23,6 @@ class Dispatcher ...@@ -23,7 +23,6 @@ class Dispatcher
new Issue() new Issue()
shortcut_handler = new ShortcutsIssuable() shortcut_handler = new ShortcutsIssuable()
new ZenMode() new ZenMode()
awards_handler = new AwardsHandler()
when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show' when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show'
new Milestone() new Milestone()
when 'dashboard:todos:index' when 'dashboard:todos:index'
...@@ -54,7 +53,6 @@ class Dispatcher ...@@ -54,7 +53,6 @@ class Dispatcher
new Diff() new Diff()
shortcut_handler = new ShortcutsIssuable(true) shortcut_handler = new ShortcutsIssuable(true)
new ZenMode() new ZenMode()
awards_handler = new AwardsHandler()
when "projects:merge_requests:diffs" when "projects:merge_requests:diffs"
new Diff() new Diff()
new ZenMode() new ZenMode()
......
((w) ->
w.gl ?= {}
w.gl.emoji ?= {}
w.gl.emoji.emojiAliases = ->
JSON.parse('<%= Gitlab::AwardEmoji.aliases.to_json %>')
) window
\ No newline at end of file
...@@ -162,13 +162,13 @@ class @Notes ...@@ -162,13 +162,13 @@ class @Notes
renderNote: (note) -> renderNote: (note) ->
unless note.valid unless note.valid
if note.award if note.award
flash = new Flash('You have already awarded this emoji, it has been removed', 'alert') flash = new Flash('You have already used this award emoji!', 'alert')
flash.pinTo('.header-content') flash.pinTo('.header-content')
return return
if note.award if note.award
awards_handler.addAwardToEmojiBar(note.name) awardsHandler.addAwardToEmojiBar(note.note)
awards_handler.scrollToAwards() awardsHandler.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
......
.awards { .awards {
line-height: 34px;
.emoji-icon { .emoji-icon {
width: 20px; width: 20px;
height: 20px; height: 20px;
...@@ -7,6 +9,8 @@ ...@@ -7,6 +9,8 @@
.emoji-menu { .emoji-menu {
position: absolute; position: absolute;
top: 100%;
left: 0;
margin-top: 3px; margin-top: 3px;
z-index: 1000; z-index: 1000;
min-width: 160px; min-width: 160px;
...@@ -19,12 +23,7 @@ ...@@ -19,12 +23,7 @@
opacity: 0; opacity: 0;
transform: scale(.2); transform: scale(.2);
transform-origin: 0 -45px; transform-origin: 0 -45px;
transition: .3s cubic-bezier(.87,-.41,.19,1.44); transition: all .3s cubic-bezier(.87,-.41,.19,1.44);
transition-property: transform, opacity;
&.is-aligned-right {
transform-origin: 100% -45px;
}
&.is-visible { &.is-visible {
pointer-events: all; pointer-events: all;
...@@ -108,7 +107,7 @@ ...@@ -108,7 +107,7 @@
} }
&.is-loading { &.is-loading {
.award-control-icon-normal { .award-control-icon {
display: none; display: none;
} }
......
...@@ -63,8 +63,7 @@ ul.notes { ...@@ -63,8 +63,7 @@ ul.notes {
&.is-editting { &.is-editting {
.note-header, .note-header,
.note-text, .note-text,
.edited-text, .edited-text {
.note-awards {
display: none; display: none;
} }
...@@ -74,6 +73,8 @@ ul.notes { ...@@ -74,6 +73,8 @@ ul.notes {
} }
.note-body { .note-body {
overflow: auto;
.note-text { .note-text {
overflow: auto; overflow: auto;
word-wrap: break-word; word-wrap: break-word;
...@@ -323,42 +324,6 @@ ul.notes { ...@@ -323,42 +324,6 @@ ul.notes {
} }
} }
.note-award-control {
display: block;
&:hover,
&:focus {
text-decoration: none;
}
.award-control-icon-loading {
display: none;
}
&.is-loading {
.award-control-icon-normal {
display: none;
}
.award-control-icon-loading {
display: block;
}
}
}
.note-awards {
.awards {
padding-top: 10px;
}
.award-control {
padding-top: 2px;
padding-bottom: 2px;
color: #8f8f8f;
font-size: 13px;
}
}
.disabled-comment { .disabled-comment {
margin-left: -$gl-padding-top; margin-left: -$gl-padding-top;
margin-right: -$gl-padding-top; margin-right: -$gl-padding-top;
......
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