Skip to content

Instantly share code, notes, and snippets.

@choan
Created May 14, 2009 23:04
Show Gist options
  • Select an option

  • Save choan/111977 to your computer and use it in GitHub Desktop.

Select an option

Save choan/111977 to your computer and use it in GitHub Desktop.
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