-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
81 lines (78 loc) · 2.79 KB
/
script.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
72
73
74
75
76
77
78
79
80
81
/**
* Delete Page Button plugin scripts
*
* @copyright (c) 2020 Damien Regad
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Damien Regad
*/
jQuery(function() {
// Get current template name, see action_plugin_deletepagebutton::addJsInfo()
// noinspection JSUnresolvedVariable
let template = JSINFO.deletepagebutton_template;
// jQuery selector for the Delete Page button
let selector;
switch (template) {
case 'bootstrap3':
selector = 'li.action a.deletepagebutton';
break;
// Default selector (from DokuWiki default template)
case 'dokuwiki':
default:
selector = '.deletepagebutton a';
}
let $button = jQuery(selector);
if ($button.length === 0) {
const urlGitHubNewIssue =
'https://github.com/dregad/dokuwiki-plugin-deletepagebutton/issues/new'
+ "?labels=bug"
+ "&title=Confirmation+dialog+not+working+with+" + template + "+template"
+ "&body=Please+provide+sample+HTML+for+the+*Delete+Page*+button";
console.warn(
"DokuWiki DeletePageButton plugin: Template '" + template + "' "
+ "is not fully supported (the Confirmation dialog will not work). "
+ "Please report the problem by clicking the following URL "
+ urlGitHubNewIssue
);
return;
}
$button.on('click', function(e) {
e.preventDefault();
let submit_url = this.href;
let $dialog = jQuery(
'<div><span>'
+ LANG.plugins.deletepagebutton.confirm
+ '</span></div>'
);
$dialog.dialog({
title: LANG.plugins.deletepagebutton.title,
resizable: true,
width: "auto",
height: "auto",
modal: true,
buttons: [
{
text: LANG.plugins.deletepagebutton.btn_ok,
click: function () {
$dialog.dialog("close");
console.log(submit_url);
window.location.href = submit_url
}
},
{
text: LANG.plugins.deletepagebutton.btn_cancel,
click: function () {
$dialog.dialog("close");
}
}
],
close: function () {
// remove the dialog's HTML
jQuery(this).remove();
// Due to the preventDefault() call, the "Delete page" span
// remains active when the dialog is closed, so we need to
// manually remove focus from it.
document.activeElement.blur();
}
});
});
});