This packages makes it nice and easy to add Easter Egg triggers to your Vue site.
npm i vue-easter-egg-trigger
import Vue from 'vue';
import EasterEggTrigger from 'vue-easter-egg-trigger';
Vue.use(EasterEggTrigger);
Name | Type | Default | Description |
---|---|---|---|
delay | Integer | 500 | Determines the timeout before the event lister resets. |
keys | Array | ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'] | The key/click combination a user does to trigger easter egg. The default combination is the konami code. |
pattern | Array | [38, 38, 40, 40, 37, 39, 37, 39, 66, 65] | The key combination a user does to trigger easter egg. (fallback for keys) |
type | String | keydown | The type of action the trigger will be listening for. |
import Vue from 'vue';
import EasterEggTrigger from 'vue-easter-egg-trigger';
Vue.use(EasterEggTrigger, {
delay: 1000,
keys: ['ArrowUp', 'ArrowDown'],
pattern: [38, 40],
type: 'keyup'
});
Name | Type | Default | Description |
---|---|---|---|
callback | Function | null | The callback function |
destroyBus | Boolean | false | Determines if a bus $on event is destroyed automatically |
keys | Array | false | The key/click combination a user does to trigger easter egg. |
name | String | easter-egg | Identifier & used for even bus callback |
pattern | Array | false | The key combination a user does to trigger easter egg. (fallback for keys) |
target | String | div | Use this to target DOM elements, Id's, or Class Names. Used with click events. |
withBus | Boolean | true | Determines if a bus event is emitted |
There are two instance methods available to use.
$easterEgg
$easterEggTrigger
The default key combination to trigger the easter egg is the Konami Code.
ex. ↑ ↑ ↓ ↓ ← → ← → b a
this.$bus.$on('easter-egg', () => {
// do something...
});
this.$easterEgg();
this.$bus.$on('easter-egg', () => {
// also do something...
});
this.$easterEgg({
name: 'easter-egg',
callback() {
// do something ...
},
});
this.$easterEgg({
name: 'easter-egg',
callback() {
// do something ...
},
withBus: false,
});
First you will need to set the type in the plugin options.
Available types of Mouse Events: click
, dblclick
, mouseup
, mousedown
.
When using dblclick
the pattern will only work with one double click. Ex. pattern: ['dblclick']
import Vue from 'vue';
import EasterEggTrigger from 'vue-easter-egg-trigger';
Vue.use(EasterEggTrigger, {
type: 'click'
});
this.$bus.$on('easter-egg', () => {
// also do something...
});
this.$easterEgg({
name: 'easter-egg',
pattern: ['click', 'click'],
callback() {
// do something...
},
});
this.$easterEgg({
name: 'easter-egg',
pattern: ['click', 'click'],
target: 'h1',
});
this.$easterEgg({
name: 'easter-egg',
pattern: ['click', 'click'],
target: '#foo',
});
this.$easterEgg({
name: 'easter-egg',
pattern: ['click', 'click'],
target: '.foo',
});
You can find more examples in the EasterEgg.vue file.
Coming soon to an animal santuary near you.
Copyright (c) 2021 WebDevNerdStuff Licensed under the MIT license.