From 3a196317abe1899b2b3c61fa97bed797c80456b9 Mon Sep 17 00:00:00 2001 From: connorshea Date: Thu, 7 Apr 2016 17:40:22 -0600 Subject: [PATCH] Add "sprite" parameter to emoji_icon helper The emoji_icon helper used to display the award emoji in Issue and Merge Request views. By default the spritesheet is used, but passing `sprite: false` to the `emoji_icon` helper makes the emoji render as separate images. For award emoji displayed by default (e.g. thumbs-up, thumbs-down, and any that have been awarded to the issue/MR) the independent images are used. Only when the full emoji menu is opened does the full spritesheet load. On a normal issue this change decreases the page load by 670KB or 250KB depending on pixel density. Resolves #14334. --- CHANGELOG | 1 + app/helpers/issues_helper.rb | 33 +++++++++++++++++++------- app/views/votes/_votes_block.html.haml | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 54d79259b30..0997c15cfdc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.7.0 (unreleased) + - Load award emoji images separately unless opening the full picker. Saves several hundred KBs of data for most pages. (Connor Shea) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu) - Improved Markdown rendering performance !3389 (Yorick Peterse) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 24b90fef4fe..bcf8639c829 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -115,17 +115,32 @@ module IssuesHelper icon('eye-slash') if issue.confidential? end - def emoji_icon(name, unicode = nil, aliases = []) + def emoji_icon(name, unicode = nil, aliases = [], sprite: true) unicode ||= Emoji.emoji_filename(name) rescue "" - content_tag :div, "", - class: "icon emoji-icon emoji-#{unicode}", - title: name, - data: { - aliases: aliases.join(' '), - emoji: name, - unicode_name: unicode - } + data = { + aliases: aliases.join(" "), + emoji: name, + unicode_name: unicode + } + + if sprite + # Emoji icons for the emoji menu, these use a spritesheet. + content_tag :div, "", + class: "icon emoji-icon emoji-#{unicode}", + title: name, + data: data + else + # Emoji icons displayed separately, used for the awards already given + # to an issue or merge request. + content_tag :img, "", + class: "icon emoji", + title: name, + height: "20px", + width: "20px", + src: url_to_image("#{unicode}.png"), + data: data + end end def emoji_author_list(notes, current_user) diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml index 8ffcdc4a327..49cfcd53d74 100644 --- a/app/views/votes/_votes_block.html.haml +++ b/app/views/votes/_votes_block.html.haml @@ -1,7 +1,7 @@ .awards.votes-block - awards_sort(votable.notes.awards.grouped_awards).each do |emoji, notes| %button.btn.award-control.js-emoji-btn.has-tooltip{class: (note_active_class(notes, current_user)), title: emoji_author_list(notes, current_user), data: {placement: "top"}} - = emoji_icon(emoji) + = emoji_icon(emoji, sprite: false) %span.award-control-text.js-counter = notes.count