to listening Konami Code Sequence and after
fire the Correct Sequence, avoid next Konami Code recognization.Fire a JavaScript Event when you enter the « Up Up Bottom Bottom Left Right Left Right B A » Konami Code Sequence.
npm install konami-code-jsFire a JavaScript Event when you enter the « Up Up Bottom Bottom Left Right Left Right B A » Konami Code Sequence with your keyboard. That work also when you do the following touch gesture « Up Up Bottom Bottom Left Right Left Right Tap Tap » with your finger.
-----
Vous êtes français ? Le README derrière ce lien vous sera peut-être plus agréable.
``js`
new KonamiCode(function () {
// Do something here.
// This part will be executed if « Up Up Down Down Left Right Left Right B A »
// is recognised from Keyboard or Touch Gesture.
});
In this example, we will authorized only the area of to listening Konami Code Sequence and after
fire the Correct Sequence, avoid next Konami Code recognization.
`js
var kc = new KonamiCode({
listener: document.getElementsByTagName("article")[0]
});
kc.setCallback(function () {
kc.disable();
// Do something here.
// This part will be executed if « Up Up Down Down Left Right Left Right B A »
// is recognised from Keyboard or Touch Gesture.
});
`
Version: 0.8.3
Author: Bruno Lesieur
* KonamiCode
* [new KonamiCode([options])](#new_KonamiCode_new)
* _instance_
* .enable() ⇒ KonamiCode
* .enableKeyboardKeys() ⇒ KonamiCode
* .enableTouchGesture() ⇒ KonamiCode
* .disable() ⇒ KonamiCode
* .disabledKeyboardKeys() ⇒ KonamiCode
* .disabledTouchGesture() ⇒ KonamiCode
* .setListener(listener) ⇒ KonamiCode
* .setCallback(callback) ⇒ KonamiCode
* [.setOptions([options])](#KonamiCode+setOptions) ⇒ KonamiCode
* _static_
* .noConflict()
* .getNumberOfInstance() ⇒ number
| Param | Type | Description |
| --- | --- | --- |
| [options] | Object | function | Container for all options. If type of options is Function, it is executed after Konami Code Sequence has been recognize. |options
| [options.callback] | function | If is not a Function, options.callback is executed after Konami Code Sequence has been entered. The first parameter provided by the callback is current instance of KonamiCode. |window.document
| [options.listener] | Node | By default it is the HTMLDocument . You can pass some HTMLElement like (HTMLInputElement) to only recognize Konami Code Sequence from this element. |false
| [options.debug] | boolean | By default it is set to . When you set this value to true, that allows you to see all debug message in the console. |
Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
.Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
| Param | Type | Description |
| --- | --- | --- |
| listener | Node | You can pass some HTMLElement like
(HTMLInputElement) to only recognize Konami Code Sequence from this element. |$3
Change the Function executed after Konami Code Sequence has been entered.Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
| Param | Type | Description |
| --- | --- | --- |
| callback | function | Function executed after Konami Code Sequence has been entered. The first parameter provided by the callback is current instance of KonamiCode. |
Example
`js
new KonamiCode().setCallback(function (konamiCode) {
konamiCode.disable();
// Do something here.
});
`
$3
Change options of instance currently existing.Kind: instance method of KonamiCode
Returns: KonamiCode - Current instance of KonamiCode
| Param | Type | Description |
| --- | --- | --- |
| [options] | Object | Container for all options. |
| [options.callback] | function | Function executed after Konami Code Sequence has been entered. The first parameter provided by the callback is current instance of KonamiCode. |
| [options.listener] | Node | By default it is the HTMLDocument
window.document. You can pass some HTMLElement like (HTMLInputElement) to only recognize Konami Code Sequence from this element. |
| [options.debug] | boolean | By default it is set to false. When you set this value to true, that allows you to see all debug message in the console. |$3
If a previous KonamiCode variable exist into global environment, you could kept it by changing name of current KonamiCode.
You can also just use that function to change the name of Global « KonamiCode » variable.Kind: static method of KonamiCode
Example
`js
`
$3
Return the number of time KonamiCode was instanciated.Kind: static method of KonamiCode
Returns: number - Number of KonamiCode instance create from begining.
Chaining ##
All API instanciated methods return the current instance of
KonamiCode Object. That allows you to use instance like this.`js
new KonamiCode()
.disable()
.enable()
.setListener(document.getElementsByTagName("body")[0])
.setCallback(function (konamiCode) {
konamiCode.disable();
// Do something here.
// This part will be executed if « Up Up Down Down Left Right Left Right B A »
// is recognised from Keyboard or Touch Gesture.
});
`Debug Mode ##
You can see what step are used with console log message.
`js
new KonamiCode({
debug: true,
callback: function (konamiCode) {
konamiCode.disable();
}
});
`Import JavaScript File ##
$3
- https://github.com/MachinisteWeb/konami-code-js/blob/master/src/konami-code.js
$3
`
npm install konami-code-js
`$3
- For development:
`html
`- For production:
`html
`$3
`html
`$3
`js
var KonamiCode = require("konami-code-js");new KonamiCode(function () {
// Do something here.
// This part will be executed if « Up Up Down Down Left Right Left Right B A »
// is recognised from Keyboard or Touch Gesture.
});
``