Commit 1e3f4abb authored by Luís Rudge's avatar Luís Rudge

trying some async stuff

parent 32549864
This diff is collapsed.
...@@ -58,6 +58,12 @@ ...@@ -58,6 +58,12 @@
}; };
this.query = ''; this.query = '';
this.searchTimeout = null; this.searchTimeout = null;
this.asyncFunction = function (callback, timeout, self) {
var args = Array.prototype.slice.call(arguments, 3);
return setTimeout(function () {
callback.apply(self || window, args);
}, timeout);
};
this.options.multiple = this.$select.attr('multiple') == "multiple"; this.options.multiple = this.$select.attr('multiple') == "multiple";
...@@ -72,21 +78,23 @@ ...@@ -72,21 +78,23 @@
}).keydown($.proxy(function (event) { }).keydown($.proxy(function (event) {
// This is useful to catch "keydown" events after the browser has updated the control // This is useful to catch "keydown" events after the browser has updated the control
clearTimeout(this.searchTimeout); clearTimeout(this.searchTimeout);
this.searchTimeout = setTimeout($.proxy(function () { this.searchTimeout = this.asyncFunction($.proxy(function () {
var inputValue = event.target.value; var inputValue = event.target.value;
if (inputValue != this.query) { if (inputValue != this.query) {
this.query = inputValue; this.query = inputValue;
this.$select.empty(); this.$select.empty();
var filteredValues = this.getFilteredOptions(); var filteredValues = this.getFilteredOptions();
var newOptions = '';
for (var i = 0; i < filteredValues.length; i++) { for (var i = 0; i < filteredValues.length; i++) {
var option = filteredValues[i]; var option = filteredValues[i];
this.$select.append($('<option></option>').attr('value', option.value).text(option.text)); newOptions += '<option value="'+option.value+'">'+option.text+'</option>';
} }
console.log(newOptions);
this.$select.html(newOptions);
this.rebuild(); this.rebuild();
} }
}, this), 300); }, this), 300, this);
}, this)); }, this));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment