summaryrefslogtreecommitdiffstats
path: root/client/components/main/rendered.js
blob: 787e8225ed975827b7fb958dabad251f5ccad822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Template.editor.rendered = function() {
  this.$('textarea').textcomplete([
    // Emojies
    {
      match: /\B:([\-+\w]*)$/,
      search: function(term, callback) {
        callback($.map(Emoji.values, function(emoji) {
          return emoji.indexOf(term) === 0 ? emoji : null;
        }));
      },
      template: function(value) {
        var image = '<img src="' + Emoji.baseImagePath + value + '.png"></img>';
        return image + value;
      },
      replace: function(value) {
        return ':' + value + ':';
      },
      index: 1
    },

    // User mentions
    {
      match: /\B@(\w*)$/,
      search: function(term, callback) {
        var currentBoard = Boards.findOne(Session.get('currentBoard'));
        callback($.map(currentBoard.members, function(member) {
          var username = Users.findOne(member.userId).username;
          return username.indexOf(term) === 0 ? username : null;
        }));
      },
      template: function(value) {
        return value;
      },
      replace: function(username) {
        return '@' + username + ' ';
      },
      index: 1
    }
  ]);
};