Deploy: Fri May 15 14:02:26 UTC 2026
This commit is contained in:
commit
884ab01739
900 changed files with 23978 additions and 0 deletions
45
docs/static/scripts/notification.js
vendored
Normal file
45
docs/static/scripts/notification.js
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { registerElementHint } from "./tips.js";
|
||||
|
||||
const notificationBox = document.createElement('div');
|
||||
notificationBox.classList.add('notificationBox');
|
||||
|
||||
export async function showNotification(title, subtitle, time, hint) {
|
||||
if (!hint) {
|
||||
hint = headeri18n.notificationDefaultHint;
|
||||
}
|
||||
const notificationBox = document.createElement('div');
|
||||
notificationBox.classList.add('notificationBox');
|
||||
notificationBox.dataset.tip = hint;
|
||||
|
||||
const notificationTitle = document.createElement('h1');
|
||||
notificationTitle.innerHTML = title;
|
||||
|
||||
const notificationSubtitle = document.createElement('p');
|
||||
notificationSubtitle.innerHTML = subtitle;
|
||||
|
||||
notificationBox.appendChild(notificationTitle);
|
||||
notificationBox.appendChild(notificationSubtitle);
|
||||
document.querySelector('body').appendChild(notificationBox);
|
||||
|
||||
registerElementHint(notificationBox);
|
||||
|
||||
let clicked = false;
|
||||
|
||||
notificationBox.addEventListener('click', () => {
|
||||
hideNotification(notificationBox);
|
||||
})
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
notificationBox.classList.add('shown');
|
||||
});
|
||||
await new Promise(r => setTimeout(r, time));
|
||||
if (!clicked) {
|
||||
hideNotification(notificationBox);
|
||||
}
|
||||
}
|
||||
|
||||
async function hideNotification(notificationBox) {
|
||||
notificationBox.classList.remove('shown');
|
||||
await new Promise(r => setTimeout(r, 1000));
|
||||
notificationBox.remove();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue