From 36d0442e837cd520dec780590040c83108bc14e6 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Tue, 17 Nov 2015 16:44:58 +0200 Subject: [PATCH] replace emoji references from class name to data [ci skip] --- app/assets/javascripts/awards_handler.coffee | 36 +++++++++++--------- app/assets/javascripts/notes.js.coffee | 2 +- app/views/votes/_votes_block.html.haml | 10 +++--- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee index 1ede7c317c8..8803c0cca2d 100644 --- a/app/assets/javascripts/awards_handler.coffee +++ b/app/assets/javascripts/awards_handler.coffee @@ -3,25 +3,27 @@ class @AwardsHandler addAward: (emoji) -> @postEmoji emoji, => - if @exist(emoji) - if @isActive(emoji) - @decrementCounter(emoji) - else - counter = $(".icon." + emoji).siblings(".counter") - counter.text(parseInt(counter.text()) + 1) - counter.parent().addClass("active") - else - @createEmoji(emoji) + @addAwardToEmojiBar(emoji) + addAwardToEmojiBar: (emoji) -> + if @exist(emoji) + if @isActive(emoji) + @decrementCounter(emoji) + else + counter = @findEmojiIcon(emoji).siblings(".counter") + counter.text(parseInt(counter.text()) + 1) + counter.parent().addClass("active") + else + @createEmoji(emoji) exist: (emoji) -> - $(".icon").hasClass(emoji) + @findEmojiIcon(emoji).length > 0 isActive: (emoji) -> - $(".icon." + emoji).parent().hasClass("active") + @findEmojiIcon(emoji).parent().hasClass("active") decrementCounter: (emoji) -> - counter = $(".icon." + emoji).siblings(".counter") + counter = @findEmojiIcon(emoji).siblings(".counter") if parseInt(counter.text()) > 1 counter.text(parseInt(counter.text()) - 1) @@ -33,7 +35,7 @@ class @AwardsHandler createEmoji: (emoji) -> nodes = [] nodes.push("
") - nodes.push("
") + nodes.push("
") nodes.push(@getImage(emoji)) nodes.push("
") nodes.push("
1") @@ -42,14 +44,16 @@ class @AwardsHandler $(".awards-controls").before(nodes.join("\n")) getImage: (emoji) -> - $("li." + emoji).html() + $("li[data-emoji='" + emoji + "'").html() postEmoji: (emoji, callback) -> - emoji = emoji.replace("emoji-", "") $.post @post_emoji_url, { emoji: emoji noteable_type: @noteable_type noteable_id: @noteable_id },(data) -> if data.ok - callback.call() \ No newline at end of file + callback.call() + + findEmojiIcon: (emoji) -> + $(".icon[data-emoji='" + emoji + "'") \ No newline at end of file diff --git a/app/assets/javascripts/notes.js.coffee b/app/assets/javascripts/notes.js.coffee index cd27b20dd7c..73a95c455e8 100644 --- a/app/assets/javascripts/notes.js.coffee +++ b/app/assets/javascripts/notes.js.coffee @@ -121,7 +121,7 @@ class @Notes @initTaskList() if note.award - awards_handler.addAward("emoji-" + note.note) + awards_handler.addAwardToEmojiBar(note.note) ### Check if note does not exists on page diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml index 7f988160ad9..118a095181f 100644 --- a/app/views/votes/_votes_block.html.haml +++ b/app/views/votes/_votes_block.html.haml @@ -1,7 +1,7 @@ .awards.votes-block - votable.notes.awards.grouped_awards.each do | vote | .award{class: ("active" if vote.last.pluck(:author_id).include?(current_user.id))} - .icon{class: "emoji-#{vote.first}"} + .icon{"data-emoji" => "#{vote.first}"} = image_tag url_to_emoji(vote.first), height: "20px", width: "20px" .counter = vote.last.count @@ -10,22 +10,22 @@ %a#add-award{"data-toggle" => "dropdown", "data-target" => "#", "href" => "#"} + %ul.dropdown-menu.awards-menu - ["100", "blush", "heart", "smile", "rage", "beers", "thumbsup", "disappointed", "ok_hand", "helicopter"].each do |emoji| - %li{class: "emoji-#{emoji}"}= image_tag url_to_emoji(emoji), height: "20px", width: "20px" + %li{"data-emoji" => "#{emoji}"}= image_tag url_to_emoji(emoji), height: "20px", width: "20px" :coffeescript post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}" noteable_type = "Issue" noteable_id = #{@issue.id} - awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id) + window.awards_handler = new AwardsHandler(post_emoji_url, noteable_type, noteable_id) $ -> $(".awards-menu li").click (e)-> - emoji = $(this).attr("class") + emoji = $(this).data("emoji") awards_handler.addAward(emoji) $(".awards").on "click", ".award", (e)-> - emoji = /(emoji-\S*)/.exec($(this).find(".icon").attr("class"))[0] + emoji = $(this).find(".icon").data("emoji") awards_handler.addAward(emoji) -- GitLab