1
0
Fork 0
forked from 0x2620/oxjs

several improvements to autocomplete

This commit is contained in:
rolux 2011-05-20 13:46:52 +02:00
commit d1477a057a
3 changed files with 33 additions and 17 deletions

View file

@ -270,7 +270,7 @@ Ox.Input = function(options, self) {
function autocomplete(oldValue, oldCursor) {
oldValue = Ox.isUndefined(oldValue) ? self.options.value : oldValue;
oldCursor = Ox.isUndefined(oldCursor) ? cursor : oldCursor;
oldCursor = Ox.isUndefined(oldCursor) ? cursor() : oldCursor;
Ox.print('autocomplete', oldValue, oldCursor)
@ -290,7 +290,12 @@ Ox.Input = function(options, self) {
}
}
if (!self.options.value) {
self.options.autocompleteSelect && self.$autocompleteMenu.hideMenu();
if (self.options.autocompleteSelect) {
self.$autocompleteMenu
.unbindEvent('select')
.hideMenu();
self.selectEventBound = false;
}
}
function autocompleteFunction() {
@ -328,6 +333,7 @@ Ox.Input = function(options, self) {
//Ox.print('selectEnd', selectEnd)
if (self.options.autocompleteReplace) {
value = self.options.value;
self.options.value = newValue;
self.$input.val(self.options.value);
if (selectEnd) {
@ -341,7 +347,7 @@ Ox.Input = function(options, self) {
}
if (self.options.autocompleteSelect) {
value = self.options.value.toLowerCase();
value = (self.options.autocompleteReplace ? value : self.options.value).toLowerCase();
if (values.length) {
self.oldCursor = cursor();
self.oldValue = self.options.value;
@ -364,11 +370,20 @@ Ox.Input = function(options, self) {
return ret;
})
});
if (!self.selectEventBound) {
self.$autocompleteMenu.bindEvent({
select: selectMenu,
});
self.selectEventBound = true;
}
self.$autocompleteMenu.options({
selected: selected
}).showMenu();
} else {
self.$autocompleteMenu.hideMenu();
self.$autocompleteMenu
.unbindEvent('select')
.hideMenu();
self.selectEventBound = false;
}
}
@ -394,12 +409,6 @@ Ox.Input = function(options, self) {
.bindEvent({
click: clickMenu
});
if (self.options.autocompleteReplace) {
menu.bindEvent({
deselect: deselectMenu,
select: selectMenu,
});
}
return menu;
}
@ -605,6 +614,8 @@ Ox.Input = function(options, self) {
}
function deselectMenu() {
return;
Ox.print('deselectMenu')
self.options.value = self.oldValue;
self.$input.val(self.options.value);
cursor(self.oldCursor);
@ -685,10 +696,12 @@ Ox.Input = function(options, self) {
function selectMenu(event, data) {
var pos = cursor();
//Ox.print('selectMenu', pos)
self.options.value = data.title
self.$input.val(self.options.value);
cursor(pos[0], self.options.value.length)
//if (self.options.value) {
Ox.print('selectMenu', pos, data.title)
self.options.value = data.title
self.$input.val(self.options.value);
cursor(pos[0], self.options.value.length);
//}
}
function setPlaceholder() {