From 17321a24a8ded3a7cc55e1819022fd51b9332cc9 Mon Sep 17 00:00:00 2001 From: Rolux Date: Sat, 20 Feb 2010 16:13:45 +0530 Subject: [PATCH] move autocomplete highlighting to callback --- build/js/ox.ui.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index d6c3d785..07999e87 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -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"), - "$1" - ); - } 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"), + "$1" + ) : title }; }); self.selectMenu.hideMenu();