forked from rDrama/rDrama
delay toast if user switches browser tab
parent
7426158eb4
commit
afcdf0fe57
|
@ -11,7 +11,7 @@ function getMessageFromJsonData(success, json) {
|
|||
return message;
|
||||
}
|
||||
|
||||
function showToast(success, message) {
|
||||
function actuallyShowToast(success, message) {
|
||||
const oldToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-' + (success ? 'error': 'success'))); // intentionally reversed here: this is the old toast
|
||||
oldToast.hide();
|
||||
let element = success ? "toast-post-success" : "toast-post-error";
|
||||
|
@ -23,6 +23,15 @@ function showToast(success, message) {
|
|||
bootstrap.Toast.getOrCreateInstance(document.getElementById(element)).show();
|
||||
}
|
||||
|
||||
function showToast(success, message) {
|
||||
if (document.hasFocus())
|
||||
actuallyShowToast(success, message)
|
||||
else
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
actuallyShowToast(success, message)
|
||||
}, {once : true})
|
||||
}
|
||||
|
||||
function createXhrWithFormKey(url, form=new FormData(), method='POST') {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open(method, url);
|
||||
|
|
Loading…
Reference in New Issue