user-mention.js 1.21 KB
(function($, undefined) {
  $(document).ready(function() {
    var is_community = _.isEmpty($('html.profile-type-is-community')) !== true;
    var community = null;

    if (is_community) {
      community = noosfero.profile;
    }

    $('#comment_body, #leave_scrap_content, form.profile-wall-reply-form textarea').mentionsInput({
      onDataRequest: function (mode, keyword, onDataRequestCompleteCallback) {
        var search_url = "/search/search_for_friends_and_members?q="+keyword;

        $.ajax({
          method: "GET",
          url: search_url,
          dataType: "json",
          data: {'community': community},
          success: function (response) {
            var data = response.map(function(item) {
              return {
                name: item.identifier,
                fullName: item.name,
                id: item.id,
                type: 'contact'
              };
            });

            // Call this to populate mention.
            onDataRequestCompleteCallback.call(this, data);
          }
        }); // $.ajax end
      },

      triggerChar: '@',

      allowRepeat: true,

      minChars: 3,

      keepTriggerCharacter: true
    }); // mentionsInput end
  }); // ready end

}) (jQuery);