-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.delayedsearch.js
44 lines (35 loc) · 1.15 KB
/
jquery.delayedsearch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
jquery.delayedsearch.js
Purpose: Adds functionality to an input box to delay a function call
for a set number of milliseconds after the user has stopped
typing.
Version: 1.0.0
Dependencies: jQuery 1.4.2+
Author: Rui Jiang
Email: [email protected]
Created: 3/28/2011
Last-modified: 4/24/2011
License: MIT license
*/
(function($) {
$.fn.extend({
delayedsearch: function(options) {
var settings = {
delay: 500,
call: function() {}
};
settings = $.extend(settings, options);
var $inputbox = $(this);
var timer = null;
$inputbox.keydown(function(event) {
// stop the last keydown from kicking off
if (timer !== null)
clearTimeout(timer);
timer = setTimeout(function() {
settings.call($inputbox.val());
}, settings.delay);
});
return this;
}
});
})(jQuery);