-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.capturekeys-1.0.js
37 lines (37 loc) · 1.03 KB
/
jquery.capturekeys-1.0.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
/*!
* jQuery captureKeys 1.0
* http://www.karalamalar.net/
*
* Copyright (c) 2011 İzzet Emre Erkan
* Licensed under Creative Commons Attribution-Share Alike 3.0 Unported License
* http://creativecommons.org/licenses/by-sa/3.0/
*
*/
(function ($) {
var inputField,
documentKeydown = function (event) {
var target = event.target, tagName = target.tagName.toLowerCase();
if (target !== inputField.get(0)) {
if (tagName === 'input' || tagName === 'textarea') {
return true;
}
target = inputField.get(0);
inputField.focus();
}
};
$.fn.captureKeys = function () {
return this.each(function (i) {
if (i === 0) {
inputField = $(this);
$(document).bind('keydown', documentKeydown);
inputField
.focus(function () {
$(document).unbind('keydown');
})
.blur(function () {
$(document).bind('keydown', documentKeydown);
});
}
});
};
})(jQuery);