Created
November 30, 2012 15:44
-
-
Save yckart/4176523 to your computer and use it in GitHub Desktop.
Letter konami-code [jQuery Plugin]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved to repo: https://github.com/yckart/jquery.konami.js