1- import { isEscapeKey , showErrorAlert } from './util.js' ;
1+ import { isEscapeKey , showErrorAlert , showPopupMessage } from './util.js' ;
22import { validateReset } from './form.js' ;
33import { sendData } from './api.js' ;
44
@@ -75,40 +75,6 @@ let slider = null;
7575let currentEffect = 'none' ;
7676let currentScale = parseFloat ( uploadScaleControlInput . value ) ;
7777
78- const showAlert = ( type ) => {
79- const fragment = document . querySelector ( `#${ type } ` ) . content ;
80- const alert = fragment . querySelector ( `.${ type } ` ) . cloneNode ( true ) ;
81- const alertCloseButton = alert . querySelector ( `.${ type } __button` ) ;
82-
83- const onDocumentKeydown = ( evt ) => {
84- if ( isEscapeKey ( evt ) ) {
85- evt . preventDefault ( ) ;
86- closeAlert ( ) ;
87- }
88- } ;
89-
90- const onDocumentClick = ( evt ) => {
91- if ( ! evt . target . closest ( `.${ type } __inner` ) ) {
92- closeAlert ( ) ;
93- }
94- } ;
95-
96- const onAlertCloseButtonClick = ( ) => {
97- closeAlert ( ) ;
98- } ;
99-
100- function closeAlert ( ) {
101- alert . remove ( ) ;
102- document . removeEventListener ( 'keydown' , onDocumentKeydown ) ;
103- document . removeEventListener ( 'click' , onDocumentClick ) ;
104- }
105-
106- alertCloseButton . addEventListener ( 'click' , onAlertCloseButtonClick ) ;
107- document . addEventListener ( 'keydown' , onDocumentKeydown ) ;
108- document . addEventListener ( 'click' , onDocumentClick ) ;
109- body . appendChild ( alert ) ;
110- } ;
111-
11278const applyFilterEffect = ( effect , value ) => `${ effectConfig [ effect ] ?. property } (${ parseFloat ( value ) } ${ effectConfig [ effect ] ?. unit } )` ;
11379
11480const applyTransformScale = ( value ) => `scale(${ parseFloat ( value ) / 100 } )` ;
@@ -124,11 +90,7 @@ const onScaleControlClick = (direction) => {
12490 uploadPreview . style . transform = applyTransformScale ( currentScale ) ;
12591} ;
12692
127- const onDocumentKeydownUpload = ( evt ) => {
128- if ( document . querySelector ( '.success' ) || document . querySelector ( '.error' ) ) {
129- return ;
130- }
131-
93+ const onDocumentKeydown = ( evt ) => {
13294 if ( isEscapeKey ( evt ) ) {
13395 evt . preventDefault ( ) ;
13496 closeUpload ( ) ;
@@ -147,10 +109,10 @@ const onFormSubmit = async (data) => {
147109
148110 if ( request ) {
149111 closeUpload ( ) ;
150- showAlert ( 'success' ) ;
112+ showPopupMessage ( 'success' ) ;
151113 }
152114 } catch {
153- showAlert ( 'error' ) ;
115+ showPopupMessage ( 'error' ) ;
154116 }
155117
156118 toggleSubmitButton ( false ) ;
@@ -229,7 +191,7 @@ const openUpload = () => {
229191 uploadOverlay . classList . remove ( 'hidden' ) ;
230192 checkEffectSliderVisibility ( 'none' ) ;
231193
232- document . addEventListener ( 'keydown' , onDocumentKeydownUpload ) ;
194+ document . addEventListener ( 'keydown' , onDocumentKeydown ) ;
233195 } else {
234196 showErrorAlert ( 'Неверный тип файла' ) ;
235197 }
@@ -258,7 +220,7 @@ function closeUpload() {
258220 body . classList . remove ( 'modal-open' ) ;
259221 uploadOverlay . classList . add ( 'hidden' ) ;
260222
261- document . removeEventListener ( 'keydown' , onDocumentKeydownUpload ) ;
223+ document . removeEventListener ( 'keydown' , onDocumentKeydown ) ;
262224}
263225
264226export { setUpload , onFormSubmit } ;
0 commit comments