Search code examples
jqueryversioncompatibilitykey-bindings

Konami Code Keybinding in jQuery 1.7.2


I'd like to implement the raptorize-Plugin but it doesn't work with jQuery 1.7.2 because of this part I think:

else if(options.enterOn == 'konami-code'){
            var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
            $(window).bind("keydown.raptorz", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 ) {
                    init();
                    $(window).unbind('keydown.raptorz');
                }
            }, true);

When I use the button-version it works. What could be the problem?


Solution

  • The .bind() on line 93 of http://www.zurb.com/playground/javascripts/plugins/jquery.raptorize.1.0.js uses the third parameter to prevent bubbling, not sure why this would be necessary when we're looking for keydown events on window, but it's what is breaking it in newer jQuery versions. Remove that third param and it will work in 1.7.2.

    Also ensure you are setting the option correctly e.g.:

    $('.myButton').raptorize({
       'enterOn' : 'konami-code'
    });