75 lines
No EOL
2.1 KiB
JavaScript
75 lines
No EOL
2.1 KiB
JavaScript
import { class_ } from "./main.js";
|
|
|
|
export const wait = (ms) => {
|
|
return new Promise((res, rej) => {
|
|
setTimeout(res, ms);
|
|
});
|
|
}
|
|
|
|
export const fadeout = async (Selems, ms = 200, force = false) => {
|
|
var oldTrans = [];
|
|
if (!Array.isArray(Selems)) Selems = [Selems];
|
|
var elems = [];
|
|
for (let i = 0; i < Selems.length; i++) {
|
|
elems[i] = Selems[i] instanceof class_ ? Selems[i]._ : Selems[i];
|
|
oldTrans[i] = elems[i].style.transition;
|
|
elems[i].style.transition = `opacity ${ms}ms`;
|
|
if(force){
|
|
elems[i].style.opacity = "1";
|
|
elems[i].style.display = "";
|
|
}
|
|
}
|
|
await wait(10);
|
|
for (let i = 0; i < elems.length; i++) {
|
|
elems[i].style.opacity = "0";
|
|
}
|
|
await wait(ms);
|
|
for (let i = 0; i < elems.length; i++) {
|
|
elems[i].style.display = "none";
|
|
elems[i].style.transition = oldTrans[i];
|
|
}
|
|
}
|
|
export const fadein = async (Selems, ms = 200, force = false, display="") => {
|
|
var oldTrans = [];
|
|
if (!Array.isArray(Selems)) Selems = [Selems];
|
|
var elems = [];
|
|
for (let i = 0; i < Selems.length; i++) {
|
|
elems[i] = (Selems[i] instanceof class_) ? Selems[i]._ : Selems[i];
|
|
oldTrans[i] = elems[i].style.transition
|
|
elems[i].style.transition = `opacity ${ms}ms`;
|
|
elems[i].style.display = display;
|
|
if (force) {
|
|
elems[i].style.opacity = "0";
|
|
}
|
|
}
|
|
await wait(10);
|
|
for (let i = 0; i < elems.length; i++) {
|
|
elems[i].style.opacity = "1";
|
|
}
|
|
await wait(ms+1);
|
|
for (let i = 0; i < elems.length; i++) {
|
|
elems[i].style.transition = oldTrans[i];
|
|
}
|
|
}
|
|
|
|
var bStack = [];
|
|
export const subCancel = (callback) => {
|
|
bStack.push(callback);
|
|
return ()=>{
|
|
var id;
|
|
if ((id = bStack.indexOf(callback)) >= 0) {
|
|
bStack.splice(id, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
function back() {
|
|
if (bStack.length) {
|
|
bStack.pop()();
|
|
}
|
|
}
|
|
|
|
document.addEventListener("backbutton", back, false);
|
|
document.addEventListener('keyup', (e)=>{
|
|
if (e.code == "Escape")back();
|
|
}); |