Skip to content

Instantly share code, notes, and snippets.

@sunny
Created November 9, 2010 16:29
Show Gist options
  • Save sunny/669331 to your computer and use it in GitHub Desktop.
Save sunny/669331 to your computer and use it in GitHub Desktop.
/**
* jQuery Konami event plugin
* Called after the ↑ ↑ ↓ ↓ ← → ← → B A keyboard sequence is completed.
* by Sunny Ripert <http://sunfox.org>, under the WTFPL <http://sam.zoy.org/wtfpl/>
*
* Example:
* $(window).konami(function() {
* alert('Konami!')
* })
**/
$.fn.konami = function(callback) {
var keys = [], sequence = /38,38,40,40,37,39,37,39,66,65$/
$(this).bind('keydown.konami', function(e) {
keys.push(e.keyCode);
if (keys.toString().match(sequence))
callback(e);
}, true);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment