Created
May 14, 2009 23:04
-
-
Save choan/111977 to your computer and use it in GitHub Desktop.
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
| var EasternEggTrigger = function(sequence, callback) { | |
| var seqString = sequence.join(' '), | |
| seqLength = sequence.length, | |
| got = [], | |
| d = document, | |
| handler = function(e) { | |
| e = e || window.event; | |
| got.push(e.keyCode); | |
| if (got.join(' ').indexOf(seqString) !== -1) { | |
| got = []; | |
| callback(); | |
| } | |
| else if (got.length > seqLength) { | |
| got.shift(); | |
| } | |
| }; | |
| if (d.addEventListener) | |
| d.addEventListener('keydown', handler, false); | |
| else if (d.attachEvent) | |
| d.attachEvent('onkeydown', handler); | |
| }; | |
| EasternEggTrigger([ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65 ], function() { | |
| document.body.appendChild(document.createTextNode('yay!')); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment