-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrowkeys.js
48 lines (39 loc) · 1.11 KB
/
arrowkeys.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
45
46
47
48
/**
* arrowkeys v0.2.0
*
* author: Yosiya Hinosawa
* license: MIT License
*/
(function (window, $) {
'use strict';
$.fn.arrowkeys = function () {
var that = this;
this._arrowkeysHandler = function (event) {
switch (event.keyCode) {
case 37:
event.preventDefault();
that.trigger('leftkey');
break;
case 38:
event.preventDefault();
that.trigger('upkey');
break;
case 39:
event.preventDefault();
that.trigger('rightkey');
break;
case 40:
event.preventDefault();
that.trigger('downkey');
break;
}
};
this.on('keydown', this._arrowkeysHandler);
return this;
};
$.fn.arrowkeysUnbind = function () {
this.off('keydown', this._arrowkeysHandler);
delete this._arrowkeysHandler;
return this;
};
}(window, window.$));