8
8
getAllInputElements ,
9
9
getResultPage ,
10
10
getCopyCodeButton ,
11
- getAllFields ,
12
11
getResetButton ,
13
12
getDegreeSpanElement ,
13
+ getGradientPreview ,
14
14
} from '../lib/getElements' ;
15
15
import {
16
16
copyCodeToClipboard ,
@@ -39,6 +39,7 @@ const toggleRadiusInputForGradientBorder = getCheckbox(attribute);
39
39
const getOutputElement = getOutput ( attribute ) ;
40
40
41
41
const getDegreeElement = getRange ( attribute ) ;
42
+ const resetButton = getResetButton ( attribute ) ;
42
43
43
44
let gradientBorderInputs = getAllInputElements ( 'gradient-border' ) ;
44
45
@@ -124,6 +125,8 @@ export function addGradientBorderListener() {
124
125
function addEventListenerToTheNewColorPicker ( ) {
125
126
gradientBorderInputs = getAllInputElements ( attribute ) ;
126
127
inputEventListner ( ) ;
128
+ if ( resetButton . classList . contains ( 'reset-show' ) ) return ;
129
+ resetButton . classList . add ( 'reset-show' ) ;
127
130
}
128
131
129
132
function inputEventListner ( ) {
@@ -135,39 +138,46 @@ function inputEventListner() {
135
138
} ) ;
136
139
}
137
140
138
-
139
141
// reset the values of all target fields
140
-
141
142
function resetValues ( ) {
142
- const { inputs } = getAllFields ( attribute ) ;
143
+ const colorInput : HTMLInputElement [ ] = [ ... new Set ( [ ] ) ] ;
143
144
144
- getResetButton ( attribute ) . addEventListener ( "click" , ( ) => {
145
+ resetButton . addEventListener ( 'click' , ( ) => {
146
+ resetButton . classList . remove ( 'reset-show' ) ;
147
+ getDegreeSpanElement ( attribute ) . innerHTML = 'deg' ;
145
148
146
- inputs . forEach ( input => {
149
+ getGradientPreview ( attribute ) . style . background = '' ;
150
+
151
+ gradientBorderInputs . forEach ( ( input ) => {
152
+ input . checked = false ;
147
153
input . value = input . defaultValue ;
148
- input . checked = false
149
- } ) ;
150
154
151
- getDegreeSpanElement ( attribute ) . innerHTML = "deg" ;
152
- getResetButton ( attribute ) . classList . remove ( "reset-show" ) ;
153
- } )
155
+ if ( input . id . includes ( 'color' ) ) {
156
+ colorInput . push ( input ) ;
157
+ }
158
+ } ) ;
154
159
160
+ if ( colorInput . length > 2 ) {
161
+ for ( let i = 2 ; i < colorInput . length ; i ++ ) {
162
+ removeColorPicker ( attribute ) ;
163
+ }
164
+ }
165
+ } ) ;
155
166
}
156
167
157
168
// get values from all targets to get notified when values change.
158
169
159
170
function getValues ( ) {
160
-
161
- const { inputs } = getAllFields ( attribute ) ;
162
-
163
- inputs . forEach ( input => {
164
- input . addEventListener ( "input" , ( ) => {
165
- if ( ! input . checked ) getResetButton ( attribute ) . classList . remove ( "reset-show" ) ;
166
- if ( input . value !== "" || input . checked === true ) {
167
- getResetButton ( attribute ) . classList . add ( "reset-show" ) ;
168
- resetValues ( ) ;
171
+ gradientBorderInputs . forEach ( ( input ) => {
172
+ input . addEventListener ( 'input' , ( ) => {
173
+ if ( input . nodeName === 'TEXTAREA' ) {
174
+ if ( input . value === '' ) return ;
169
175
}
170
- } )
171
- } )
176
+
177
+ if ( resetButton . classList . contains ( 'reset-show' ) ) return ;
178
+ resetButton . classList . add ( 'reset-show' ) ;
179
+ } ) ;
180
+ } ) ;
172
181
}
173
- getValues ( ) ;
182
+ resetValues ( ) ;
183
+ getValues ( ) ;
0 commit comments