mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 10:58:54 +08:00
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"
|
Discourse.Emoji.ImageVersion = "0"
|
||||||
|
|
||||||
var emoji = <%= Emoji.standard.map(&:name).flatten.inspect %>;
|
var emoji = <%= Emoji.standard.map(&:name).flatten.inspect %>;
|
||||||
|
var aliases = <%= Emoji.aliases.inspect.gsub("=>", ":") %>;
|
||||||
|
|
||||||
var extendedEmoji = {};
|
var extendedEmoji = {};
|
||||||
Discourse.Dialect.registerEmoji = function(code, url) {
|
Discourse.Dialect.registerEmoji = function(code, url) {
|
||||||
@ -13,19 +14,19 @@ Discourse.Dialect.registerEmoji = function(code, url) {
|
|||||||
|
|
||||||
Discourse.Emoji.list = function(){
|
Discourse.Emoji.list = function(){
|
||||||
var list = emoji.slice(0);
|
var list = emoji.slice(0);
|
||||||
|
_.each(aliases, function(v,k){ list.push(k); });
|
||||||
_.each(extendedEmoji, function(v,k){ list.push(k); });
|
_.each(extendedEmoji, function(v,k){ list.push(k); });
|
||||||
return list;
|
return list;
|
||||||
};
|
};
|
||||||
|
|
||||||
var toSearch;
|
var toSearch;
|
||||||
|
|
||||||
var search = function(term, options) {
|
Discourse.Emoji.search = function(term, options) {
|
||||||
var maxResults = (options && options["maxResults"]) || -1;
|
var maxResults = (options && options["maxResults"]) || -1;
|
||||||
|
|
||||||
toSearch = toSearch || emoji.concat(Object.keys(extendedEmoji));
|
|
||||||
|
|
||||||
if (maxResults === 0) { return []; }
|
if (maxResults === 0) { return []; }
|
||||||
|
|
||||||
|
toSearch = toSearch || Discourse.Emoji.list();
|
||||||
|
|
||||||
var i, results = [];
|
var i, results = [];
|
||||||
|
|
||||||
var done = function() {
|
var done = function() {
|
||||||
@ -51,12 +52,17 @@ var search = function(term, options) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
Discourse.Emoji.search = search;
|
|
||||||
|
|
||||||
var emojiHash = {};
|
var emojiHash = {};
|
||||||
|
// add all default emojis
|
||||||
emoji.forEach(function(code){ emojiHash[code] = true; });
|
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;
|
var url, set = Discourse.SiteSettings.emoji_set;
|
||||||
|
|
||||||
code = code.toLowerCase();
|
code = code.toLowerCase();
|
||||||
@ -66,6 +72,7 @@ var urlFor = function(code) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!url && emojiHash.hasOwnProperty(code)) {
|
if(!url && emojiHash.hasOwnProperty(code)) {
|
||||||
|
if (aliases.hasOwnProperty(code)) { code = aliases[code]; }
|
||||||
url = Discourse.getURL('/images/emoji/' + set + '/' + code + '.png');
|
url = Discourse.getURL('/images/emoji/' + set + '/' + code + '.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +87,6 @@ var urlFor = function(code) {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
Discourse.Emoji.urlFor = urlFor;
|
|
||||||
|
|
||||||
Discourse.Emoji.exists = function(code){
|
Discourse.Emoji.exists = function(code){
|
||||||
code = code.toLowerCase();
|
code = code.toLowerCase();
|
||||||
return !!(extendedEmoji.hasOwnProperty(code) || emojiHash.hasOwnProperty(code));
|
return !!(extendedEmoji.hasOwnProperty(code) || emojiHash.hasOwnProperty(code));
|
||||||
@ -98,27 +103,27 @@ function imageFor(code) {
|
|||||||
// Also support default emotions
|
// Also support default emotions
|
||||||
var translations = {
|
var translations = {
|
||||||
':)' : 'smile',
|
':)' : 'smile',
|
||||||
':-)' : 'smile',
|
':-)' : 'smile',
|
||||||
':(' : 'frowning',
|
':(' : 'frowning',
|
||||||
':-(' : 'frowning',
|
':-(' : 'frowning',
|
||||||
';)' : 'wink',
|
';)' : 'wink',
|
||||||
';-)' : 'wink',
|
';-)' : 'wink',
|
||||||
':\'(' : 'cry',
|
':\'(' : 'cry',
|
||||||
':\'-(' : 'cry',
|
':\'-(': 'cry',
|
||||||
':-\'(' : 'cry',
|
':-\'(': 'cry',
|
||||||
':p' : 'stuck_out_tongue',
|
':p' : 'stuck_out_tongue',
|
||||||
':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',
|
':-O' : 'open_mouth',
|
||||||
':D' : 'smiley',
|
':D' : 'smiley',
|
||||||
':-D' : 'smiley',
|
':-D' : 'smiley',
|
||||||
':|' : 'expressionless',
|
':|' : 'expressionless',
|
||||||
':-|' : 'expressionless',
|
':-|' : 'expressionless',
|
||||||
";P" : 'stuck_out_tongue_winking_eye',
|
";P" : 'stuck_out_tongue_winking_eye',
|
||||||
";-P" : 'stuck_out_tongue_winking_eye',
|
";-P" : 'stuck_out_tongue_winking_eye',
|
||||||
":$" : 'blush',
|
":$" : 'blush',
|
||||||
":-$" : 'blush'
|
":-$" : 'blush'
|
||||||
};
|
};
|
||||||
|
|
||||||
Discourse.Emoji.translations = translations;
|
Discourse.Emoji.translations = translations;
|
||||||
|
@ -27,6 +27,10 @@ class Emoji
|
|||||||
Discourse.cache.fetch("standard_emojis") { load_standard }
|
Discourse.cache.fetch("standard_emojis") { load_standard }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.aliases
|
||||||
|
Discourse.cache.fetch("aliases_emojis") { load_aliases }
|
||||||
|
end
|
||||||
|
|
||||||
def self.custom
|
def self.custom
|
||||||
Discourse.cache.fetch("custom_emojis") { load_custom }
|
Discourse.cache.fetch("custom_emojis") { load_custom }
|
||||||
end
|
end
|
||||||
@ -74,6 +78,7 @@ class Emoji
|
|||||||
def self.clear_cache
|
def self.clear_cache
|
||||||
Discourse.cache.delete("custom_emojis")
|
Discourse.cache.delete("custom_emojis")
|
||||||
Discourse.cache.delete("standard_emojis")
|
Discourse.cache.delete("standard_emojis")
|
||||||
|
Discourse.cache.delete("aliases_emojis")
|
||||||
Discourse.cache.delete("all_emojis")
|
Discourse.cache.delete("all_emojis")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -81,9 +86,21 @@ class Emoji
|
|||||||
"#{Rails.root}/lib/emoji/db.json"
|
"#{Rails.root}/lib/emoji/db.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.db
|
||||||
|
@db ||= File.open(db_file, "r:UTF-8") { |f| JSON.parse(f.read) }
|
||||||
|
end
|
||||||
|
|
||||||
def self.load_standard
|
def self.load_standard
|
||||||
File.open(db_file, "r:UTF-8") { |f| JSON.parse(f.read) }
|
db.map { |emoji| Emoji.create_from_db_item(emoji) }
|
||||||
.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
|
end
|
||||||
|
|
||||||
def self.load_custom
|
def self.load_custom
|
||||||
|
Loading…
x
Reference in New Issue
Block a user