Overlay reorganised. Volume now stored in a global variable.

This commit is contained in:
Alexander Andreev 2022-01-21 22:49:02 +04:00
parent bc2d2f6e74
commit 72d6e835bb
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
1 changed files with 17 additions and 1 deletions

View File

@ -4,6 +4,7 @@ const image_formats = ["jpg", "jpeg", "gif", "png", "bmp", "webp"];
const overlay = document.getElementById("overlay");
let scale = 1;
let g_volume = 1.0;
function mousescroll(e) {
e.preventDefault();
@ -11,18 +12,33 @@ function mousescroll(e) {
e.target.style.transform = `scale(${scale})`;
}
function onvolumechange(e) {
g_volume = e.target.volume;
console.log("new ", e);
}
const ext_filter = (ext, pathname) => pathname.toLowerCase().endsWith(ext);
function to_overlay(eltyp, pathname) {
const div = document.createElement("div");
const el = document.createElement(eltyp);
const el_label = document.createElement("span");
el_label.textContent = decodeURI(pathname.substr(pathname.lastIndexOf("/") + 1));
if (eltyp !== "audio") el.addEventListener('wheel', mousescroll);
if (eltyp !== "img") el.autoplay = el.controls = true;
if (eltyp !== "img") {
el.autoplay = el.controls = true;
el.addEventListener("volumechange", onvolumechange);
el.volume = g_volume;
}
el.src = pathname;
overlay.appendChild(el);
overlay.appendChild(el_label);
// overlay.appendChild(div);
overlay.style.visibility = "visible";
}
document.getElementById("overlay").addEventListener("click", e => {
e.target.firstChild.remove();
e.target.firstChild.remove();
e.target.style.visibility = "hidden";
scale = 1;