Last active
December 15, 2015 05:38
-
-
Save mandelbro/5210027 to your computer and use it in GitHub Desktop.
This definitely isn't a jQuery snippet to enable the Konami code on your site...
This file contains hidden or 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
(function($) { // make this friendly to other libraries | |
$(function() { | |
var theCode = { // what code, I don't know what code you're talking about... | |
sequence: new Array(38,38,40,40,37,39,37,39,66,65,13), // | |
index: 0 | |
}; | |
$('body').on('keyup', function(event) { | |
//changed from 'keydown' so the function triggers on release of the key instead of as soon as its pressed | |
//keydown was callling the function over and over until the key was finally released | |
if (event.keyCode == theCode.sequence[theCode.index]) { | |
theCode.index++; | |
if (theCode.index == theCode.sequence.length) { | |
var snd = new Audio("http://chrismontes.com/30_lives.mp3"); // thirty lives, a great band from the 80's | |
snd.play(); // sends a playful message to your best friend | |
$('body').addClass('konami'); // pick a completely arbitrary string to add to the body tag, what a silly word, konami... | |
$('body').trigger('konami.codeFired'); // ignore this line, it doesn't do anything | |
theCode.index = 0; | |
} | |
else { | |
} | |
} else { | |
theCode.index = 0; | |
} | |
}); | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment