99 getRemoveNewColorButton ,
1010 getResultPage ,
1111 getSVGButton ,
12- getAllFields ,
1312 getResetButton ,
14- getDegreeSpanElement
13+ getDegreeSpanElement ,
14+ getGradientPreview ,
1515} from '../lib/getElements' ;
1616import {
1717 copyCodeToClipboard ,
@@ -39,6 +39,7 @@ const getNewColorButtonElement = getNewColorButton(attribute);
3939const getRemoveColorButtonElement = getRemoveNewColorButton ( attribute ) ;
4040
4141const getDegreeElement = getRange ( attribute ) ;
42+ const resetButton = getResetButton ( attribute ) ;
4243
4344function copyHandler ( ) {
4445 const outputElement = getOutput ( attribute ) ;
@@ -155,9 +156,12 @@ export function addGradientTextListener() {
155156
156157 setGradientDegreeValue ( getDegreeElement ) ;
157158}
159+
158160function addEventListenerToTheNewColorPicker ( ) {
159161 gradientTextInputs = getAllInputElements ( attribute ) ;
160162 inputEventListner ( ) ;
163+ if ( resetButton . classList . contains ( 'reset-show' ) ) return ;
164+ resetButton . classList . add ( 'reset-show' ) ;
161165}
162166
163167function inputEventListner ( ) {
@@ -169,44 +173,44 @@ function inputEventListner() {
169173}
170174
171175// reset the values of all target fields
172-
173176function resetValues ( ) {
174- const { inputs , textarea } = getAllFields ( attribute ) ;
177+ const colorInput : HTMLInputElement [ ] = [ ... new Set ( [ ] ) ] ;
175178
176- getResetButton ( attribute ) . addEventListener ( "click" , ( ) => {
177- inputs . forEach ( input => {
178- input . value = input . defaultValue ;
179- } )
179+ resetButton . addEventListener ( 'click' , ( ) => {
180+ resetButton . classList . remove ( 'reset-show' ) ;
181+ getDegreeSpanElement ( attribute ) . innerHTML = 'deg' ;
182+
183+ getGradientPreview ( attribute ) . style . background = '' ;
180184
181- textarea . value = textarea . defaultValue ;
185+ gradientTextInputs . forEach ( ( input ) => {
186+ input . value = input . defaultValue ;
182187
183- getDegreeSpanElement ( attribute ) . innerHTML = "deg" ;
184- getResetButton ( attribute ) . classList . remove ( "reset-show" ) ;
185- } )
188+ if ( input . id . includes ( 'color' ) ) {
189+ colorInput . push ( input ) ;
190+ }
191+ } ) ;
186192
193+ if ( colorInput . length > 2 ) {
194+ for ( let i = 2 ; i < colorInput . length ; i ++ ) {
195+ removeColorPicker ( attribute ) ;
196+ }
197+ }
198+ } ) ;
187199}
188200
189201// get values from all targets to get notified when values change.
190202
191203function getValues ( ) {
192-
193- const { inputs, textarea } = getAllFields ( attribute ) ;
194-
195-
196- inputs . forEach ( input => {
197- input . addEventListener ( "input" , ( ) => {
198- if ( input . value !== "" ) {
199- getResetButton ( attribute ) . classList . add ( "reset-show" ) ;
200- resetValues ( ) ;
204+ gradientTextInputs . forEach ( ( input ) => {
205+ input . addEventListener ( 'input' , ( ) => {
206+ if ( input . nodeName === 'TEXTAREA' ) {
207+ if ( input . value === '' ) return ;
201208 }
202- } )
203- } )
204209
205- textarea . addEventListener ( "input" , ( ) => {
206- if ( textarea . value !== "" ) {
207- resetValues ( )
208- getResetButton ( attribute ) . classList . add ( "reset-show" ) ;
209- }
210- } )
210+ if ( resetButton . classList . contains ( 'reset-show' ) ) return ;
211+ resetButton . classList . add ( 'reset-show' ) ;
212+ } ) ;
213+ } ) ;
211214}
212- getValues ( ) ;
215+ resetValues ( ) ;
216+ getValues ( ) ;
0 commit comments