1
- import Vue from 'vue' ;
1
+ // import Vue from 'vue';
2
2
import _ from '@assets/lodash.custom' ;
3
3
4
- let easterEggs = [ ] ;
4
+ let EasterEggTriggerVueObj = null ;
5
+ let easterEggsTriggerEggs = [ ] ;
5
6
6
7
const EasterEggTrigger = {
7
8
timeout : null ,
@@ -13,56 +14,44 @@ const EasterEggTrigger = {
13
14
} ,
14
15
15
16
// 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 ,
38
25
} ,
39
26
eggOptions : { } ,
40
27
pluginOptions : { } ,
41
28
42
29
// Initiate Eggs //
43
- init ( vue , pluginOptions , eggOptions = { } ) {
30
+ init ( Vue , pluginOptions = { } , eggOptions = { } ) {
31
+ EasterEggTriggerVueObj = Vue ;
32
+
44
33
// 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 } ;
47
36
48
37
this . layEggs ( ) ;
49
38
} ,
50
39
51
40
// Adds Eggs to Easter Eggs //
52
41
layEggs ( ) {
53
- easterEggs . push ( this . eggOptions ) ;
42
+ easterEggsTriggerEggs . push ( this . eggOptions ) ;
54
43
55
44
this . callAddListener ( ) ;
56
45
} ,
57
46
58
47
// Call the add listener //
59
48
callAddListener ( ) {
60
- Object . values ( easterEggs ) . forEach ( ( egg ) => {
49
+ Object . values ( easterEggsTriggerEggs ) . forEach ( ( egg ) => {
61
50
const newEgg = egg ;
62
51
63
52
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 ;
66
55
}
67
56
} ) ;
68
57
@@ -93,7 +82,7 @@ const EasterEggTrigger = {
93
82
}
94
83
95
84
// -------------------- Mouse Events //
96
- if ( _ . includes ( EasterEggTrigger . defaultOptions . plugin . mouseEvents , e . type ) ) {
85
+ if ( _ . includes ( EasterEggTrigger . pluginOptions . mouseEvents , e . type ) ) {
97
86
key = e . type ;
98
87
99
88
EasterEggTrigger . targets . nodes . push ( e . target . nodeName . toLowerCase ( ) ) ;
@@ -107,7 +96,7 @@ const EasterEggTrigger = {
107
96
108
97
// Check the Keys or Click Pattern //
109
98
checkPattern ( e ) {
110
- Object . values ( easterEggs ) . forEach ( ( egg ) => {
99
+ Object . values ( easterEggsTriggerEggs ) . forEach ( ( egg ) => {
111
100
// Check Keyboard Events //
112
101
if ( _ . isEqual ( egg ?. keys , this . input ) || _ . isEqual ( egg ?. pattern , this . input ) ) {
113
102
// Check Targets if Mouse Events //
@@ -168,7 +157,7 @@ const EasterEggTrigger = {
168
157
169
158
// Emit Bus Event and/or Callback //
170
159
emit ( egg ) {
171
- if ( Object . keys ( easterEggs ) . length === 1 ) {
160
+ if ( Object . keys ( easterEggsTriggerEggs ) . length === 1 ) {
172
161
document . removeEventListener ( this . pluginOptions . type , this . capturePattern , false ) ;
173
162
}
174
163
else {
@@ -183,30 +172,30 @@ const EasterEggTrigger = {
183
172
}
184
173
}
185
174
186
- new Vue ( ) . $bus . $emit ( `${ egg . name } ` ) ;
175
+ new EasterEggTriggerVueObj ( ) . $bus . $emit ( `${ egg . name } ` ) ;
187
176
188
177
// Auto destroy $bus.$on //
189
178
if ( egg . destroyBus ) {
190
- new Vue ( ) . $bus . $off ( `${ egg . name } ` ) ;
179
+ new EasterEggTriggerVueObj ( ) . $bus . $off ( `${ egg . name } ` ) ;
191
180
}
192
181
193
182
return false ;
194
183
} ,
195
184
196
185
// Rebuild the Easter Eggs //
197
186
rebuild ( usedEgg ) {
198
- const currentEggs = easterEggs ;
199
- easterEggs = [ ] ;
187
+ const currentEggs = easterEggsTriggerEggs ;
188
+ easterEggsTriggerEggs = [ ] ;
200
189
201
- // Remove usedEgg from easterEggs //
190
+ // Remove usedEgg from easterEggsTriggerEggs //
202
191
const idx = _ . findIndex ( currentEggs , ( egg ) => egg . name === usedEgg . name ) ;
203
192
currentEggs . splice ( idx , 1 ) ;
204
193
205
194
Object . values ( currentEggs ) . forEach ( ( egg ) => {
206
195
this . layEggs ( egg ) ;
207
196
} ) ;
208
197
209
- easterEggs = currentEggs ;
198
+ easterEggsTriggerEggs = currentEggs ;
210
199
} ,
211
200
} ;
212
201
0 commit comments