Skip to content

Commit f672116

Browse files
Merge pull request #1 from webdevnerdstuff/dev
Dev
2 parents 5dab4bf + 94103ac commit f672116

9 files changed

+13947
-20462
lines changed

dist/ssr.vue-easter-egg-trigger.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-easter-egg-trigger.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+13,909-20,202
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "vue-easter-egg-trigger",
3-
"version": "0.1.15",
3+
"version": "0.1.22",
44
"description": "This packages makes it nice and easy to add Easter Egg triggers to your Vue site.",
55
"private": false,
6-
"main": "dist/index.js",
6+
"main": "dist/vue-easter-egg-trigger.js",
77
"types": "types/index.d.ts",
88
"scripts": {
99
"serve": "npm run development",
@@ -13,10 +13,6 @@
1313
"build:release": "webpack --config ./build/webpack.release.config.js --progress",
1414
"build:ssr": "webpack --config ./build/webpack.ssr.config.js --progress",
1515
"build": "npm run build:release && npm run build:ssr",
16-
"lint:js": "eslint --ext js --ext jsx --ext vue src",
17-
"lint:js:fix": "npm run lint:js -- --fix",
18-
"test": "jest",
19-
"test:types": "tsc -p types/test",
2016
"docs:dev": "vuepress dev docs",
2117
"docs:build": "vuepress build docs"
2218
},
@@ -70,7 +66,6 @@
7066
"@babel/runtime": "^7.13.17",
7167
"@vue/eslint-config-prettier": "^6.0.0",
7268
"@vue/test-utils": "1.0.0-beta.31",
73-
"babel-jest": "^23.6.0",
7469
"babel-loader": "^8.2.2",
7570
"babel-plugin-module-resolver": "^4.1.0",
7671
"browser-sync": "^2.26.14",
@@ -88,8 +83,6 @@
8883
"eslint-webpack-plugin": "^2.5.4",
8984
"file-loader": "^0.9.0",
9085
"html-webpack-plugin": "^5.3.1",
91-
"jest": "^23.6.0",
92-
"jest-serializer-vue": "^2.0.2",
9386
"ts-loader": "^6.2.2",
9487
"vue-hot-reload-api": "^2.0.8",
9588
"vue-jest": "^3.0.1",

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import EasterEggTrigger from '@plugins/EasterEggTrigger'
1+
import EasterEggTrigger from '@plugins/EasterEggTrigger';
22

3-
export const version = '__VERSION__'
3+
export const version = '__VERSION__';
44

55
// Automatic installation if Vue has been added to the global scope.
66
if (typeof window !== 'undefined' && window.Vue) {
77
window.Vue.use(EasterEggTrigger);
88
}
99

10-
export default EasterEggTrigger
10+
export default EasterEggTrigger;

