FEATURE: add support for emojis in title

This commit is contained in:
Régis Hanol 2015-06-15 15:27:22 +02:00
parent d910d3c37e
commit 2d03163be0
7 changed files with 25 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import registerUnbound from 'discourse/helpers/register-unbound';
registerUnbound('topic-link', function(topic) {
var title = topic.get('fancy_title');
var title = topic.get('fancyTitle');
return new Handlebars.SafeString("<a href='" + topic.get('lastUnreadUrl') + "' class='title'>" + title + "</a>");
});

View File

@ -99,7 +99,7 @@ function checkPrev(prev) {
var lastToken = prev[prev.length-1];
if (lastToken && lastToken.charAt) {
var lastChar = lastToken.charAt(lastToken.length-1);
if (lastChar !== ' ' && lastChar !== "\n") return false;
if (!/\s/.test(lastChar)) return false;
}
}
return true;
@ -140,10 +140,9 @@ Discourse.Dialect.registerInline(':', function(text, match, prev) {
translationColonRegexp.lastIndex = 0;
var m = translationColonRegexp.exec(text);
if (m && m[0] && text.indexOf(m[0]) === 0) {
// Check outer edge
var lastChar = text.charAt(m[0].length);
if (lastChar && (lastChar !== ' ' && lastChar !== "\n")) return;
if (lastChar && !/\s/.test(lastChar)) return;
contents = imageFor(translationsWithColon[m[0]]);
if (contents) {
return [m[0].length, contents];

View File

@ -5,6 +5,20 @@ const Topic = RestModel.extend({
errorTitle: null,
errorLoading: false,
fancyTitle: function() {
let title = this.get("fancy_title");
if (this.siteSettings.enable_emoji && title.indexOf(":") >= 0) {
title = title.replace(/:\S+:?/, function(m) {
const emoji = Discourse.Emoji.translations[m] ? Discourse.Emoji.translations[m] : m.slice(1, m.length - 1),
url = Discourse.Emoji.urlFor(emoji);
return url ? "<img src='" + url + "' title='" + emoji + "' alt='" + emoji + "' class='emoji'>" : m;
});
}
return title;
}.property("fancy_title"),
// returns createdAt if there's no bumped date
bumpedAt: function() {
const bumpedAt = this.get('bumped_at');

View File

@ -1,5 +1,5 @@
{{topic-status topic=topic}}
<a class='title' href="{{unbound topic.lastUnreadUrl}}">{{{unbound topic.fancy_title}}}</a>
<a class='title' href="{{unbound topic.lastUnreadUrl}}">{{{unbound topic.fancyTitle}}}</a>
{{topic-post-badges newPosts=topic.totalUnread unseen=topic.unseen url=topic.lastUnreadUrl}}
{{#if latestTopicOnly}}

View File

@ -8,7 +8,7 @@
{{#if topic.details.loaded}}
{{topic-status topic=topic}}
<a class='topic-link' href='{{unbound topic.url}}' {{action "jumpToTopPost"}}>{{{topic.fancy_title}}}</a>
<a class='topic-link' href='{{unbound topic.url}}' {{action "jumpToTopPost"}}>{{{topic.fancyTitle}}}</a>
{{else}}
{{#if topic.errorLoading}}
<span class="error">{{topic.errorTitle}}</span>

View File

@ -37,7 +37,7 @@
{{#if model.details.loaded}}
{{topic-status topic=model}}
<a href='{{unbound model.url}}' {{action "jumpTop"}} class='fancy-title'>
{{{model.fancy_title}}}
{{{model.fancyTitle}}}
</a>
{{/if}}

View File

@ -71,3 +71,8 @@ test("recover", function() {
blank(topic.get('deleted_by'), "it clears deleted_by");
//ok(Discourse.ajax.calledOnce, "it called recover over the wire");
});
test('fancyTitle', function() {
var topic = Topic.create({ siteSettings: { enable_emoji: true }, fancy_title: ":smile: with all the emojis" });
equal(topic.get('fancyTitle'), "<img src='/images/emoji/undefined/smile.png?v=0' title='smile' alt='smile' class='emoji'> with all the emojis", "supports emojis");
});