1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 08:53:14 +00:00

Add basic autocomplete for @

This commit is contained in:
xiez
2012-08-19 13:36:32 +08:00
parent afb29917bf
commit 12b63f3e7a
5 changed files with 76 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
//add op confirm dialog
var Op_url = '';
function addConfirmTo(ele, confirm_con) {
@@ -73,6 +75,53 @@ function addAutocomplete(ele_id, container_id, data) {
});
}
/*
* func: add autocomplete for `@` to some input ele
* @param ele_id: autocomplete is added to this ele(ment), e.g-'#xxx'
* @param container_id: id of autocomplete's container, often container of element above
* @param data: tip data in array, e.g- ['xx', 'yy']
*/
function addAtAutocomplete(ele_id, container_id, data) {
function split(val) {
return val.split(/\ \s*/);
}
function extractLast(term) {
return split(term).pop();
}
$(ele_id)
.bind("keydown", function(event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active) {
event.preventDefault();
}
})
.autocomplete({
appendTo: container_id,
autoFocus: true,
delay: 100,
minLength: 0,
source: function(request, response) {
var lastTerm = extractLast(request.term);
var lastIndex = lastTerm.lastIndexOf('@');
if (lastIndex >= 0) {
response($.ui.autocomplete.filter(data, lastTerm.substring(lastIndex+1)));
}
},
focus: function() {
return false;
},
select: function(event, ui) {
var terms = split(this.value);
var popTerm = terms.pop();
terms.push(popTerm.concat(ui.item.value));
terms.push("");
this.value = terms.join(" ");
return false;
}
});
}
function filesizeformat(bytes, precision)
{
var kilobyte = 1024;