Skip to content

Instantly share code, notes, and snippets.

@RobinHerbots
Created October 25, 2011 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinHerbots/1312012 to your computer and use it in GitHub Desktop.
Save RobinHerbots/1312012 to your computer and use it in GitHub Desktop.
jquery konami code plugin
(function($) {
$(document).ready(function() {
$(document).konami(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
document.body.appendChild(s);
s.src = 'http://erkie.github.com/asteroids.min.js';
});
$(document).konami(function() {
var u = navigator.userAgent.toLowerCase(), v = (u.match(/.+?(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1];
if (/msie/.test(u) && parseInt(v, 10) <= 9) {
if (confirm('Ready to kill the iexplorer?')) {
window.open('', '_parent', '');
window.close();
}
}
}, { 'code': [73, 69, 83, 85, 67, 75, 83] }); //iesucks
});
})(jQuery);
(function($) {
//konami code plugin
$.konami = {
defaults: {
'code': [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
'step': 0
}
};
$.fn.konami = function(fn, options) {
var opts = $.extend({}, $.konami.defaults, options);
return this.each(function() {
$(this).bind('konami.' + opts.code.join(''), fn)
.bind('keyup', function(event) {
if (event.keyCode == opts.code[opts.step])
opts.step++;
else
opts.step = 0;
if (opts.step == opts.code.length) {
$(this).trigger('konami.' + opts.code.join(''));
opts.step = 0;
}
});
return this;
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment