├── .gitignore ├── README.md ├── bower.json ├── changelog.md ├── demo ├── demo.html └── demo.js └── src ├── jquery.konami.js ├── jquery.konami.min.js ├── vanilla.konami.js └── vanilla.konami.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Konami Code For jQuery 2 | By [Tom McFarlin](https://tommcfarlin.com). Last Updated 4 December 2015. 3 | 4 | ## About 5 | 6 | Using the Konami code, easily configure and Easter Egg for your page or any element on the page. 7 | 8 | ## Parameters 9 | 10 | * `code` Personalized code. 11 | * `cheat` The callback function to fire once the cheat code has been entered. 12 | * `eventName` jQuery event name for default callback 13 | * `eventProperties` event property override for default callback 14 | 15 | ## Installation 16 | ```sh 17 | bower install konami-code 18 | ``` 19 | 20 | ## Instructions 21 | 22 | Include the plugin in the header of your page: 23 | 24 | ```html 25 | ` 26 | 27 | ``` 28 | 29 | ### With callback 30 | 31 | Apply the plugin to a selector to capture keypresses: 32 | 33 | ```js 34 | $( window ).konami(); 35 | ``` 36 | 37 | ```js 38 | $( '.konami-sensitive' ).konami(); 39 | ``` 40 | 41 | Specify a callback to fire once the code has been entered: 42 | 43 | ```js 44 | $( window ).konami({ 45 | cheat: function() { 46 | alert( 'Cheat code activated!' ); 47 | } 48 | }); 49 | ``` 50 | 51 | ### Using jQuery events 52 | 53 | Catch the konami code with a jQuery event handler: 54 | 55 | ```js 56 | $( window ).konami(); 57 | $( window ).on('konami', function() { 58 | alert( 'Cheat code activated!' ); 59 | }) 60 | ``` 61 | 62 | Add extra data to the jQuery event callback: 63 | 64 | ```js 65 | $( window ).konami( { message: 'special message' } ); 66 | $( window ).on('konami', function(evt, extraParam) { 67 | alert( 'Cheat code activated: ' + extraParam.message + '!' ); 68 | }) 69 | ``` 70 | 71 | Use event names: 72 | 73 | ```js 74 | $('.type1').konami( { eventName: 'konami.on.type1' } ); 75 | $('.type2').konami( { eventName: 'konami.on.type2' } ); 76 | $( window ).on('konami.on.type2', function(evt, extraParam) { 77 | alert( 'Cheat code activated on a type2 element' ); 78 | }) 79 | ``` 80 | 81 | ### Personallizing the code 82 | 83 | You can personalize the code too, just entering a array with ASCII codes keys in code param 84 | 85 | ```js 86 | $( window ).konami({ 87 | code : [38,38,40,40,37,39,37,39], // up up down down left right left right 88 | cheat: function() { 89 | alert( 'Cheat code activated!' ); 90 | } 91 | }); 92 | ``` 93 | 94 | 95 | ## Contact 96 | 97 | * Web: [Tom McFarlin](https://tommcfarlin.com) 98 | * Twitter: [@tommcfarlin](https://twitter.com/tommcfarlin/) 99 | 100 | ## License 101 | 102 | [MIT license](http://www.opensource.org/licenses/mit-license.php) 103 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "konami-code", 3 | "version": "1.3.3", 4 | "homepage": "https://github.com/tommcfarlin/konami-code", 5 | "authors": [ 6 | { 7 | "name": "Tom McFarlin", 8 | "email": "tom@tommcfarlin.com", 9 | "homepage": "https://tommcfarlin.com" 10 | } 11 | ], 12 | "description": "Using the Konami code, easily configure and Easter Egg for your page or any element on the page.", 13 | "main": "./src/jquery.konami.min.js", 14 | "keywords": [ 15 | "konami", "jquery", "js" 16 | ], 17 | "license": "MIT", 18 | "ignore": [ 19 | "**/.*", 20 | "node_modules", 21 | "bower_components", 22 | "test", 23 | "tests" 24 | ], 25 | "dependencies": { 26 | "jquery": ">= 1.10.2" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | _1.3.3_ (4 December 2015) 2 | 3 | * Updating README 4 | * Tagging for Bower support 5 | 6 | _1.3.1_ 7 | 8 | * jQuery events supported 9 | 10 | _1.3.0 (7 March 2014)_ 11 | 12 | * Minor updates to the coding conventions and docblocks 13 | * Tagging for registration in the Bower repository 14 | 15 | _1.2.2 (6 March 2014)_ 16 | 17 | * Added support for bower (bower.json) 18 | 19 | _1.2.1 (23 October 2013)_ 20 | 21 | * Added option to customize the code 22 | 23 | _1.2.0 (11 October 2013)_ 24 | 25 | * Additional, minor refactoring for strong JSLint 26 | * Removing extranneous whitespace 27 | * Moving the plugin to a `src` directory 28 | * Updated the demo to the latest version of jQuery 29 | * Updated the code for jQuery 30 | * Updated authorship information 31 | * Updated the version number in the plugin 32 | * Updated the README and the changelog 33 | 34 | _1.1.0 (10, October, 2013)_ 35 | 36 | * Refactoring some of the code up to JSLint standards 37 | * Updating the changelog to markdown 38 | * Updating the README to markdown 39 | * Removed the MIT License and included it in the README 40 | 41 | _1.0.0 4 March 2011_ 42 | 43 | * Initial release 44 | * 3/14/2011 -------------------------------------------------------------------------------- /demo/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Konami Code For jQuery | Demo 9 | 10 | 11 |

Enter the Konami Code

12 |

[up up down down left right left right b a]

13 | 14 | Four konami code event handlers are attached to this window. 15 | 21 | 22 | When you enter the komami code while the caret is in input1, you should see three alerts. 23 | 24 |
25 | Input 1:
26 | Input 2:
27 | Input 3:
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /demo/demo.js: -------------------------------------------------------------------------------- 1 | (function( $ ) { 2 | "use strict"; 3 | 4 | $(function() { 5 | $( window ).konami({ 6 | cheat: function() { 7 | alert( 'Cheat code activated!' ); 8 | } // end cheat 9 | }); 10 | 11 | $('#input1').konami( { eventName: 'konami.with.message', message: 'Code on Input 1' } ); 12 | $('#input2').konami( { eventName: 'konami.with.message', message: 'Code on Input 2' } ); 13 | $('.odd').konami( { eventName: 'konami.with.message', message: 'Code on an odd-numbered input' } ); 14 | 15 | $(window).on('konami.with.message', function(event, opts) { 16 | alert('Cheat code with message: ' + opts.message); 17 | }); 18 | }); 19 | }(jQuery)); 20 | 21 | -------------------------------------------------------------------------------- /src/jquery.konami.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Konami Code For jQuery Plugin 3 | * 1.3.3, 4 December 2015 4 | * 5 | * Using the Konami code, easily configure and Easter Egg for your page or any element on the page. 6 | * 7 | * Copyright 2011 - 2015 Tom McFarlin, https://tommcfarlin.com 8 | * Released under the MIT License 9 | */ 10 | 11 | (function ( $ ) { 12 | "use strict"; 13 | 14 | $.fn.konami = function( options ) { 15 | var opts, controllerCode; 16 | 17 | opts = $.extend({}, $.fn.konami.defaults, options); 18 | controllerCode = []; 19 | 20 | // Note that we use the passed-in options, not the resolved options. 21 | opts.eventProperties = $.extend({}, options, opts.eventProperties); 22 | 23 | this.keyup(function( evt ) { 24 | var code = evt.keyCode || evt.which; 25 | 26 | if ( opts.code.length > controllerCode.push( code ) ) { 27 | return; 28 | } 29 | 30 | if ( opts.code.length < controllerCode.length ) { 31 | controllerCode.shift(); 32 | } 33 | 34 | if ( opts.code.toString() !== controllerCode.toString() ) { 35 | return; 36 | } 37 | 38 | opts.cheat(evt, opts); 39 | 40 | }); 41 | 42 | return this; 43 | }; 44 | 45 | $.fn.konami.defaults = { 46 | code : [38,38,40,40,37,39,37,39,66,65], 47 | eventName : 'konami', 48 | eventProperties : null, 49 | cheat: function(evt, opts) { 50 | $(evt.target).trigger(opts.eventName, [ opts.eventProperties ]); 51 | } 52 | }; 53 | 54 | })( jQuery ); -------------------------------------------------------------------------------- /src/jquery.konami.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Konami Code For jQuery Plugin 3 | * 1.3.0, 7 March 2014 4 | * 5 | * Using the Konami code, easily configure and Easter Egg for your page or any element on the page. 6 | * 7 | * Copyright 2011 - 2014 Tom McFarlin, http://tommcfarlin.com 8 | * Released under the MIT License 9 | */ 10 | !function(e){"use strict";e.fn.konami=function(t){var n,i;return n=e.extend({},e.fn.konami.defaults,t),i=[],n.eventProperties=e.extend({},t,n.eventProperties),this.keyup(function(e){var t=e.keyCode||e.which;n.code.length>i.push(t)||(n.code.length cache.push( keycode ) ) { 131 | 132 | return; 133 | } 134 | 135 | if ( config.code.length < cache.length ) { 136 | 137 | cache.shift(); 138 | } 139 | 140 | if ( config.code.toString() !== cache.toString() ) { 141 | 142 | return; 143 | } 144 | 145 | config.cheat(); 146 | } 147 | }; 148 | 149 | ret.init( options ); 150 | return ret; 151 | }; 152 | 153 | /*========================================= 154 | Example Usage: 155 | 156 | var options = { 157 | cheat : function() { 158 | alert( 'KONAMI!!' ); 159 | } 160 | }; 161 | 162 | var example = new KONAMI( options ); 163 | 164 | // rebuild with new settings 165 | example.destroy(); 166 | example.init( newConfig ); 167 | ==========================================*/ -------------------------------------------------------------------------------- /src/vanilla.konami.min.js: -------------------------------------------------------------------------------- 1 | var KONAMI=function(e){var f,d,g,a,c,b;g={code:[38,38,40,40,37,39,37,39,66,65],cheat:null,elem:window};d={init:function(h){b=[],c={};if(h){for(var i in g){if(g.hasOwnProperty(i)){if(!h[i]){c[i]=g[i]}else{c[i]=h[i]}}}}else{c=g}d.bind(c.elem,"keyup",d.konami)},destroy:function(){d.unbind(c.elem,"keyup",d.konami);b=c=null},bind:function(j,h,i){if(j.addEventListener){j.addEventListener(h,i,false)}else{if(j.attachEvent){j.attachEvent("on"+h,function(k){i(k||window.event)})}}},unbind:function(j,h,i){if(j.removeEventListener){j.removeEventListener(h,i,false)}else{if(j.detachEvent){j.detachEvent("on"+h,function(k){i(k||window.event)})}}},konami:function(h){a=h.keyCode||h.which;if(c.code.length>b.push(a)){return}if(c.code.length