Skip to content

Commit 1ffea42

Browse files
committed
#2 Stale the cache, reload and shows the feedback
1 parent 7887d41 commit 1ffea42

File tree

3 files changed

+72
-53
lines changed

3 files changed

+72
-53
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ You can stale the cache:
3030

3131
## Release
3232

33+
* 2021-09-04:
34+
* As [per request 2](https://github.com/ComboStrap/stale/issues/2), Make the cache stale, reload the page and shows the feedback
3335
* 2021-09-01:
3436
* Delete the [sitemap](https://www.dokuwiki.org/sitemap)
3537
* 2021-08-30:

plugin.info.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
base stale
22
author ComboStrap
33
email support@combostrap.com
4-
date 2021-09-01
4+
date 2021-09-04
55
name Stale plugin
66
desc Make the cache stale by by touching configuration files
77
url https://www.dokuwiki.org/plugin:stale

stale.js

+69-52
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,73 @@
11
/**
2-
* Call the plugin with ajax
3-
*
2+
* Add a click handler to the
3+
* element with the `plugin_stale` class
44
*/
55

6-
jQuery('.plugin_stale')
7-
.show()
8-
.click(function (e) {
9-
e.preventDefault();
10-
11-
// post the data
12-
jQuery.post(
13-
DOKU_BASE + 'lib/exe/ajax.php',
14-
{
15-
call: 'plugin_stale'
16-
},
17-
// Display feedback
18-
// https://api.jqueryui.com/dialog/
19-
function (result) {
20-
let dialogElement = jQuery(document.createElement('div'));
21-
dialogElement.html(result.message);
22-
23-
/**
24-
*
25-
* @param {any | JQuery} jElement
26-
*/
27-
let remove = function (jElement) {
28-
if (jElement.parent().length > 0) {
29-
jElement.dialog('close');
30-
jElement.remove();
31-
jQuery(document.activeElement).blur();
32-
}
33-
};
34-
35-
dialogElement.dialog({
36-
dialogClass: "stale-dialog",
37-
closeOnEscape: true,
38-
modal: true,
39-
open: function () {
40-
// close it after 2 seconds (toast)
41-
setTimeout(function () {
42-
remove(dialogElement)
43-
}, 2000);
44-
}
45-
});
46-
47-
// Close it if the user click
48-
jQuery(document).on("click", function () {
49-
remove(dialogElement)
50-
});
51-
52-
}
53-
);
54-
55-
});
6+
(function IIFE(){
7+
const queryParameterKey = "stale";
8+
jQuery('.plugin_stale')
9+
.show()
10+
.click(function (e) {
11+
e.preventDefault();
12+
// post the data
13+
jQuery.post(
14+
DOKU_BASE + 'lib/exe/ajax.php',
15+
{
16+
call: 'plugin_stale'
17+
},
18+
// Display feedback
19+
// https://api.jqueryui.com/dialog/
20+
function (result) {
21+
const actualUrl = new URL(window.location.href);
22+
actualUrl.searchParams.set(queryParameterKey,result.message);
23+
window.location.assign(actualUrl.toString());
24+
}
25+
);
26+
});
27+
jQuery(function(){
28+
29+
const actualUrl = new URL(window.location.href);
30+
if(actualUrl.searchParams.has(queryParameterKey)){
31+
32+
const sec = 10;
33+
const message = actualUrl.searchParams.get(queryParameterKey);
34+
let dialogElement = jQuery(document.createElement('div'));
35+
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>`);
36+
37+
/**
38+
*
39+
* @param {any | JQuery} jElement
40+
*/
41+
let remove = function (jElement) {
42+
if (jElement.parent().length > 0) {
43+
jElement.dialog('close');
44+
jElement.remove();
45+
jQuery(document.activeElement).blur();
46+
}
47+
};
48+
49+
dialogElement.dialog({
50+
dialogClass: "stale-dialog",
51+
closeOnEscape: true,
52+
modal: true,
53+
open: function () {
54+
// close it after 2 seconds (toast)
55+
setTimeout(function () {
56+
remove(dialogElement)
57+
}, sec*1000);
58+
}
59+
});
60+
61+
// Close it if the user click or press any key
62+
jQuery(document).on("click", function () {
63+
remove(dialogElement)
64+
});
65+
jQuery(document).on("keypress", function () {
66+
remove(dialogElement)
67+
});
68+
69+
}
70+
})
71+
})();
72+
5673

0 commit comments

Comments
 (0)