Last active
August 29, 2015 14:16
-
-
Save devdays/f5cd2947e3a60eef0f1c to your computer and use it in GitHub Desktop.
Sample code to user filter input from jQuery UI Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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