Internt_Programmirovanie_PI.../Lab4/web-site vite/js/GaleryFilling.js

31 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-21 12:37:22 +04:00
var imgContainer = document.getElementById('response-container')
function filling(line){
const Container =
`<button class="col-xxl-4 col-lg-6 col-12 p-0 btn mx-auto my-2 my-sm-4 p-0 bg-image rounded-8 PictureButton" data-bs-toggle="modal" data-bs-target="#imageModal">
<img src="` + line + `" class="rounded-8 width-100" alt="image">
</button>`
imgContainer.innerHTML += Container
}
function Fill(){
fetch('imgs.txt')
.then(response => response.text())
.then(data => {
readFile(data)
})
.catch(error => {
console.error('Ошибка:', error);
});
}
async function readFile(file) {
console.log(file);
const arr = file.split(/\r?\n/gm)
arr.map(line => filling(line))
console.log('done')
imgContainer.innerHTML += `
<button onclick="file.click()" type="button" class="col-xxl-4 col-lg-6 col-12 p-0 btn btn-dark mx-auto my-4 rounded-8 fw-bold fs-1 PictureButton">
+
</button>
<input id="file" type="file" hidden`
}