-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.inputChange.js
44 lines (44 loc) · 1.46 KB
/
jquery.inputChange.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 inputChange plugin by Otar Chekurishvili
(function($)
{
$.extend($.fn, {
inputChange: function(callback, options)
{
options = $.extend({
delay: 500,
valueChange: true,
fallbackMessage: true
}, options);
if (!$.isFunction(callback))
{
if (options.fallbackMessage === true)
{
console.log('inputChange: provided callback was not a function, silently falling back...');
}
return this;
}
this.each(function()
{
var $this = $(this);
$this.
data('inputChangeValue', $this.val()).
data('inputChangeTimer', null).
on('keyup', function()
{
if (options.valueChange === true && $this.val() == $this.data('inputChangeValue'))
{
return;
}
$this.data('inputChangeValue', $this.val());
clearTimeout($this.data('inputChangeTimer'));
var scope = this;
$this.data('inputChangeTimer', setTimeout(function()
{
callback.call(scope);
}, options.delay));
});
});
return this;
}
});
})(jQuery);