diff --git a/web/static/image/placeholder.png b/web/static/image/placeholder.png new file mode 100644 index 0000000..bf1d310 Binary files /dev/null and b/web/static/image/placeholder.png differ diff --git a/web/static/scripts/gallery.js b/web/static/scripts/gallery.js index 146f7f0..7fe1281 100644 --- a/web/static/scripts/gallery.js +++ b/web/static/scripts/gallery.js @@ -39,11 +39,6 @@ $(document).ready(function() { }); }); -const myModal = new bootstrap.Modal('#Wallpaper', { - keyboard: false -}); -myModal.show(); - function wallpaper(data) { $(".preloader").hide(); data = data.reverse(); @@ -51,32 +46,52 @@ function wallpaper(data) { for (let i = 0; i < data.length; i++, id++) { ids.push(data[i]); - if (ids.filter((item) => item.url === data[i].url).length > 1) { + if (ids.filter((item) => item['url'] === data[i]['url']).length > 1) { continue; } + let image = new Image(); + image.src = ids[id]['media_type'] === "video" ? + `https://img.youtube.com/vi/${ids[id]['url'].slice(30, 41)}/maxresdefault.jpg` : + ids[id]['url']; + + image.onload = function() { + if(image.width+image.height !== 210) { + $(`img[data-src="${image.src}"]`).attr("src", `${image.src}`); + } + } + if (ids[id]['media_type'] === "image") { $(".header-row").append(`
- ${ids[id]['title']} + ${ids[id]['title']}
`); } else { $(".header-row").append(` -
- - ${ids[id]['title']} - -
- `); +
+ + ${ids[id]['title']} + +
+ `); } } + let button_modal = document.querySelector(".header-row"); button_modal.addEventListener("click", function (event) { - let id = event.target.getAttribute("idi"); + if (event.target === button_modal) { + return; + } + + let id = event.target.getAttribute("id"); let img = document.querySelector(".modal-body"); let title = document.querySelector(".w-modal-title"); @@ -87,6 +102,7 @@ function wallpaper(data) { ids[id]['copyright'] = ids[id]['copyright'] === undefined ? "NASA" : ids[id]['copyright']; if (ids[id]['media_type'] === "image") { + title.innerHTML = ``; img.innerHTML = ` ${ids[id]['title']}

Author: ${ids[id]['copyright']}

@@ -94,27 +110,32 @@ function wallpaper(data) {

Explanation: ${ids[id]['explanation']}

`; - title.innerHTML = ``; setWallpaper.addEventListener("click", function () { wallpaperUpdate(ids[id]['hdurl']); }); } else { + title.innerHTML = ``; img.innerHTML = ` - + +

Author: ${ids[id]['copyright']}

Date of publication: ${ids[id]['date']}

Explanation: ${ids[id]['explanation']}

`; - title.innerHTML = ``; setWallpaper.addEventListener("click", function () { - wallpaperUpdate(`https://img.youtube.com/vi/${ids[id]['url'].slice(30,41)}/maxresdefault.jpg`); + wallpaperUpdate(`https://img.youtube.com/vi/${ids[id]['url'].slice(30, 41)}/maxresdefault.jpg`); }); } }); $(window).scroll(function () { - if (($(window).scrollTop() > $(document).height() - $(window).height() - 100)) { + if (($(window).scrollTop() > $(document).height() - $(window).height() - 100)) { $(".preloader").show(); $(window).off("scroll");