Created
June 5, 2019 06:08
-
-
Save benrowe/8f66a6e32759db98ad8a16eb1a7274a4 to your computer and use it in GitHub Desktop.
old konami jquery plugin
This file contains 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
$.fn.konami = function (options) { | |
var enterKey = 13; | |
if (typeof options == 'function') { | |
options = { callback: options }; | |
} | |
options = options || {}; | |
options = $.extend({ | |
callback: false, | |
keyCode: [38, 38, 40, 40, 37, 39, 37, 39, 66, 65], | |
reqEnter: true, //13, | |
enterTime: false | |
}, options); | |
if (options.callback == false) return; | |
if (options.reqEnter && options.keyCode[options.keyCode.length] != enterKey) { | |
options.keyCode.push(enterKey); | |
} | |
return this.each(function () { | |
var seq = []; | |
$(this).keyup(function (e) { | |
if (e.keyCode == options.keyCode[seq.length]) { | |
seq.push(e.keyCode); | |
} else { | |
seq = []; | |
} | |
if (options.keyCode.length == seq.length) { | |
seq = []; | |
options.callback(); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$('css selector').konami(() => {
// do something
});