I posted this before, but i think i replied to the wrong thing,
whoops!
anyway, How about making it a jquery plugin? :)
[code]
$.konamiCode = function (toExecute){
var press = 0, keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65,
13];
$(document).keydown(function (e){
if (e.which == keys[press]) {
press++;
} else {
press = 0;
}
if (press == keys.length) {
toExecute;
}
});
}
[/code]
Usage demo:
[code]
$.konamiCode(function() {alert('yay');});
[/code]
On Nov 17, 7:03 am, Ash <[email protected]> wrote:
> Every body loves a little treat in their websites...
>
> Well I believe jQuery holds the PERFECT javascript library for doing
> the Konami Code. A fan of Konami, and having such a cool little hidden
> feature to your websites, I decided i'd share my code with the world,
> or at least
> those people who'd like it..
>
> Just like the PHP logo change, creativity with this little beauty will
> keep your mind going for ever ;)
>
> [code]
> $(function (){
> var press = 0, keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
>
> $(document).keydown(function (e){
> if (e.which == keys[press])
> press++;
> else
> press = 0;
>
> if (press == keys.length)
> (function (){
> // your little treat...
> });
> });});
>
> [/code]