forked from lupo49/plugin-enforcesummary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (61 loc) · 2.53 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
/*
enforcesummary plugin for DokuWiki
File: script.js
https://www.dokuwiki.org/plugin:enforcesummary
*/
jQuery(function() {
var $summary = jQuery('#edit__summary'); // get summary field
if (typeof $summary.val() == 'undefined') return;
// Minor Edit by default
// Parts copied from https://www.dokuwiki.org/tips:autominor
// Note: since DokuWiki 2020-10-13 snapshot, the id of minoredit checkbox
// has changed to "edit__minoredit" from "minoredit".
// We must find '#edit__minoredit" or '#minoredit' for compatibility.
var $minoredit = jQuery('#edit__minoredit,#minoredit');
var prv = jQuery('div.preview');
if (!prv[0] && JSINFO.plugin_enforcesummary.default_minoredit)
jQuery('#edit__minoredit,#minoredit').prop('checked', true);
// Parts copied from https://www.dokuwiki.org/tips:summary_enforcement
$summary.keyup(enforceSummary).focus(enforceSummary);
$minoredit.change(enforceSummary);
enforceSummary(); // summary may be there if we're previewing
});
function enforceSummary() {
var $summary = jQuery('#edit__summary'); // get summary field
var $minoredit = jQuery('#edit__minoredit,#minoredit');
var ckgd = jQuery( 'input[type="checkbox"][name="ckgdoku"]:checked' ).val();
var ckge = jQuery( 'input[type="checkbox"][name="ckgedit"]:checked' ).val();
var m_class, $savebutton;
if (typeof ckgd == 'string' || typeof ckge == 'string') {
$savebutton = jQuery('#save_button');
m_class = 'plugin_enforcesummary_missing';
} else {
$savebutton = jQuery('#edbtn__save');
m_class = 'missing'
}
var prv = jQuery('div.preview');
// always require summary, even when minor change option is checked
// if($summary.val().replace(/^\s+/,"") === '')
summary_filled = !($summary.val().replace(/^\s+/,'') === '');
minor_checked = $minoredit.is(':checked');
// set summary inputbox attribute
if (summary_filled) {
$summary.removeClass(m_class);
} else {
$summary.addClass(m_class);
}
// set save button attribute
save_ready = false;
if (JSINFO.plugin_enforcesummary.enforce_summary) {
if (summary_filled || minor_checked) save_ready = true;
}
if (JSINFO.plugin_enforcesummary.enforce_preview) {
if (prv[0]) { save_ready = true; }
else { save_ready = false; }
}
if (save_ready) {
$savebutton.removeAttr("disabled").css("color", "black");
} else {
$savebutton.attr("disabled", true).css("color", "#999");
}
}