Add user name completion in the textarea

This commit is contained in:
Naoki Takezoe
2016-07-09 11:47:41 +09:00
parent 135c34ef0f
commit 458820a09d

View File

@@ -9,6 +9,9 @@
<script>
$(function(){
var emojis = @Html(gitbucket.core.util.EmojiUtil.emojis.map("\"" + _ + "\"").mkString("[", ", ", "]"));
var users = [];
$.get('@path/_user/proposals', { query: '' }, function (data) { users = data.options; });
$('#@textareaId').textcomplete([
{ // emoji strategy
@@ -26,21 +29,21 @@ $(function(){
return ':' + value + ': ';
},
index: 1
}//,
// { // tech companies
// id: 'tech-companies',
// words: ['apple', 'google', 'facebook', 'github'],
// match: /\b(\w{2,})$/,
// search: function (term, callback) {
// callback($.map(this.words, function (word) {
// return word.indexOf(term) === 0 ? word : null;
// }));
// },
// index: 1,
// replace: function (word) {
// return word + ' ';
// }
// }
},
{ // users
id: 'user',
//words: users,
match: /\B@@([\-+\w]*)$/,
search: function (term, callback) {
callback($.map(users, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
index: 1,
replace: function (word) {
return '@@' + word + ' ';
}
}
], {
onKeydown: function (e, commands) {
if (e.ctrlKey && e.keyCode === 74) { // CTRL-J