From 9909c715dca1b07e89a8c9f4bd511dd334017467 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 1 Sep 2015 13:23:03 +0800 Subject: [PATCH 1/2] FIX: Emoji can't be copy and pasted. --- app/assets/javascripts/discourse/lib/emoji/emoji.js.erb | 3 ++- test/javascripts/lib/bbcode-test.js.es6 | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb b/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb index e662df804..8a8fceb25 100644 --- a/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb +++ b/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb @@ -77,7 +77,8 @@ function imageFor(code) { code = code.toLowerCase(); var url = urlFor(code); if (url) { - return ['img', { href: url, title: ':' + code + ':', 'class': 'emoji', alt: code }]; + var code = ':' + code + ':'; + return ['img', { href: url, title: code, 'class': 'emoji', alt: code }]; } } diff --git a/test/javascripts/lib/bbcode-test.js.es6 b/test/javascripts/lib/bbcode-test.js.es6 index 575ad7e75..385569c9c 100644 --- a/test/javascripts/lib/bbcode-test.js.es6 +++ b/test/javascripts/lib/bbcode-test.js.es6 @@ -52,7 +52,7 @@ test('spoiler', function() { format("[spoiler]it's a sled[/spoiler]", "it's a sled", "supports spoiler tags on text"); format("[spoiler][/spoiler]", "", "supports spoiler tags on images"); - format("[spoiler] This is the **bold** :smiley: [/spoiler]", " This is the bold \"smiley\" ", "supports spoiler tags on emojis"); + format("[spoiler] This is the **bold** :smiley: [/spoiler]", " This is the bold \":smiley:\" ", "supports spoiler tags on emojis"); format("[spoiler] Why not both ?[/spoiler]", " Why not both ?", "supports images and text"); format("In a p tag a spoiler [spoiler] [/spoiler] can work.", "In a p tag a spoiler can work.", "supports images and text in a p tag"); }); From c2eceaa50de002f69d6bba513f5fd7e0b6db3460 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 1 Sep 2015 14:26:23 +0800 Subject: [PATCH 2/2] FIX: Allow user to quote Emojis. --- app/assets/javascripts/discourse/lib/utilities.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/lib/utilities.js b/app/assets/javascripts/discourse/lib/utilities.js index ac55bdaf4..05ed05caf 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js +++ b/app/assets/javascripts/discourse/lib/utilities.js @@ -97,7 +97,10 @@ Discourse.Utilities = { // Strip out any .click elements from the HTML before converting it to text var div = document.createElement('div'); div.innerHTML = html; - $('.clicks', $(div)).remove(); + var $div = $(div); + // Find all emojis and replace with its title attribute. + $div.find('img.emoji').replaceWith(function() { return this.title }); + $('.clicks', $div).remove(); var text = div.textContent || div.innerText || ""; return String(text).trim();