forked from dokufreaks/plugin-discussion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
99 lines (88 loc) · 2.38 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Javascript functionality for the discussion plugin
*/
/**
* Check if a field is blank
*/
function isBlank(s){
if ((s === null) || (s.length === 0)){
return true;
}
for (var i = 0; i < s.length; i++){
var c = s.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')){
return false;
}
}
return true;
}
/**
* Validate an input field
*/
function validate(form){
if(!form) return;
if (isBlank(form.name.value)){
form.name.focus();
form.name.style.backgroundColor = '#fcc';
return false;
} else {
form.name.style.backgroundColor = '#fff';
}
if (isBlank(form.mail.value) || form.mail.value.indexOf("@") == -1){
form.mail.focus();
form.mail.style.backgroundColor = '#fcc';
return false;
} else {
form.mail.style.backgroundColor = '#fff';
}
if (isBlank(form.text.value)){
form.text.focus();
form.text.style.borderColor = '#fcc';
return false;
}
}
/**
* AJAX preview
*
* @author Michael Klier <chi@chimeric.de>
*/
function discussion_ajax_preview() {
var $textarea = jQuery('#discussion__comment_text');
var comment = $textarea.val();
var $preview = jQuery('#discussion__comment_preview');
if (!comment) {
$preview.hide();
return;
}
$preview.html('<img src="'+DOKU_BASE+'lib/images/throbber.gif" />');
$preview.show();
jQuery.post(DOKU_BASE + 'lib/exe/ajax.php',
{
'call': 'discussion_preview',
'comment': comment
},
function (data) {
if (data === '') {
$preview.hide();
return;
}
$preview.html(data);
$preview.show();
$preview.css('visibility', 'visible');
$preview.css('display', 'inline');
}, 'html');
}
jQuery(function() {
// init toolbar
if(typeof window.initToolbar == 'function') {
initToolbar("discussion__comment_toolbar", "discussion__comment_text", toolbar);
}
// init preview button
jQuery('#discussion__btn_preview').click(discussion_ajax_preview);
// init field check
jQuery('#discussion__comment_form').submit(function() { return validate(this); });
// toggle section visibility
jQuery('#discussion__btn_toggle_visibility').click(function() {
jQuery('#comment_wrapper').toggle();
});
});