feat: add a wait before a notice can be accepted
This commit is contained in:
@@ -186,7 +186,8 @@
|
||||
'.heraldLink{color:var(--jf-palette-primary-main,#00a4dc);text-decoration:underline}',
|
||||
'.heraldFoot{flex:none;display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:.4em 1em;padding:.7em 1.7em 1.3em}',
|
||||
'.heraldError{flex:1 1 12em;margin:0;font-size:.9em;color:var(--jf-palette-error-main,#e2574c)}',
|
||||
'.heraldButton.heraldButton{flex:none;margin:0;min-width:8.5em;justify-content:center;text-align:center}',
|
||||
'.heraldButton.heraldButton{flex:none;margin:0;min-width:8.5em;justify-content:center;text-align:center;font-variant-numeric:tabular-nums}',
|
||||
'.heraldButton.heraldWaiting{opacity:.5;cursor:default}',
|
||||
'@media (max-width:30em){.heraldBackdrop{padding:.6em;align-items:flex-end}.heraldMast{padding:1.2em 1.2em 0}',
|
||||
'.heraldBody{padding:.8em 1.2em .2em}.heraldFoot{padding:.6em 1.2em 1.1em}.heraldButton.heraldButton{flex:1 1 100%}}',
|
||||
'@media (prefers-reduced-motion:reduce){.heraldBackdrop,.heraldSheet.heraldSheet{transition:none}}'
|
||||
@@ -228,6 +229,7 @@
|
||||
var backdrop = element('div', 'heraldBackdrop');
|
||||
// "dialog" and the button classes are jellyfin-web's own, so the active theme colors them.
|
||||
var sheet = element('div', 'heraldSheet dialog');
|
||||
sheet.tabIndex = -1;
|
||||
sheet.setAttribute('role', mustAccept ? 'alertdialog' : 'dialog');
|
||||
sheet.setAttribute('aria-modal', 'true');
|
||||
sheet.setAttribute('aria-labelledby', titleId);
|
||||
@@ -266,6 +268,7 @@
|
||||
button: button,
|
||||
error: error,
|
||||
sending: false,
|
||||
timer: null,
|
||||
previousFocus: document.activeElement,
|
||||
onKey: null
|
||||
};
|
||||
@@ -302,7 +305,45 @@
|
||||
backdrop.classList.add('heraldIn');
|
||||
});
|
||||
});
|
||||
button.focus();
|
||||
var wait = mustAccept ? Math.floor(Number(notice.AcceptDelaySeconds) || 0) : 0;
|
||||
if (wait > 0) {
|
||||
holdButton(state, wait);
|
||||
sheet.focus();
|
||||
} else {
|
||||
button.focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Keeps the button locked for the given number of seconds. Only time with the tab in view counts.
|
||||
function holdButton(state, seconds) {
|
||||
var button = state.button;
|
||||
var label = button.textContent;
|
||||
var left = seconds;
|
||||
|
||||
function paint() {
|
||||
button.textContent = label + ' (' + left + ')';
|
||||
}
|
||||
|
||||
button.disabled = true;
|
||||
button.classList.add('heraldWaiting');
|
||||
paint();
|
||||
|
||||
state.timer = setInterval(function () {
|
||||
if (document.hidden) {
|
||||
return;
|
||||
}
|
||||
left--;
|
||||
if (left > 0) {
|
||||
paint();
|
||||
return;
|
||||
}
|
||||
clearInterval(state.timer);
|
||||
state.timer = null;
|
||||
button.textContent = label;
|
||||
button.classList.remove('heraldWaiting');
|
||||
button.disabled = false;
|
||||
button.focus();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function keepFocusInside(e, sheet) {
|
||||
@@ -325,7 +366,7 @@
|
||||
}
|
||||
|
||||
function respond(state, action) {
|
||||
if (state.sending || open !== state) {
|
||||
if (state.sending || state.timer || open !== state) {
|
||||
return;
|
||||
}
|
||||
state.sending = true;
|
||||
@@ -361,6 +402,10 @@
|
||||
return;
|
||||
}
|
||||
open = null;
|
||||
if (state.timer) {
|
||||
clearInterval(state.timer);
|
||||
state.timer = null;
|
||||
}
|
||||
document.removeEventListener('keydown', state.onKey, true);
|
||||
if (state.backdrop.parentNode) {
|
||||
state.backdrop.parentNode.removeChild(state.backdrop);
|
||||
|
||||
Reference in New Issue
Block a user