@@ -4,6 +4,20 @@ import {gradientTextGenerator} from './pages/gradient-text';
4
4
import { gradientBorderGenerator } from './pages/gradient-border' ;
5
5
import { gradientBackgroundGenerator } from './pages/gradient-background' ;
6
6
import { animationGenerator } from './pages/animation' ;
7
+
8
+ // Utils
9
+ import {
10
+ createGradientPreview ,
11
+ gradientElementInputs ,
12
+ gradientPreview ,
13
+ getColorInput1 ,
14
+ getColorInput2 ,
15
+ getRange ,
16
+ getCheckbox ,
17
+ getRadiusInput ,
18
+ } from './lib/general' ;
19
+
20
+ // Packages
7
21
import * as FilePond from 'filepond' ;
8
22
import 'filepond/dist/filepond.min.css' ;
9
23
@@ -43,20 +57,20 @@ const sideBarTiming = {
43
57
} ;
44
58
45
59
const navBarSlideIn = [
46
- { left : " -50%" , opacity : '0' , } ,
47
- { left : "0%" , opacity : '1' }
48
- ]
60
+ { left : ' -50%' , opacity : '0' } ,
61
+ { left : '0%' , opacity : '1' } ,
62
+ ] ;
49
63
50
64
const navBarSlideOut = [
51
- { left : "0%" , opacity : '1' } ,
52
- { left : " -50%" , opacity : '0' }
53
- ]
65
+ { left : '0%' , opacity : '1' } ,
66
+ { left : ' -50%' , opacity : '0' } ,
67
+ ] ;
54
68
55
69
const navBarAnimationOptions = {
56
70
duration : 300 ,
57
71
iterations : 1 ,
58
- easing : 'ease'
59
- }
72
+ easing : 'ease' ,
73
+ } ;
60
74
61
75
// Elements
62
76
const generators = document . querySelectorAll ( '[data-gen]' ) ;
@@ -71,91 +85,61 @@ const navBar = document.querySelector('#nav');
71
85
const menuIcon = document . querySelector ( '#menu-icon' ) ;
72
86
73
87
//gradient text color elements
74
- const gradientTextInputs = document . querySelectorAll ( '.gradient-text-inputs' ) ;
75
- const textPreview = < HTMLElement > (
76
- document . querySelector ( '#gradient-text-color-preview' )
77
- ) ;
78
- const gradientTextColor1 = < HTMLInputElement > (
79
- document . querySelector ( '#gradient-text-color1' )
80
- ) ;
81
- const gradientTextColor2 = < HTMLInputElement > (
82
- document . querySelector ( '#gradient-text-color2' )
83
- ) ;
84
- const gradientTextDegree = < HTMLInputElement > (
85
- document . querySelector ( '#gradient-text-degree' )
86
- ) ;
88
+ const gradientTextInputs = gradientElementInputs ( 'gradient-text' ) ;
89
+ const textPreview = gradientPreview ( 'gradient-text' ) ;
90
+ const gradientTextColor1 = getColorInput1 ( 'gradient-text' ) ;
91
+ const gradientTextColor2 = getColorInput2 ( 'gradient-text' ) ;
92
+ const gradientTextDegree = getRange ( 'gradient-text' ) ;
87
93
88
94
//gradient border color element
89
- const gradientBorderInputs = document . querySelectorAll (
90
- '.gradient-border-inputs'
91
- ) ;
92
- const borderPreview = < HTMLElement > (
93
- document . querySelector ( '#gradient-border-color-preview' )
94
- ) ;
95
- const gradientBorderColor1 = < HTMLInputElement > (
96
- document . querySelector ( '#gradient-border-color1' )
97
- ) ;
98
- const gradientBorderColor2 = < HTMLInputElement > (
99
- document . querySelector ( '#gradient-border-color2' )
100
- ) ;
101
- const gradientBorderDegree = < HTMLInputElement > (
102
- document . querySelector ( '#gradient-border-degree' )
103
- ) ;
104
- const gradientBorderRadius = < HTMLInputElement > (
105
- document . querySelector ( '#gradient-border-radius' )
106
- ) ;
107
- const gradientBorderInput = < HTMLInputElement > (
108
- document . querySelector ( '#gradient-border-input' )
109
- )
95
+ const gradientBorderInputs = gradientElementInputs ( 'gradient-border' ) ;
96
+ const borderPreview = gradientPreview ( 'gradient-border' ) ;
97
+ const gradientBorderColor1 = getColorInput1 ( 'gradient-border' ) ;
98
+ const gradientBorderColor2 = getColorInput2 ( 'gradient-border' ) ;
99
+ const gradientBorderDegree = getRange ( 'gradient-border' ) ;
100
+
101
+ const gradientBorderRadius = getCheckbox ( 'gradient-border' ) ;
102
+ const gradientBorderInput = getRadiusInput ( 'gradient-border' ) ;
103
+
110
104
//gradient background color elements
111
- const gradientBackgroundInputs = document . querySelectorAll (
112
- '.gradient-background-inputs'
113
- ) ;
114
- const backgroundPreview = < HTMLElement > (
115
- document . querySelector ( '#gradient-background-color-preview' )
116
- ) ;
117
- const gradientBackgroundColor1 = < HTMLInputElement > (
118
- document . querySelector ( '#gradient-background-color1' )
119
- ) ;
120
- const gradientBackgroundColor2 = < HTMLInputElement > (
121
- document . querySelector ( '#gradient-background-color2' )
122
- ) ;
123
- const gradientBackgroundDegree = < HTMLInputElement > (
124
- document . querySelector ( '#gradient-background-degree' )
125
- ) ;
105
+ const gradientBackgroundInputs = gradientElementInputs ( 'gradient-background' ) ;
106
+ const backgroundPreview = gradientPreview ( 'gradient-background' ) ;
107
+ const gradientBackgroundColor1 = getColorInput1 ( 'gradient-background' ) ;
108
+ const gradientBackgroundColor2 = getColorInput2 ( 'gradient-background' ) ;
109
+ const gradientBackgroundDegree = getRange ( 'gradient-background' ) ;
126
110
127
111
// get all range inputs
128
112
const gradientRangeInputs = document . querySelectorAll ( '.degree-range' ) ;
129
113
130
114
menuIcon ?. addEventListener ( 'click' , ( ) => {
131
115
if ( navBar ?. classList . contains ( 'closed-nav' ) ) {
132
- navBar ?. animate ( navBarSlideIn , navBarAnimationOptions )
116
+ navBar ?. animate ( navBarSlideIn , navBarAnimationOptions ) ;
133
117
navBar ?. classList . remove ( 'closed-nav' ) ;
134
118
menuIcon ?. setAttribute ( 'icon' , 'ci:close-big' ) ;
135
119
} else {
136
- navBar ?. animate ( navBarSlideOut , navBarAnimationOptions )
120
+ navBar ?. animate ( navBarSlideOut , navBarAnimationOptions ) ;
137
121
navBar ?. classList . add ( 'closed-nav' ) ;
138
122
menuIcon ?. setAttribute ( 'icon' , 'dashicons:menu-alt' ) ;
139
123
}
140
124
} ) ;
141
125
142
- const menu = < HTMLElement > ( document . querySelector ( '.menu' ) )
143
- const body = < HTMLElement > ( document . querySelector ( 'body' ) )
126
+ const menu = < HTMLElement > document . querySelector ( '.menu' ) ;
127
+ const body = < HTMLElement > document . querySelector ( 'body' ) ;
144
128
145
- if ( getComputedStyle ( menu ) . display == 'block' ) {
146
- body . onclick = ( e ) => {
147
- if ( e . target !== navBar ) {
148
- if ( e . target !== menuIcon ) {
149
- navBar ?. classList . add ( 'closed-nav' )
150
- menuIcon ?. setAttribute ( 'icon' , 'dashicons:menu-alt' ) ;
151
- }
129
+ if ( getComputedStyle ( menu ) . display == 'block' ) {
130
+ body . onclick = ( e ) => {
131
+ if ( e . target !== navBar ) {
132
+ if ( e . target !== menuIcon ) {
133
+ navBar ?. classList . add ( 'closed-nav' ) ;
134
+ menuIcon ?. setAttribute ( 'icon' , 'dashicons:menu-alt' ) ;
135
+ }
152
136
}
153
- }
137
+ } ;
154
138
}
155
139
156
140
for ( let i = 0 ; i < generators . length ; i ++ ) {
157
141
generators [ i ] . addEventListener ( 'click' , ( ) => {
158
- navBar ?. animate ( navBarSlideOut , navBarAnimationOptions )
142
+ navBar ?. animate ( navBarSlideOut , navBarAnimationOptions ) ;
159
143
navBar ?. classList . add ( 'closed-nav' ) ;
160
144
menuIcon ?. setAttribute ( 'icon' , 'dashicons:menu-alt' ) ;
161
145
} ) ;
@@ -282,25 +266,11 @@ function showResult(attribute: string | null) {
282
266
generatorsFunction ( attribute ) ;
283
267
}
284
268
285
- // function fixPicTextFile() {
286
- // const getImageEntryElement = <HTMLInputElement>(
287
- // document.getElementById(`pic-text-file`)
288
- // );
289
- // getImageEntryElement.setAttribute('value', '');
290
- // getImageEntryElement.setAttribute('src', '');
291
- // FilePond.destroy(getImageEntryElement);
292
-
293
- // if (attributeValue === null) return;
294
- // removeOrAddGeneratorContent(attributeValue, 'none');
295
- // }
296
-
297
- // add event listener to generator icons
298
-
299
269
generators . forEach ( ( generator ) => {
300
270
generator ?. addEventListener ( 'click' , ( ) : void => {
301
271
const checking = generator . getAttribute ( 'data-gen' ) ;
302
272
303
- if ( checking === null ) return ;
273
+ if ( checking === null ) return ;
304
274
sidebar . style . display = 'none' ;
305
275
attributeValue = checking ;
306
276
showContent ( attributeValue , 'flex' ) ;
@@ -342,7 +312,7 @@ gradientRangeInputs.forEach((gradientRangeInput: HTMLInputElement) => {
342
312
} ) ;
343
313
344
314
for ( let i = 0 ; i < gradientBackgroundInputs . length ; i ++ ) {
345
- gradientBackgroundInputs [ i ] . addEventListener ( 'input ' , ( ) =>
315
+ gradientBackgroundInputs [ i ] . addEventListener ( 'change ' , ( ) =>
346
316
createGradientPreview (
347
317
gradientBackgroundColor1 ,
348
318
gradientBackgroundColor2 ,
@@ -354,7 +324,7 @@ for (let i = 0; i < gradientBackgroundInputs.length; i++) {
354
324
355
325
//set gradient border preview
356
326
for ( let i = 0 ; i < gradientBorderInputs . length ; i ++ ) {
357
- gradientBorderInputs [ i ] . addEventListener ( 'input ' , ( ) =>
327
+ gradientBorderInputs [ i ] . addEventListener ( 'change ' , ( ) =>
358
328
createGradientPreview (
359
329
gradientBorderColor1 ,
360
330
gradientBorderColor2 ,
@@ -364,9 +334,8 @@ for (let i = 0; i < gradientBorderInputs.length; i++) {
364
334
) ;
365
335
}
366
336
367
- //set gradient text preview
368
337
for ( let i = 0 ; i < gradientTextInputs . length ; i ++ ) {
369
- gradientTextInputs [ i ] . addEventListener ( 'input ' , ( ) =>
338
+ gradientTextInputs [ i ] . addEventListener ( 'change ' , ( ) =>
370
339
createGradientPreview (
371
340
gradientTextColor1 ,
372
341
gradientTextColor2 ,
@@ -376,20 +345,7 @@ for (let i = 0; i < gradientTextInputs.length; i++) {
376
345
) ;
377
346
}
378
347
379
- //create gradient preview
380
- const createGradientPreview = (
381
- color1 : HTMLInputElement ,
382
- color2 : HTMLInputElement ,
383
- range : HTMLInputElement ,
384
- preview : HTMLElement
385
- ) => {
386
- const colorFrom = color1 ?. value ;
387
- const colorTo = color2 ?. value ;
388
- const fill = range ?. value ;
389
- preview . style . background = `linear-gradient(${ fill } deg, ${ colorFrom } , ${ colorTo } )` ;
390
- } ;
391
-
392
348
//Toggle gradient border radius input display
393
- gradientBorderRadius . addEventListener ( 'change' , function ( ) {
394
- gradientBorderInput . style . display = this . checked ? " inline" : " none"
395
- } )
349
+ gradientBorderRadius . addEventListener ( 'change' , function ( ) {
350
+ gradientBorderInput . style . display = this . checked ? ' inline' : ' none' ;
351
+ } ) ;
0 commit comments