Skip to content

Instantly share code, notes, and snippets.

@devdays
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/f5cd2947e3a60eef0f1c to your computer and use it in GitHub Desktop.
Save devdays/f5cd2947e3a60eef0f1c to your computer and use it in GitHub Desktop.
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