add username suggestions to editor

This commit is contained in:
jomo
2014-07-06 02:38:44 +02:00
parent 4079fe6a2c
commit 2b1e8acee3
7 changed files with 702 additions and 4 deletions

View File

@@ -52,4 +52,37 @@ $(function() {
});
}
var query_history = {};
$('.md_editor .editor_field').autocomplete({
wordCount: 1,
mode: "inner",
on: {
query: function(text, callback) {
console.log(query_history)
if (text.length > 2 && text[0] == "@") {
text = text.slice(1)
if (query_history[text]) {
callback(query_history[text]);
} else {
$.ajax("/users/suggestions", {
type: 'post',
data: {name: text},
dataType: 'json',
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
success: function(data) {
query_history[text] = data;
callback(data);
},
error: function(xhr, status, err) {
callback([]);
}
});
}
}
}
}
});
});