2014-12-08 09:51:13 +08:00
|
|
|
|
|
|
|
// TODO: Make this a proper ES6 import
|
|
|
|
var ComposerView = require('discourse/views/composer').default;
|
2014-12-12 00:08:47 +08:00
|
|
|
|
2014-12-08 09:51:13 +08:00
|
|
|
ComposerView.on("initWmdEditor", function(){
|
|
|
|
if (!Discourse.SiteSettings.enable_emoji) { return; }
|
|
|
|
|
2014-12-12 00:08:47 +08:00
|
|
|
var template = Handlebars.compile(
|
|
|
|
"<div class='autocomplete'>" +
|
|
|
|
"<ul>" +
|
|
|
|
"{{#each options}}" +
|
|
|
|
"<li>" +
|
|
|
|
"<a href='#'><img src='{{src}}' class='emoji'> {{code}}</a>" +
|
|
|
|
"</li>" +
|
|
|
|
"{{/each}}" +
|
|
|
|
"</ul>" +
|
|
|
|
"</div>"
|
|
|
|
);
|
2014-12-08 09:51:13 +08:00
|
|
|
|
|
|
|
$('#wmd-input').autocomplete({
|
|
|
|
template: template,
|
|
|
|
key: ":",
|
2014-12-12 00:08:47 +08:00
|
|
|
transformComplete: function(v){ return v.code + ":"; },
|
2014-12-08 09:51:13 +08:00
|
|
|
dataSource: function(term){
|
|
|
|
return new Ember.RSVP.Promise(function(resolve) {
|
|
|
|
var full = ":" + term;
|
|
|
|
term = term.toLowerCase();
|
|
|
|
|
|
|
|
if (term === "") {
|
|
|
|
return resolve(["smile", "smiley", "wink", "sunny", "blush"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Discourse.Emoji.translations[full]) {
|
|
|
|
return resolve([Discourse.Emoji.translations[full]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var options = Discourse.Emoji.search(term, {maxResults: 5});
|
|
|
|
|
|
|
|
return resolve(options);
|
|
|
|
}).then(function(list) {
|
|
|
|
return list.map(function(i) {
|
|
|
|
return {code: i, src: Discourse.Emoji.urlFor(i)};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|