Skip to content

Commit

Permalink
Сделал дз 13
Browse files Browse the repository at this point in the history
  • Loading branch information
generalofgotei committed Jan 19, 2025
1 parent 0c320ee commit ee465f8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
File renamed without changes.
18 changes: 18 additions & 0 deletions js/image-upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const FILE_TYPES = ['jpg', 'jpeg', 'png'];

const fileChooser = document.querySelector('.img-upload__input');
const preview = document.querySelector('.img-upload__preview img');

const setupUploadEventListener = () => {
fileChooser.addEventListener('change', () => {
const file = fileChooser.files[0];
const fileName = file.name.toLowerCase();

const matches = FILE_TYPES.some((it) => fileName.endsWith(it));

if (matches) {
preview.src = URL.createObjectURL(file);
}
});
};
export { setupUploadEventListener };
4 changes: 3 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getData } from './api.js';
import { renderGallery, setupFilterListeners } from './thumbnails.js';
import { setupPictureEventListeners } from './photo-modal.js';
import { setupPictureEventListeners } from './image-modal.js';
import { setupUploadEventListener } from './image-upload.js';
import { setupFormEventListeners } from './form.js';
import { showGetErrorAlert } from './util.js';

Expand All @@ -17,4 +18,5 @@ async function initializeGallery() {
}

initializeGallery();
setupUploadEventListener();
setupFormEventListeners();
2 changes: 1 addition & 1 deletion js/thumbnails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupPictureEventListeners } from './photo-modal.js';
import { setupPictureEventListeners } from './image-modal.js';
import { debounce } from './util.js';

const MAX_RANDOM_QTY = 10;
Expand Down

0 comments on commit ee465f8

Please sign in to comment.