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

[@]make simpler

This commit is contained in:
llj
2012-08-28 14:47:17 +08:00
parent 9bd6c2b580
commit cac0727eaa

View File

@@ -92,7 +92,6 @@ function addAtAutocomplete(ele_id, container_id, data) {
}) })
.bind('keypress', function(e) { .bind('keypress', function(e) {
if (String.fromCharCode(e.keyCode || e.charCode) == '@') { if (String.fromCharCode(e.keyCode || e.charCode) == '@') {
//$(this).autocomplete( "option", "disabled", false);
pos = getCaretPos($(ele_id)[0]); // get cursor position pos = getCaretPos($(ele_id)[0]); // get cursor position
if (pos == $(this).val().length) { if (pos == $(this).val().length) {
cursor_at_end = true; cursor_at_end = true;
@@ -103,7 +102,6 @@ function addAtAutocomplete(ele_id, container_id, data) {
} }
}) })
.autocomplete({ .autocomplete({
//disabled:true,
appendTo: container_id, appendTo: container_id,
autoFocus: true, autoFocus: true,
delay: 100, delay: 100,
@@ -112,7 +110,7 @@ function addAtAutocomplete(ele_id, container_id, data) {
if (pos === '') { if (pos === '') {
return false; return false;
} }
if (getCaretPos($(ele_id)[0]) > pos) { // cursor is at the right of the current @ if ($(ele_id).val().charAt(pos) == '@' && getCaretPos($(ele_id)[0]) > pos) { // cursor is at the right of the current @
var request_term = ''; var request_term = '';
if (cursor_at_end) { if (cursor_at_end) {
request_term = request.term.substring(pos + 1); request_term = request.term.substring(pos + 1);
@@ -131,29 +129,12 @@ function addAtAutocomplete(ele_id, container_id, data) {
return false; return false;
}, },
select: function(event, ui) { select: function(event, ui) {
var str = $(this).val().substring(0, pos - 1), var str = $(this).val().substring(0, pos + 1) + ui.item.label + ' ';
add_space = false,
pos_set = pos + ui.item.label.length + 2;
if (pos == 0) {
str += $(this).val().charAt(pos - 1) + '@';
} else {
if ($(this).val().charAt(pos - 1) != ' ') {
str += $(this).val().charAt(pos - 1) + ' @';
add_space = true;
} else {
str += $(this).val().charAt(pos - 1) + '@';
}
}
str += ui.item.label + ' ';
if (cursor_at_end) { if (cursor_at_end) {
$(this).val(str); $(this).val(str);
} else { } else {
$(this).val(str + end_str); $(this).val(str + end_str);
if (add_space) { setCaretPos($(this)[0], pos + ui.item.label.length + 2);
pos_set += 1;
}
setCaretPos($(this)[0], pos_set);
} }
return false; return false;
} }