Skip to content

Instantly share code, notes, and snippets.

@clindsey
Forked from lainebrain/konami.jquery.plugin.js
Created July 22, 2010 21:55
Show Gist options
  • Save clindsey/486663 to your computer and use it in GitHub Desktop.
Save clindsey/486663 to your computer and use it in GitHub Desktop.
/*
Example Use;
$(document).ready(function(){
$(document).konami({ callback: function(){
//do something funny here! hehe
}});
});
*/
// up, up, down, down, left, right, left, right, B, A
(function($){
$.fn.konami = function(raw_settings){
var settings = {callback: function(){ alert("konami"); }};
if(raw_settings) $.extend(settings, raw_settings);
return this.each(function(){
var string = "38,38,40,40,37,39,37,39,66,65";
var keys = [];
$(window).bind("keydown", function(e){
keys.push(e.keyCode);
if (keys.toString().indexOf(string) >= 0 ) {
$(this).unbind("keydown");
settings.callback.apply();
}
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment