├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── karma.conf.js ├── package.json ├── src └── vue-konami-code.js └── test └── vue-konami-code.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | - "6" 5 | - "5" 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 azzra 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VueJS Konami code plugin 2 | 3 | [![Build Status](https://travis-ci.org/azzra/vue-konami-code.svg?branch=master)](https://travis-ci.org/azzra/vue-konami-code) 4 | 5 | Enable the [Konami code](https://en.wikipedia.org/wiki/Konami_Code) on your VueJS application. 6 | 7 | ## Installation 8 | 9 | Download the plugin 10 | 11 | ```sh 12 | npm install --save vue-konami-code 13 | ``` 14 | 15 | In your application code 16 | 17 | ```js 18 | import KonamiCode from 'vue-konami-code' 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```js 24 | Vue.use(KonamiCode, {callback: function () { 25 | alert('Snake? Snake!? Snaaaake!') 26 | }}) 27 | ``` 28 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | 3 | module.exports = function(config) { 4 | config.set({ 5 | 6 | // base path that will be used to resolve all patterns (eg. files, exclude) 7 | basePath: '', 8 | 9 | 10 | // frameworks to use 11 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 12 | frameworks: ['mocha'], 13 | 14 | 15 | // list of files / patterns to load in the browser 16 | files: [ 17 | 'test/*.js' 18 | ], 19 | 20 | 21 | // list of files to exclude 22 | exclude: [ 23 | ], 24 | 25 | 26 | // preprocess matching files before serving them to the browser 27 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 28 | preprocessors: { 29 | 'test/*.js': ['webpack'] 30 | }, 31 | 32 | 33 | // test results reporter to use 34 | // possible values: 'dots', 'progress' 35 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 36 | reporters: ['progress'], 37 | 38 | 39 | // web server port 40 | port: 9876, 41 | 42 | 43 | // enable / disable colors in the output (reporters and logs) 44 | colors: true, 45 | 46 | 47 | // level of logging 48 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 49 | logLevel: config.LOG_INFO, 50 | 51 | 52 | // enable / disable watching file and executing tests whenever any file changes 53 | autoWatch: false, 54 | 55 | 56 | // start these browsers 57 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 58 | browsers: ['PhantomJS'], 59 | 60 | 61 | // Continuous Integration mode 62 | // if true, Karma captures browsers, runs the tests and exits 63 | singleRun: true, 64 | 65 | // Concurrency level 66 | // how many browser should be started simultaneous 67 | concurrency: Infinity 68 | }) 69 | } 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-konami-code", 3 | "version": "1.0.0", 4 | "description": "Use the Konami code in VueJS", 5 | "main": "src/vue-konami-code.js", 6 | "scripts": { 7 | "test": "karma start" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/azzra/vue-konami-code.git" 12 | }, 13 | "keywords": [ 14 | "vuejs", 15 | "plugin", 16 | "konamicode" 17 | ], 18 | "author": "Azzra", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/azzra/vue-konami-code/issues" 22 | }, 23 | "homepage": "https://github.com/azzra/vue-konami-code#readme", 24 | "dependencies": { 25 | "vue": "^2.2.2" 26 | }, 27 | "devDependencies": { 28 | "karma": "^1.5.0", 29 | "karma-mocha": "^1.3.0", 30 | "karma-phantomjs-launcher": "^1.0.4", 31 | "karma-webpack": "^2.0.2", 32 | "mocha": "^3.2.0", 33 | "phantomjs": "^2.1.7", 34 | "sinon": "^2.0.0-pre.6", 35 | "webpack": "^2.2.1" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/vue-konami-code.js: -------------------------------------------------------------------------------- 1 | var install = function (Vue, options) { 2 | if (typeof options !== 'undefined' && typeof options.callback !== 'function') { 3 | return 4 | } 5 | const kode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65] 6 | const length = kode.length 7 | var pos = 0 8 | document.addEventListener('keydown', function (event) { 9 | if (event.keyCode === kode[pos++]) { 10 | if (length === pos) { 11 | options.callback() 12 | pos = 0 // ability to start over 13 | return false 14 | } 15 | } else { 16 | pos = 0 17 | } 18 | }, false) 19 | } 20 | 21 | typeof module !== 'undefined' && typeof module.exports !== 'undefined' && (module.exports = install) 22 | -------------------------------------------------------------------------------- /test/vue-konami-code.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import KonamiCode from '../src/vue-konami-code.js' 3 | 4 | import assert from 'assert' 5 | import sinon from 'sinon' 6 | 7 | describe('Konami Code Plugin', function() { 8 | 9 | describe('#callback', function() { 10 | 11 | var dispatchEvent = function(keyCode) { 12 | var keydown = document.createEvent('Event'); 13 | keydown.initEvent('keydown', true, true); 14 | keydown.keyCode = keyCode 15 | document.dispatchEvent(keydown) 16 | } 17 | 18 | var callback 19 | before(function() { 20 | callback = sinon.spy() 21 | Vue.use(KonamiCode, {'callback': callback}) 22 | }) 23 | 24 | it('should not be executed', function() { 25 | dispatchEvent(38) 26 | dispatchEvent(38) 27 | dispatchEvent(40) 28 | dispatchEvent(40) 29 | dispatchEvent(37) 30 | dispatchEvent(39) 31 | dispatchEvent(37) 32 | dispatchEvent(39) 33 | dispatchEvent(66) 34 | dispatchEvent(66) // diff 35 | dispatchEvent(65) 36 | assert(!callback.called) 37 | }) 38 | 39 | it('should be executed', function() { 40 | var executeCode = function() { 41 | dispatchEvent(38) 42 | dispatchEvent(38) 43 | dispatchEvent(40) 44 | dispatchEvent(40) 45 | dispatchEvent(37) 46 | dispatchEvent(39) 47 | dispatchEvent(37) 48 | dispatchEvent(39) 49 | dispatchEvent(66) 50 | dispatchEvent(65) 51 | } 52 | 53 | executeCode() 54 | assert(callback.calledOnce) 55 | executeCode() 56 | assert(callback.calledTwice) 57 | }) 58 | 59 | }) 60 | 61 | }) 62 | --------------------------------------------------------------------------------