Skip to content

Instantly share code, notes, and snippets.

@devdays
Last active Aug 29, 2015
Embed
What would you like to do?
Sample code to user filter input from jQuery UI Widget
filter: function (event) {
// Debounce the keyup event with a timeout, using the specified delay
clearTimeout(this.timeout);
// like setTimeout, only better!
this.timeout = this._delay(function () {
var re = new RegExp(this.filterInput.val(), "i"),
visible = this.filterElems.filter(function () {
var $t = $(this), matches = re.test($t.text());
// Leverage the CSS Framework to handle visual state changes
$t.toggleClass("ui-helper-hidden", !matches);
return matches;
});
// Trigger a callback so the user can respond to filtering being complete
// Supply an object of useful parameters with the second argument to _trigger
this._trigger("filtered", event, {
visible: visible
});
}, this.options.delay);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment