Created
          November 9, 2010 16:29 
        
      - 
      
- 
        Save sunny/669331 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | /** | |
| * 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