mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:09:00 +08:00
FIX: Emoji aliases not autocompleted
This commit is contained in:
parent
775c6d7a65
commit
7942b28780
|
@ -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');
|
||||
|
|
10
test/javascripts/lib/emoji-test.js.es6
Normal file
10
test/javascripts/lib/emoji-test.js.es6
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
module('emoji');
|
||||
|
||||
test("Emoji.search", function(){
|
||||
|
||||
// able to find an alias
|
||||
equal(Discourse.Emoji.search("coll").length, 1);
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user