src/plugins/EasterEggTrigger.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ const EasterEggTrigger = {
1111

1212
// Add an instance methods //
1313
Vue.prototype.$easterEgg = function(eggOptions) {
14-
const pluginOptions = EasterEggTrigger.options;
15-
16-
EasterEggTriggerCore.init(Vue, pluginOptions, eggOptions);
14+
EasterEggTriggerCore.init(Vue, EasterEggTrigger.options, eggOptions);
1715
};
1816

1917
Vue.prototype.$easterEggTrigger = function(eggOptions) {
20-
const pluginOptions = EasterEggTrigger.options;
21-
EasterEggTriggerCore.init(Vue, pluginOptions, eggOptions);
22-
// plugin.setEggOptions(methodOptions);
23-
// plugin.callAddListener();
18+
EasterEggTriggerCore.init(Vue, EasterEggTrigger.options, eggOptions);
2419
};
2520
},
2621
options: {

src/plugins/EasterEggTriggerCore.js

+29-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import Vue from 'vue';
1+
// import Vue from 'vue';
22
import _ from '@assets/lodash.custom';
33

4-
let easterEggs = [];
4+
let EasterEggTriggerVueObj = null;
5+
let easterEggsTriggerEggs = [];
56

67
const EasterEggTrigger = {
78
timeout: null,
@@ -13,56 +14,44 @@ const EasterEggTrigger = {
1314
},
1415

1516
// Options //
16-
defaultOptions: {
17-
egg: {
18-
callback: null,
19-
destroyBus: false,
20-
keys: false,
21-
name: 'easter-egg',
22-
pattern: false,
23-
target: 'html',
24-
withBus: true,
25-
},
26-
plugin: {
27-
delay: 500,
28-
keys: ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'],
29-
mouseEvents: [
30-
'click', // Works with multiple single clicks pattern
31-
'dblclick', // Only works with single double click pattern set
32-
'mouseup', // Works with multiple mouseup clicks pattern
33-
'mousedown', // Works with multiple mousedown clicks pattern
34-
],
35-
pattern: [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
36-
type: 'keydown',
37-
},
17+
defaultEggOptions: {
18+
callback: null,
19+
destroyBus: false,
20+
keys: false,
21+
name: 'easter-egg',
22+
pattern: false,
23+
target: 'div',
24+
withBus: true,
3825
},
3926
eggOptions: {},
4027
pluginOptions: {},
4128

4229
// Initiate Eggs //
43-
init(vue, pluginOptions, eggOptions = {}) {
30+
init(Vue, pluginOptions = {}, eggOptions = {}) {
31+
EasterEggTriggerVueObj = Vue;
32+
4433
// Set Options //
45-
this.pluginOptions = { ...this.defaultOptions.plugin, ...pluginOptions };
46-
this.eggOptions = { ...this.defaultOptions.egg, ...eggOptions };
34+
this.pluginOptions = pluginOptions;
35+
this.eggOptions = { ...this.defaultEggOptions, ...eggOptions };
4736

4837
this.layEggs();
4938
},
5039

5140
// Adds Eggs to Easter Eggs //
5241
layEggs() {
53-
easterEggs.push(this.eggOptions);
42+
easterEggsTriggerEggs.push(this.eggOptions);
5443

5544
this.callAddListener();
5645
},
5746

5847
// Call the add listener //
5948
callAddListener() {
60-
Object.values(easterEggs).forEach((egg) => {
49+
Object.values(easterEggsTriggerEggs).forEach((egg) => {
6150
const newEgg = egg;
6251

6352
if (!newEgg.keys && !newEgg.pattern) {
64-
newEgg.keys = this.defaultOptions.plugin.keys;
65-
newEgg.pattern = this.defaultOptions.plugin.pattern;
53+
newEgg.keys = this.pluginOptions.keys;
54+
newEgg.pattern = this.pluginOptions.pattern;
6655
}
6756
});
6857

@@ -93,7 +82,7 @@ const EasterEggTrigger = {
9382
}
9483

9584
// -------------------- Mouse Events //
96-
if (_.includes(EasterEggTrigger.defaultOptions.plugin.mouseEvents, e.type)) {
85+
if (_.includes(EasterEggTrigger.pluginOptions.mouseEvents, e.type)) {
9786
key = e.type;
9887

9988
EasterEggTrigger.targets.nodes.push(e.target.nodeName.toLowerCase());
@@ -107,7 +96,7 @@ const EasterEggTrigger = {
10796

10897
// Check the Keys or Click Pattern //
10998
checkPattern(e) {
110-
Object.values(easterEggs).forEach((egg) => {
99+
Object.values(easterEggsTriggerEggs).forEach((egg) => {
111100
// Check Keyboard Events //
112101
if (_.isEqual(egg?.keys, this.input) || _.isEqual(egg?.pattern, this.input)) {
113102
// Check Targets if Mouse Events //
@@ -168,7 +157,7 @@ const EasterEggTrigger = {
168157

169158
// Emit Bus Event and/or Callback //
170159
emit(egg) {
171-
if (Object.keys(easterEggs).length === 1) {
160+
if (Object.keys(easterEggsTriggerEggs).length === 1) {
172161
document.removeEventListener(this.pluginOptions.type, this.capturePattern, false);
173162
}
174163
else {
@@ -183,30 +172,30 @@ const EasterEggTrigger = {
183172
}
184173
}
185174

186-
new Vue().$bus.$emit(`${egg.name}`);
175+
new EasterEggTriggerVueObj().$bus.$emit(`${egg.name}`);
187176

188177
// Auto destroy $bus.$on //
189178
if (egg.destroyBus) {
190-
new Vue().$bus.$off(`${egg.name}`);
179+
new EasterEggTriggerVueObj().$bus.$off(`${egg.name}`);
191180
}
192181

193182
return false;
194183
},
195184

196185
// Rebuild the Easter Eggs //
197186
rebuild(usedEgg) {
198-
const currentEggs = easterEggs;
199-
easterEggs = [];
187+
const currentEggs = easterEggsTriggerEggs;
188+
easterEggsTriggerEggs = [];
200189

201-
// Remove usedEgg from easterEggs //
190+
// Remove usedEgg from easterEggsTriggerEggs //
202191
const idx = _.findIndex(currentEggs, (egg) => egg.name === usedEgg.name);
203192
currentEggs.splice(idx, 1);
204193

205194
Object.values(currentEggs).forEach((egg) => {
206195
this.layEggs(egg);
207196
});
208197

209-
easterEggs = currentEggs;
198+
easterEggsTriggerEggs = currentEggs;
210199
},
211200
};
212201

0 commit comments

Comments
 (0)