FIX: Emoji aliases not autocompleted

This commit is contained in:
Sam Saffron 2015-06-01 12:33:42 +10:00
parent 775c6d7a65
commit 7942b28780
2 changed files with 43 additions and 32 deletions

View File

@ -18,38 +18,6 @@ Discourse.Emoji.list = function(){
return list;
};
var toSearch;
Discourse.Emoji.search = function(term, options) {
var maxResults = (options && options["maxResults"]) || -1;
if (maxResults === 0) { return []; }
toSearch = toSearch || Discourse.Emoji.list();
var i, results = [];
var done = function() {
return maxResults > 0 && results.length >= maxResults;
}
for (i=0; i < toSearch.length; i++) {
if (toSearch[i].indexOf(term) === 0) {
results.push(toSearch[i]);
if(done()) { break; }
}
}
if(!done()){
for (i=0; i < toSearch.length; i++) {
if (toSearch[i].indexOf(term) > 0) {
results.push(toSearch[i]);
if(done()) { break; }
}
}
}
return results;
}
var emojiHash = {};
// add all default emojis
@ -192,4 +160,37 @@ Discourse.Dialect.registerInline(':', function(text, match, prev) {
}
});
var toSearch;
Discourse.Emoji.search = function(term, options) {
var maxResults = (options && options["maxResults"]) || -1;
if (maxResults === 0) { return []; }
toSearch = toSearch || _.keys(emojiHash);
var i, results = [];
var done = function() {
return maxResults > 0 && results.length >= maxResults;
}
for (i=0; i < toSearch.length; i++) {
if (toSearch[i].indexOf(term) === 0) {
results.push(toSearch[i]);
if(done()) { break; }
}
}
if(!done()){
for (i=0; i < toSearch.length; i++) {
if (toSearch[i].indexOf(term) > 0) {
results.push(toSearch[i]);
if(done()) { break; }
}
}
}
return results;
}
Discourse.Markdown.whiteListTag('img', 'class', 'emoji');

View File

@ -0,0 +1,10 @@
module('emoji');
test("Emoji.search", function(){
// able to find an alias
equal(Discourse.Emoji.search("coll").length, 1);
});