-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathk.js
More file actions
executable file
·50 lines (36 loc) · 762 Bytes
/
k.js
File metadata and controls
executable file
·50 lines (36 loc) · 762 Bytes
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
49
50
/*
Javascript by @dan_bentley
*/
(function() {
var opts = {};
$.fn.k = function(args, callback) {
var defaults = {
code: [84, 69, 83, 84], // test
currentKey: 0,
debug: false
}
opts = $.extend(defaults, args);
// add key listener
$(this).keyup(function(e) {
success = checkCode(e);
if (success) {
callback();
}
});
};
function checkCode(e) {
var keyPressed = e.keyCode;
if (keyPressed == opts.code[opts.currentKey]) {
opts.currentKey++;
if (opts.debug) console.log('match');
} else {
opts.currentKey = 0;
if (opts.debug) console.log('fail');
}
if (opts.currentKey == opts.code.length) {
if (opts.debug) console.log('code matched')
return true;
}
return false;
};
})(jQuery);