-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstale.js
73 lines (64 loc) · 2.34 KB
/
stale.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Add a click handler to the
* element with the `plugin_stale` class
*/
(function IIFE(){
const queryParameterKey = "stale";
jQuery('.plugin_stale')
.show()
.click(function (e) {
e.preventDefault();
// post the data
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_stale'
},
// Display feedback
// https://api.jqueryui.com/dialog/
function (result) {
const actualUrl = new URL(window.location.href);
actualUrl.searchParams.set(queryParameterKey,result.message);
window.location.assign(actualUrl.toString());
}
);
});
jQuery(function(){
const actualUrl = new URL(window.location.href);
if(actualUrl.searchParams.has(queryParameterKey)){
const sec = 10;
const message = actualUrl.searchParams.get(queryParameterKey);
let dialogElement = jQuery(document.createElement('div'));
dialogElement.html(`<h3>Stale</h3><p>${message}</p><p>The page was reloaded.</p><p>Note: This window will close automatically after ${sec} second if you don't click or press any key.</p>`);
/**
*
* @param {any | JQuery} jElement
*/
let remove = function (jElement) {
if (jElement.parent().length > 0) {
jElement.dialog('close');
jElement.remove();
jQuery(document.activeElement).blur();
}
};
dialogElement.dialog({
dialogClass: "stale-dialog",
closeOnEscape: true,
modal: true,
open: function () {
// close it after 2 seconds (toast)
setTimeout(function () {
remove(dialogElement)
}, sec*1000);
}
});
// Close it if the user click or press any key
jQuery(document).on("click", function () {
remove(dialogElement)
});
jQuery(document).on("keypress", function () {
remove(dialogElement)
});
}
})
})();