-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.keystop.js
40 lines (33 loc) · 1.03 KB
/
jquery.keystop.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
/*\
* jQuery keystop event plugin (https://github.com/tkazec/final--jquery-keystop)
* Triggers the "keystop" event once the user has ceased typing in an input
* for a specified period of time. Dedicated to the public domain.
*
* .keystop(handler, [delay]) or .on("keystop", [delay], handler) to bind.
* .keystop() or .trigger("keystop") to trigger.
* .off("keystop") to unbind.
\*/
(function ($) { "use strict";
$.event.special.keystop = {
add: function (details) {
var $el = $(this);
var ns = ".__" + details.guid;
var delay = details.data || 500;
var tID = -1;
details.namespace += ns;
$el.on("input" + ns + " propertychange" + ns, function () {
clearTimeout(tID);
tID = setTimeout(function () {
$el.trigger("keystop" + ns);
}, delay);
});
},
remove: function (details) {
var ns = ".__" + details.guid;
$(this).off("input" + ns + " propertychange" + ns);
}
};
$.fn.keystop = function (handler, delay) {
return handler ? this.on("keystop", delay, handler) : this.trigger("keystop");
};
})(jQuery);