From 178eda18872f99840937dc3d23629b5d7aa7cee0 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 29 Dec 2015 18:44:21 +0100 Subject: Add autocompletion in textarea for user mentions --- assets/js/src/Dropdown.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'assets/js/src') diff --git a/assets/js/src/Dropdown.js b/assets/js/src/Dropdown.js index 20fca8a7..81ce2509 100644 --- a/assets/js/src/Dropdown.js +++ b/assets/js/src/Dropdown.js @@ -40,6 +40,21 @@ Dropdown.prototype.listen = function() { $(this).find('a:visible')[0].click(); // Calling native click() not the jQuery one } }); + + // User mention autocomplete + $('textarea[data-mention-search-url]').textcomplete([{ + match: /(^|\s)@(\w*)$/, + search: function (term, callback) { + var url = $('textarea[data-mention-search-url]').data('mention-search-url'); + $.getJSON(url, { q: term }) + .done(function (resp) { callback(resp); }) + .fail(function () { callback([]); }); + }, + replace: function (value) { + return '$1@' + value + ' '; + }, + cache: true + }], {className: "textarea-dropdown"}); }; Dropdown.prototype.close = function() { -- cgit v1.2.3