author | Dan |
Tue, 03 Jul 2007 14:21:33 -0400 | |
changeset 41 | 7c7920b65f42 |
parent 29 | e5484a9e0818 |
child 74 | 68469a95658d |
permissions | -rw-r--r-- |
1 | 1 |
// Comments |
2 |
||
3 |
var comment_template = false; |
|
4 |
||
5 |
function ajaxComments(parms) { |
|
6 |
setAjaxLoading(); |
|
7 |
var pid = strToPageID(title); |
|
8 |
if(!parms) |
|
9 |
{ |
|
10 |
var parms = { |
|
11 |
'mode' : 'fetch' |
|
12 |
}; |
|
13 |
} |
|
14 |
parms.page_id = pid[0]; |
|
15 |
parms.namespace = pid[1]; |
|
16 |
if(comment_template) |
|
17 |
parms.have_template = true; |
|
18 |
parms = ajaxEscape(toJSONString(parms)); |
|
19 |
ajaxPost(stdAjaxPrefix+'&_mode=comments', 'data=' + parms, function() { |
|
20 |
if(ajax.readyState == 4) { |
|
21 |
unsetAjaxLoading(); |
|
22 |
selectButtonMajor('discussion'); |
|
23 |
unselectAllButtonsMinor(); |
|
24 |
// IE compatibility - doing ajax.responseText.substr() doesn't work |
|
25 |
var rsptxt = ajax.responseText + ''; |
|
26 |
if ( rsptxt.substr(0, 1) != '{' ) |
|
27 |
{ |
|
28 |
document.getElementById('ajaxEditContainer').innerHTML = '<p>Comment system Javascript runtime: invalid JSON response from server, response text:</p><pre>' + ajax.responseText + '</pre>'; |
|
29 |
return false; |
|
30 |
} |
|
31 |
var response = parseJSON(ajax.responseText); |
|
32 |
switch(response.mode) |
|
33 |
{ |
|
34 |
case 'fetch': |
|
35 |
document.getElementById('ajaxEditContainer').innerHTML = 'Rendering response...'; |
|
36 |
if(response.template) |
|
37 |
comment_template = response.template; |
|
38 |
setAjaxLoading(); |
|
39 |
renderComments(response); |
|
40 |
unsetAjaxLoading(); |
|
41 |
break; |
|
42 |
case 'redraw': |
|
43 |
redrawComment(response); |
|
44 |
break; |
|
45 |
case 'annihilate': |
|
46 |
annihiliateComment(response.id); |
|
47 |
break; |
|
48 |
case 'materialize': |
|
49 |
alert('Your comment has been posted. If it does not appear right away, it is probably awaiting approval.'); |
|
50 |
hideCommentForm(); |
|
51 |
materializeComment(response); |
|
52 |
break; |
|
53 |
case 'error': |
|
54 |
alert(response.error); |
|
55 |
break; |
|
56 |
default: |
|
57 |
alert(ajax.responseText); |
|
58 |
break; |
|
59 |
} |
|
60 |
} |
|
61 |
}); |
|
62 |
} |
|
63 |
||
64 |
function renderComments(data) |
|
65 |
{ |
|
66 |
||
67 |
var html = ''; |
|
68 |
||
69 |
// Header |
|
70 |
||
71 |
html += '<h3>Article Comments</h3>'; |
|
72 |
||
73 |
var ns = ( strToPageID(title)[1]=='Article' ) ? 'article' : ( strToPageID(title)[1].toLowerCase() ) + ' page'; |
|
74 |
||
75 |
// Counters |
|
76 |
if ( data.auth_mod_comments ) |
|
77 |
{ |
|
78 |
var cnt = ( data.auth_mod_comments ) ? data.count_total : data.count_appr; |
|
79 |
if ( cnt == 0 ) cnt = 'no'; |
|
80 |
var s = ( cnt == 1 ) ? '' : 's'; |
|
81 |
var is = ( cnt == 1 ) ? 'is' : 'are'; |
|
82 |
html += "<p id=\"comment_status\">There "+is+" " + cnt + " comment"+s+" on this "+ns+"."; |
|
83 |
if ( data.count_unappr > 0 ) |
|
84 |
{ |
|
85 |
html += ' <span style="color: #D84308">' + data.count_unappr + ' of those are unapproved.</span>'; |
|
86 |
} |
|
87 |
html += '</p>'; |
|
88 |
} |
|
89 |
else |
|
90 |
{ |
|
91 |
var cnt = data.count_appr; |
|
92 |
if ( cnt == 0 ) cnt = 'no'; |
|
93 |
var s = ( cnt == 1 ) ? '' : 's'; |
|
94 |
var is = ( cnt == 1 ) ? 'is' : 'are'; |
|
95 |
html += "<p id=\"comment_status\">There "+is+" " + cnt + " comment"+s+" on this "+ns+"."; |
|
96 |
if ( data.count_unappr > 0 ) |
|
97 |
{ |
|
98 |
var s = ( data.count_unappr == 1 ) ? '' : 's'; |
|
99 |
var is = ( data.count_unappr == 1 ) ? 'is' : 'are'; |
|
100 |
html += ' However, there '+is+' '+data.count_unappr+' additional comment'+s+' awaiting approval.'; |
|
101 |
} |
|
102 |
html += '</p>'; |
|
103 |
} |
|
104 |
||
105 |
// Comment display |
|
106 |
||
107 |
if ( data.count_total > 0 ) |
|
108 |
{ |
|
109 |
var parser = new templateParser(comment_template); |
|
110 |
for ( var i = 0; i < data.comments.length; i++ ) |
|
111 |
{ |
|
112 |
var tplvars = new Object(); |
|
113 |
||
114 |
if ( data.comments[i].approved != '1' && !data.auth_mod_comments ) |
|
115 |
continue; |
|
116 |
||
117 |
tplvars.ID = i; |
|
118 |
tplvars.DATETIME = data.comments[i].time; |
|
119 |
tplvars.SUBJECT = data.comments[i].subject; |
|
120 |
tplvars.DATA = data.comments[i].comment_data; |
|
121 |
tplvars.SIGNATURE = data.comments[i].signature; |
|
122 |
||
123 |
if ( data.comments[i].approved != '1' ) |
|
124 |
tplvars.SUBJECT += ' <span style="color: #D84308">(Unapproved)</span>'; |
|
125 |
||
126 |
// Name |
|
127 |
tplvars.NAME = data.comments[i].name; |
|
128 |
if ( data.comments[i].user_id > 1 ) |
|
129 |
tplvars.NAME = '<a href="' + makeUrlNS('User', data.comments[i].name) + '">' + data.comments[i].name + '</a>'; |
|
130 |
||
131 |
// User level |
|
132 |
tplvars.USER_LEVEL = 'Guest'; |
|
133 |
if ( data.comments[i].user_level >= data.user_level.member ) tplvars.USER_LEVEL = 'Member'; |
|
134 |
if ( data.comments[i].user_level >= data.user_level.mod ) tplvars.USER_LEVEL = 'Moderator'; |
|
135 |
if ( data.comments[i].user_level >= data.user_level.admin ) tplvars.USER_LEVEL = 'Administrator'; |
|
136 |
||
137 |
// Send PM link |
|
138 |
tplvars.SEND_PM_LINK=(data.comments[i].user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( data.comments[i].name.replace(/ /g, '_') )) +'">Send private message</a><br />':''; |
|
139 |
||
140 |
// Add buddy link |
|
141 |
tplvars.ADD_BUDDY_LINK=(data.comments[i].user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( data.comments[i].name.replace(/ /g, '_') )) +'">Add to buddy list</a><br />':''; |
|
142 |
||
143 |
// Edit link |
|
144 |
tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">edit</a>'; |
|
145 |
||
146 |
// Delete link |
|
147 |
tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">delete</a>'; |
|
148 |
||
149 |
// Moderation: (Un)approve link |
|
150 |
var appr = ( data.comments[i].approved == 1 ) ? 'Unapprove' : 'Approve'; |
|
151 |
tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>'; |
|
152 |
||
153 |
// Moderation: Delete post link |
|
154 |
tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">Delete</a>'; |
|
155 |
||
156 |
var tplbool = new Object(); |
|
157 |
||
158 |
tplbool.signature = ( data.comments[i].signature == '' ) ? false : true; |
|
159 |
tplbool.can_edit = ( data.auth_edit_comments && ( ( data.comments[i].user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) ); |
|
160 |
tplbool.auth_mod = data.auth_mod_comments; |
|
161 |
||
162 |
parser.assign_vars(tplvars); |
|
163 |
parser.assign_bool(tplbool); |
|
164 |
||
165 |
html += '<div id="comment_holder_' + i + '"><input type="hidden" value="'+data.comments[i].comment_id+'" /><input type="hidden" id="comment_source_'+i+'" />' + parser.run() + '</div>'; |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
// Posting form |
|
170 |
||
171 |
html += '<h3>Got something to say?</h3>'; |
|
172 |
html += '<p>If you have comments or suggestions on this article, you can shout it out here.'; |
|
173 |
if ( data.approval_needed ) |
|
174 |
html+=' Before your post will be visible to the public, a moderator will have to approve it.'; |
|
175 |
html += ' <a id="leave_comment_button" href="#" onclick="displayCommentForm(); return false;">Leave a comment...</a></p>'; |
|
176 |
html += '<div id="comment_form" style="display: none;">'; |
|
177 |
html += ' <table border="0">'; |
|
178 |
html += ' <tr><td>Your name/screen name:</td><td>'; |
|
179 |
if ( data.user_id > 1 ) html += data.username + '<input id="commentform_name" type="hidden" value="'+data.username+'" size="40" />'; |
|
180 |
else html += '<input id="commentform_name" type="text" size="40" />'; |
|
181 |
html += ' </td></tr>'; |
|
182 |
html += ' <tr><td>Comment subject:</td><td><input id="commentform_subject" type="text" size="40" /></td></tr>'; |
|
183 |
html += ' <tr><td>Comment:</td><td><textarea id="commentform_message" rows="15" cols="50"></textarea></td></tr>'; |
|
184 |
if ( !data.logged_in && data.guest_posting == '1' ) |
|
185 |
{ |
|
186 |
html += ' <tr><td>Visual confirmation:<br /><small>Please enter the confirmation code seen in the image on the right into the box. If you cannot read the code, please click on the image to generate a new one. This helps to prevent automated bot posting.</small></td><td>'; |
|
187 |
html += ' <img alt="CAPTCHA image" src="'+makeUrlNS('Special', 'Captcha/' + data.captcha)+'" onclick="this.src=\''+makeUrlNS('Special', 'Captcha/' + data.captcha)+'/\'+Math.floor(Math.random()*10000000);" style="cursor: pointer;" /><br />'; |
|
188 |
html += ' Confirmation code: <input type="text" size="8" id="commentform_captcha" />'; |
|
189 |
html += ' <!-- This input is used to track the ID of the CAPTCHA image --> <input type="hidden" id="commentform_captcha_id" value="'+data.captcha+'" />'; |
|
190 |
html += ' </td></tr>'; |
|
191 |
} |
|
192 |
html += ' <tr><td colspan="2" style="text-align: center;"><input type="button" onclick="submitComment();" value="Submit comment" /></td></tr>'; |
|
193 |
html += ' </table>'; |
|
194 |
html += '</div>'; |
|
195 |
||
196 |
document.getElementById('ajaxEditContainer').innerHTML = html; |
|
197 |
||
198 |
for ( i = 0; i < data.comments.length; i++ ) |
|
199 |
{ |
|
200 |
document.getElementById('comment_source_'+i).value = data.comments[i].comment_source; |
|
201 |
} |
|
202 |
||
203 |
} |
|
204 |
||
205 |
function displayCommentForm() |
|
206 |
{ |
|
207 |
document.getElementById('leave_comment_button').style.display = 'none'; |
|
208 |
document.getElementById('comment_form').style.display = 'block'; |
|
209 |
} |
|
210 |
||
211 |
function hideCommentForm() |
|
212 |
{ |
|
213 |
document.getElementById('leave_comment_button').style.display = 'inline'; |
|
214 |
document.getElementById('comment_form').style.display = 'none'; |
|
215 |
} |
|
216 |
||
217 |
function editComment(id, link) |
|
218 |
{ |
|
219 |
var ctr = document.getElementById('subject_'+id); |
|
220 |
var subj = trim(ctr.firstChild.nodeValue); // If there's a span in there that says 'unapproved', this eliminates it |
|
221 |
ctr.innerHTML = ''; |
|
222 |
var ipt = document.createElement('input'); |
|
223 |
ipt.id = 'subject_edit_'+id; |
|
224 |
ipt.value = subj; |
|
225 |
ctr.appendChild(ipt); |
|
226 |
||
227 |
var src = document.getElementById('comment_source_'+id).value; |
|
228 |
var cmt = document.getElementById('comment_'+id); |
|
229 |
cmt.innerHTML = ''; |
|
230 |
var ta = document.createElement('textarea'); |
|
231 |
ta.rows = '10'; |
|
232 |
ta.cols = '40'; |
|
233 |
ta.value = src; |
|
234 |
ta.id = 'comment_edit_'+id; |
|
235 |
cmt.appendChild(ta); |
|
236 |
||
237 |
link.style.fontWeight = 'bold'; |
|
238 |
link.innerHTML = 'save'; |
|
239 |
link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; }; |
|
240 |
} |
|
241 |
||
242 |
function saveComment(id, link) |
|
243 |
{ |
|
244 |
var data = document.getElementById('comment_edit_'+id).value; |
|
245 |
var subj = document.getElementById('subject_edit_'+id).value; |
|
246 |
var div = document.getElementById('comment_holder_'+id); |
|
247 |
var real_id = div.getElementsByTagName('input')[0]['value']; |
|
248 |
var req = { |
|
249 |
'mode' : 'edit', |
|
250 |
'id' : real_id, |
|
251 |
'local_id' : id, |
|
252 |
'data' : data, |
|
253 |
'subj' : subj |
|
254 |
}; |
|
255 |
link.style.fontWeight = 'normal'; |
|
256 |
link.innerHTML = 'edit'; |
|
257 |
link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; }; |
|
258 |
ajaxComments(req); |
|
259 |
} |
|
260 |
||
261 |
function deleteComment(id) |
|
262 |
{ |
|
263 |
//var c = confirm('Do you really want to delete this comment?'); |
|
264 |
//if(!c); |
|
265 |
// return false; |
|
266 |
var div = document.getElementById('comment_holder_'+id); |
|
267 |
var real_id = div.getElementsByTagName('input')[0]['value']; |
|
268 |
var req = { |
|
269 |
'mode' : 'delete', |
|
270 |
'id' : real_id, |
|
271 |
'local_id' : id |
|
272 |
}; |
|
273 |
ajaxComments(req); |
|
274 |
} |
|
275 |
||
276 |
function submitComment() |
|
277 |
{ |
|
278 |
var name = document.getElementById('commentform_name').value; |
|
279 |
var subj = document.getElementById('commentform_subject').value; |
|
280 |
var text = document.getElementById('commentform_message').value; |
|
281 |
if ( document.getElementById('commentform_captcha') ) |
|
282 |
{ |
|
283 |
var captcha_code = document.getElementById('commentform_captcha').value; |
|
284 |
var captcha_id = document.getElementById('commentform_captcha_id').value; |
|
285 |
} |
|
286 |
else |
|
287 |
{ |
|
288 |
var captcha_code = ''; |
|
289 |
var captcha_id = ''; |
|
290 |
} |
|
291 |
var req = { |
|
292 |
'mode' : 'submit', |
|
293 |
'name' : name, |
|
294 |
'subj' : subj, |
|
295 |
'text' : text, |
|
296 |
'captcha_code' : captcha_code, |
|
297 |
'captcha_id' : captcha_id |
|
298 |
}; |
|
299 |
ajaxComments(req); |
|
300 |
} |
|
301 |
||
302 |
function redrawComment(data) |
|
303 |
{ |
|
304 |
if ( data.subj ) |
|
305 |
{ |
|
306 |
document.getElementById('subject_' + data.id).innerHTML = data.subj; |
|
307 |
} |
|
308 |
if ( data.approved && data.approved != '1' ) |
|
309 |
{ |
|
310 |
document.getElementById('subject_' + data.id).innerHTML += ' <span style="color: #D84308">(Unapproved)</span>'; |
|
311 |
} |
|
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
312 |
if ( data.approved && ( typeof(data.approve_updated) == 'string' && data.approve_updated == 'yes' ) ) |
1 | 313 |
{ |
314 |
var appr = ( data.approved == '1' ) ? 'Unapprove' : 'Approve'; |
|
315 |
document.getElementById('comment_approve_'+data.id).innerHTML = appr; |
|
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
316 |
|
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
317 |
// Update approval status |
1 | 318 |
var p = document.getElementById('comment_status'); |
319 |
var count = p.firstChild.nodeValue.split(' ')[2]; |
|
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
320 |
|
1 | 321 |
if ( p.firstChild.nextSibling ) |
322 |
{ |
|
323 |
var span = p.firstChild.nextSibling; |
|
324 |
var is = ( data.approved == '1' ) ? -1 : 1; |
|
325 |
var n_unapp = parseInt(span.firstChild.nodeValue.split(' ')[0]) + is; |
|
326 |
n_unapp = n_unapp + ''; |
|
327 |
} |
|
328 |
else |
|
329 |
{ |
|
330 |
var span = document.createElement('span'); |
|
331 |
p.innerHTML += ' '; |
|
332 |
span.innerHTML = ' '; |
|
333 |
span.style.color = '#D84308'; |
|
334 |
var n_unapp = '1'; |
|
335 |
p.appendChild(span); |
|
336 |
} |
|
337 |
span.innerHTML = n_unapp + ' of those are unapproved.'; |
|
338 |
if ( n_unapp == '0' ) |
|
339 |
p.removeChild(span); |
|
340 |
} |
|
341 |
if ( data.text ) |
|
342 |
{ |
|
343 |
document.getElementById('comment_' + data.id).innerHTML = data.text; |
|
344 |
} |
|
345 |
if ( data.src ) |
|
346 |
{ |
|
347 |
document.getElementById('comment_source_' + data.id).value = data.src; |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
function approveComment(id) |
|
352 |
{ |
|
353 |
var div = document.getElementById('comment_holder_'+id); |
|
354 |
var real_id = div.getElementsByTagName('input')[0]['value']; |
|
355 |
var req = { |
|
356 |
'mode' : 'approve', |
|
357 |
'id' : real_id, |
|
358 |
'local_id' : id |
|
359 |
}; |
|
360 |
ajaxComments(req); |
|
361 |
} |
|
362 |
||
363 |
// Does the actual DOM object removal |
|
364 |
function annihiliateComment(id) // Did I spell that right? |
|
365 |
{ |
|
366 |
// Approved? |
|
367 |
var p = document.getElementById('comment_status'); |
|
368 |
||
369 |
if(document.getElementById('comment_approve_'+id)) |
|
370 |
{ |
|
371 |
var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue; |
|
372 |
if ( p.firstChild.nextSibling && appr == 'Approve' ) |
|
373 |
{ |
|
374 |
var span = p.firstChild.nextSibling; |
|
375 |
var t = span.firstChild.nodeValue; |
|
376 |
var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1; |
|
377 |
if ( n_unapp == 0 ) |
|
378 |
p.removeChild(span); |
|
379 |
else |
|
380 |
span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' ')); |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
var div = document.getElementById('comment_holder_'+id); |
|
385 |
div.parentNode.removeChild(div); |
|
386 |
var t = p.firstChild.nodeValue.split(' '); |
|
387 |
t[2] = ( parseInt(t[2]) - 1 ) + ''; |
|
388 |
delete(t.toJSONString); |
|
389 |
if ( t[2] == '1' ) |
|
390 |
{ |
|
391 |
t[1] = 'is'; |
|
392 |
t[3] = 'comment'; |
|
393 |
} |
|
394 |
else |
|
395 |
{ |
|
396 |
t[1] = 'are'; |
|
397 |
t[3] = 'comments'; |
|
398 |
} |
|
399 |
t = implode(' ', t); |
|
400 |
p.firstChild.nodeValue = t; |
|
401 |
} |
|
402 |
||
403 |
function materializeComment(data) |
|
404 |
{ |
|
405 |
// Intelligently get an ID |
|
406 |
||
407 |
var i = 0; |
|
408 |
var brother; |
|
409 |
while ( true ) |
|
410 |
{ |
|
411 |
var x = document.getElementById('comment_holder_'+i); |
|
412 |
if(!x) |
|
413 |
break; |
|
414 |
brother = x; |
|
415 |
i++; |
|
416 |
} |
|
417 |
||
418 |
var parser = new templateParser(comment_template); |
|
419 |
var tplvars = new Object(); |
|
420 |
||
421 |
if ( data.approved != '1' && !data.auth_mod_comments ) |
|
422 |
return false; |
|
423 |
||
424 |
tplvars.ID = i; |
|
425 |
tplvars.DATETIME = data.time; |
|
426 |
tplvars.SUBJECT = data.subject; |
|
427 |
tplvars.DATA = data.comment_data; |
|
428 |
tplvars.SIGNATURE = data.signature; |
|
429 |
||
430 |
tplvars.NAME = data.name; |
|
431 |
if ( data.user_id > 1 ) |
|
432 |
tplvars.NAME = '<a href="' + makeUrlNS('User', data.name) + '">' + data.name + '</a>'; |
|
433 |
||
434 |
if ( data.approved != '1' ) |
|
435 |
tplvars.SUBJECT += ' <span style="color: #D84308">(Unapproved)</span>'; |
|
436 |
||
437 |
// User level |
|
438 |
tplvars.USER_LEVEL = 'Guest'; |
|
439 |
if ( data.user_level >= data.user_level_list.member ) tplvars.USER_LEVEL = 'Member'; |
|
440 |
if ( data.user_level >= data.user_level_list.mod ) tplvars.USER_LEVEL = 'Moderator'; |
|
441 |
if ( data.user_level >= data.user_level_list.admin ) tplvars.USER_LEVEL = 'Administrator'; |
|
442 |
||
443 |
// Send PM link |
|
444 |
tplvars.SEND_PM_LINK=(data.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/Compose/To/' + ( data.name.replace(/ /g, '_') )) +'">Send private message</a><br />':''; |
|
445 |
||
446 |
// Add buddy link |
|
447 |
tplvars.ADD_BUDDY_LINK=(data.user_id>1)?'<a onclick="window.open(this.href); return false;" href="'+ makeUrlNS('Special', 'PrivateMessages/FriendList/Add/' + ( data.name.replace(/ /g, '_') )) +'">Add to buddy list</a><br />':''; |
|
448 |
||
449 |
// Edit link |
|
450 |
tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">edit</a>'; |
|
451 |
||
452 |
// Delete link |
|
453 |
tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">delete</a>'; |
|
454 |
||
455 |
// Moderation: (Un)approve link |
|
456 |
var appr = ( data.approved == 1 ) ? 'Unapprove' : 'Approve'; |
|
457 |
tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>'; |
|
458 |
||
459 |
// Moderation: Delete post link |
|
460 |
tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">Delete</a>'; |
|
461 |
||
462 |
var tplbool = new Object(); |
|
463 |
||
464 |
tplbool.signature = ( data.signature == '' ) ? false : true; |
|
465 |
tplbool.can_edit = ( data.auth_edit_comments && ( ( data.user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) ); |
|
466 |
tplbool.auth_mod = data.auth_mod_comments; |
|
467 |
||
468 |
parser.assign_vars(tplvars); |
|
469 |
parser.assign_bool(tplbool); |
|
470 |
||
471 |
var div = document.createElement('div'); |
|
472 |
div.id = 'comment_holder_'+i; |
|
473 |
||
474 |
div.innerHTML = '<input type="hidden" value="'+data.comment_id+'" /><input type="hidden" id="comment_source_'+i+'" />' + parser.run(); |
|
475 |
||
476 |
if ( brother ) |
|
477 |
{ |
|
478 |
brother.parentNode.insertBefore(div, brother.nextSibling); |
|
479 |
} |
|
480 |
else |
|
481 |
{ |
|
482 |
// No comments in ajaxEditContainer, insert it after the header |
|
483 |
var aec = document.getElementById("ajaxEditContainer"); |
|
484 |
aec.insertBefore(div, aec.firstChild.nextSibling.nextSibling); |
|
485 |
} |
|
486 |
||
487 |
document.getElementById('comment_source_'+i).value = data.comment_source; |
|
488 |
||
489 |
var p = document.getElementById('comment_status'); |
|
490 |
var t = p.firstChild.nodeValue.split(' '); |
|
491 |
var n = ( isNaN(parseInt(t[2])) ) ? 0 : parseInt(t[2]); |
|
492 |
t[2] = ( n + 1 ) + ''; |
|
493 |
delete(t.toJSONString); |
|
494 |
if ( t[2] == '1' ) |
|
495 |
{ |
|
496 |
t[1] = 'is'; |
|
497 |
t[3] = 'comment'; |
|
498 |
} |
|
499 |
else |
|
500 |
{ |
|
501 |
t[1] = 'are'; |
|
502 |
t[3] = 'comments'; |
|
503 |
} |
|
504 |
t = implode(' ', t); |
|
505 |
p.firstChild.nodeValue = t; |
|
506 |
||
507 |
if(document.getElementById('comment_approve_'+i)) |
|
508 |
{ |
|
509 |
var appr = document.getElementById('comment_approve_'+i).firstChild.nodeValue; |
|
510 |
if ( p.firstChild.nextSibling && appr == 'Approve' ) |
|
511 |
{ |
|
512 |
var span = p.firstChild.nextSibling; |
|
513 |
var t = span.firstChild.nodeValue; |
|
514 |
var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1; |
|
515 |
if ( n_unapp == 0 ) |
|
516 |
p.removeChild(span); |
|
517 |
else |
|
518 |
span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' ')); |
|
519 |
} |
|
520 |
else if ( appr == 'Approve' && !p.firstChild.nextSibling ) |
|
521 |
{ |
|
522 |
var span = document.createElement('span'); |
|
523 |
p.innerHTML += ' '; |
|
524 |
span.innerHTML = '1 of those are unapproved.'; |
|
525 |
span.style.color = '#D84308'; |
|
526 |
var n_unapp = '1'; |
|
527 |
p.appendChild(span); |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
} |
|
532 |
||
533 |
function htmlspecialchars(text) |
|
534 |
{ |
|
535 |
text = text.replace(/</g, '<'); |
|
536 |
text = text.replace(/>/g, '>'); |
|
537 |
return text; |
|
538 |
} |
|
539 |
||
540 |
// Equivalent to PHP trim() function |
|
541 |
function trim(text) |
|
542 |
{ |
|
543 |
text = text.replace(/^([\s]+)/, ''); |
|
544 |
text = text.replace(/([\s]+)$/, ''); |
|
545 |
return text; |
|
546 |
} |
|
547 |
||
548 |
// Equivalent to PHP implode() function |
|
549 |
function implode(chr, arr) |
|
550 |
{ |
|
551 |
if ( typeof ( arr.toJSONString ) == 'function' ) |
|
552 |
delete(arr.toJSONString); |
|
553 |
||
554 |
var ret = ''; |
|
555 |
var c = 0; |
|
556 |
for ( var i in arr ) |
|
557 |
{ |
|
558 |
if(i=='toJSONString')continue; |
|
559 |
if ( c > 0 ) |
|
560 |
ret += chr; |
|
561 |
ret += arr[i]; |
|
562 |
c++; |
|
563 |
} |
|
564 |
return ret; |
|
565 |
} |
|
566 |
||
567 |
function nl2br(text) |
|
568 |
{ |
|
569 |
var regex = new RegExp(unescape('%0A'), 'g'); |
|
570 |
return text.replace(regex, '<br />' + unescape('%0A')); |
|
571 |
} |
|
572 |