Skip to content

Instantly share code, notes, and snippets.

@yckart
Created November 30, 2012 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yckart/4176523 to your computer and use it in GitHub Desktop.
Save yckart/4176523 to your computer and use it in GitHub Desktop.
Letter konami-code [jQuery Plugin]
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');
@yckart
Copy link
Author

yckart commented Nov 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment