public
Last active

Letter konami-code [jQuery Plugin]

  • Download Gist
jquery.konami.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
jQuery.konami = function(fn, code) {
// ↑ ↑ ↓ ↓ ← → ← → B A
code = code || [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var i = 0;
 
$(document).keydown(function(e) {
var char = typeof code === 'string' ? String.fromCharCode(e.which).toLowerCase() : e.which;
i = char === code[i] ? i + 1 : 0;
if (i === code.length) {
fn();
i = 0;
}
});
};
 
$.konami(function() {
alert('Woohoo!');
});
 
$.konami(function() {
alert('Woohoo!');
}, 'foo');

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.