1- import Vue from 'vue' ;
1+ // import Vue from 'vue';
22import _ from '@assets/lodash.custom' ;
33
4- let easterEggs = [ ] ;
4+ let EasterEggTriggerVueObj = null ;
5+ let easterEggsTriggerEggs = [ ] ;
56
67const 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