FIX: emoji aliases were not recognised
This commit is contained in:
parent
50bf066afd
commit
4ff1e19712
|
@ -4,6 +4,7 @@ Discourse.Emoji = {};
|
|||
Discourse.Emoji.ImageVersion = "0"
|
||||
|
||||
var emoji = <%= Emoji.standard.map(&:name).flatten.inspect %>;
|
||||
var aliases = <%= Emoji.aliases.inspect.gsub("=>", ":") %>;
|
||||
|
||||
var extendedEmoji = {};
|
||||
Discourse.Dialect.registerEmoji = function(code, url) {
|
||||
|
@ -13,19 +14,19 @@ Discourse.Dialect.registerEmoji = function(code, url) {
|
|||
|
||||
Discourse.Emoji.list = function(){
|
||||
var list = emoji.slice(0);
|
||||
_.each(aliases, function(v,k){ list.push(k); });
|
||||
_.each(extendedEmoji, function(v,k){ list.push(k); });
|
||||
return list;
|
||||
};
|
||||
|
||||
var toSearch;
|
||||
|
||||
var search = function(term, options) {
|
||||
Discourse.Emoji.search = function(term, options) {
|
||||
var maxResults = (options && options["maxResults"]) || -1;
|
||||
|
||||
toSearch = toSearch || emoji.concat(Object.keys(extendedEmoji));
|
||||
|
||||
if (maxResults === 0) { return []; }
|
||||
|
||||
toSearch = toSearch || Discourse.Emoji.list();
|
||||
|
||||
var i, results = [];
|
||||
|
||||
var done = function() {
|
||||
|
@ -51,12 +52,17 @@ var search = function(term, options) {
|
|||
return results;
|
||||
}
|
||||
|
||||
Discourse.Emoji.search = search;
|
||||
|
||||
var emojiHash = {};
|
||||
// add all default emojis
|
||||
emoji.forEach(function(code){ emojiHash[code] = true; });
|
||||
// and their aliases
|
||||
for (var name in aliases) {
|
||||
aliases[name].forEach(function(alias) {
|
||||
emojiHash[alias] = true;
|
||||
});
|
||||
}
|
||||
|
||||
var urlFor = function(code) {
|
||||
Discourse.Emoji.urlFor = urlFor = function(code) {
|
||||
var url, set = Discourse.SiteSettings.emoji_set;
|
||||
|
||||
code = code.toLowerCase();
|
||||
|
@ -66,6 +72,7 @@ var urlFor = function(code) {
|
|||
}
|
||||
|
||||
if(!url && emojiHash.hasOwnProperty(code)) {
|
||||
if (aliases.hasOwnProperty(code)) { code = aliases[code]; }
|
||||
url = Discourse.getURL('/images/emoji/' + set + '/' + code + '.png');
|
||||
}
|
||||
|
||||
|
@ -80,8 +87,6 @@ var urlFor = function(code) {
|
|||
return url;
|
||||
}
|
||||
|
||||
Discourse.Emoji.urlFor = urlFor;
|
||||
|
||||
Discourse.Emoji.exists = function(code){
|
||||
code = code.toLowerCase();
|
||||
return !!(extendedEmoji.hasOwnProperty(code) || emojiHash.hasOwnProperty(code));
|
||||
|
@ -98,27 +103,27 @@ function imageFor(code) {
|
|||
// Also support default emotions
|
||||
var translations = {
|
||||
':)' : 'smile',
|
||||
':-)' : 'smile',
|
||||
':-)' : 'smile',
|
||||
':(' : 'frowning',
|
||||
':-(' : 'frowning',
|
||||
':-(' : 'frowning',
|
||||
';)' : 'wink',
|
||||
';-)' : 'wink',
|
||||
';-)' : 'wink',
|
||||
':\'(' : 'cry',
|
||||
':\'-(' : 'cry',
|
||||
':-\'(' : 'cry',
|
||||
':\'-(': 'cry',
|
||||
':-\'(': 'cry',
|
||||
':p' : 'stuck_out_tongue',
|
||||
':P' : 'stuck_out_tongue',
|
||||
':-P' : 'stuck_out_tongue',
|
||||
':-P' : 'stuck_out_tongue',
|
||||
':O' : 'open_mouth',
|
||||
':-O' : 'open_mouth',
|
||||
':-O' : 'open_mouth',
|
||||
':D' : 'smiley',
|
||||
':-D' : 'smiley',
|
||||
':-D' : 'smiley',
|
||||
':|' : 'expressionless',
|
||||
':-|' : 'expressionless',
|
||||
':-|' : 'expressionless',
|
||||
";P" : 'stuck_out_tongue_winking_eye',
|
||||
";-P" : 'stuck_out_tongue_winking_eye',
|
||||
";-P" : 'stuck_out_tongue_winking_eye',
|
||||
":$" : 'blush',
|
||||
":-$" : 'blush'
|
||||
":-$" : 'blush'
|
||||
};
|
||||
|
||||
Discourse.Emoji.translations = translations;
|
||||
|
|
|
@ -27,6 +27,10 @@ class Emoji
|
|||
Discourse.cache.fetch("standard_emojis") { load_standard }
|
||||
end
|
||||
|
||||
def self.aliases
|
||||
Discourse.cache.fetch("aliases_emojis") { load_aliases }
|
||||
end
|
||||
|
||||
def self.custom
|
||||
Discourse.cache.fetch("custom_emojis") { load_custom }
|
||||
end
|
||||
|
@ -74,6 +78,7 @@ class Emoji
|
|||
def self.clear_cache
|
||||
Discourse.cache.delete("custom_emojis")
|
||||
Discourse.cache.delete("standard_emojis")
|
||||
Discourse.cache.delete("aliases_emojis")
|
||||
Discourse.cache.delete("all_emojis")
|
||||
end
|
||||
|
||||
|
@ -81,9 +86,21 @@ class Emoji
|
|||
"#{Rails.root}/lib/emoji/db.json"
|
||||
end
|
||||
|
||||
def self.db
|
||||
@db ||= File.open(db_file, "r:UTF-8") { |f| JSON.parse(f.read) }
|
||||
end
|
||||
|
||||
def self.load_standard
|
||||
File.open(db_file, "r:UTF-8") { |f| JSON.parse(f.read) }
|
||||
.map { |emoji| Emoji.create_from_db_item(emoji) }
|
||||
db.map { |emoji| Emoji.create_from_db_item(emoji) }
|
||||
end
|
||||
|
||||
def self.load_aliases
|
||||
aliases = {}
|
||||
|
||||
db.select { |emoji| emoji["aliases"].count > 1 }
|
||||
.each { |emoji| aliases[emoji["aliases"][0]] = emoji["aliases"][1..-1] }
|
||||
|
||||
aliases
|
||||
end
|
||||
|
||||
def self.load_custom
|
||||
|
|
Loading…
Reference in New Issue