move autocomplete highlighting to callback

This commit is contained in:
Rolux 2010-02-20 16:13:45 +05:30
parent 977bc51beb
commit 17321a24a8

View file

@ -1745,19 +1745,12 @@ requires
});
function autocomplete(value, callback) {
value = value.toLowerCase();
var items = [];
if (value === "") {
// items = self.options.autocomplete[self.placeholder];
} else {
$.each(self.options.autocomplete[self.label || self.placeholder], function(i, item) {
if (item.toLowerCase().indexOf(value) > -1) {
if (self.options.highlight) {
item = item.replace(
new RegExp("(" + value + ")", "ig"),
"<span class=\"OxHighlight\">$1</span>"
);
}
items.push(item);
}
});
@ -1766,7 +1759,7 @@ requires
}
function call() {
var value = that.$input.val();
var value = that.$input.val().toLowerCase();
if (self.options.autocomplete) {
Ox.isFunction(self.options.autocomplete) ?
self.options.autocomplete(value, callback) :
@ -1775,7 +1768,8 @@ requires
}
function callback(items) {
var selected = items.length == 1 ? 0 : -1;
var selected = items.length == 1 ? 0 : -1,
value = that.$input.val().toLowerCase();
if (items.length) {
items = $.map(items, function(title, position) {
if (that.$input.val().toLowerCase() == Ox.stripTags(title.toLowerCase())) {
@ -1783,7 +1777,10 @@ requires
}
return {
id: title.toLowerCase(), // fixme: need function to do lowercase, underscores etc?
title: title
title: self.options.highlight ? title.replace(
new RegExp("(" + value + ")", "ig"),
"<span class=\"OxHighlight\">$1</span>"
) : title
};
});
self.selectMenu.hideMenu();