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
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 169
if ( data.auth_post_comments )
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 170
{
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 171
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 172
// Posting form
1
+ − 173
+ − 174
html += '<h3>Got something to say?</h3>';
+ − 175
html += '<p>If you have comments or suggestions on this article, you can shout it out here.';
+ − 176
if ( data.approval_needed )
+ − 177
html+=' Before your post will be visible to the public, a moderator will have to approve it.';
+ − 178
html += ' <a id="leave_comment_button" href="#" onclick="displayCommentForm(); return false;">Leave a comment...</a></p>';
+ − 179
html += '<div id="comment_form" style="display: none;">';
+ − 180
html += ' <table border="0">';
+ − 181
html += ' <tr><td>Your name/screen name:</td><td>';
+ − 182
if ( data.user_id > 1 ) html += data.username + '<input id="commentform_name" type="hidden" value="'+data.username+'" size="40" />';
+ − 183
else html += '<input id="commentform_name" type="text" size="40" />';
+ − 184
html += ' </td></tr>';
+ − 185
html += ' <tr><td>Comment subject:</td><td><input id="commentform_subject" type="text" size="40" /></td></tr>';
+ − 186
html += ' <tr><td>Comment:</td><td><textarea id="commentform_message" rows="15" cols="50"></textarea></td></tr>';
+ − 187
if ( !data.logged_in && data.guest_posting == '1' )
+ − 188
{
+ − 189
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>';
+ − 190
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 />';
+ − 191
html += ' Confirmation code: <input type="text" size="8" id="commentform_captcha" />';
+ − 192
html += ' <!-- This input is used to track the ID of the CAPTCHA image --> <input type="hidden" id="commentform_captcha_id" value="'+data.captcha+'" />';
+ − 193
html += ' </td></tr>';
+ − 194
}
+ − 195
html += ' <tr><td colspan="2" style="text-align: center;"><input type="button" onclick="submitComment();" value="Submit comment" /></td></tr>';
+ − 196
html += ' </table>';
+ − 197
html += '</div>';
+ − 198
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 199
}
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 200
1
+ − 201
document.getElementById('ajaxEditContainer').innerHTML = html;
+ − 202
+ − 203
for ( i = 0; i < data.comments.length; i++ )
+ − 204
{
+ − 205
document.getElementById('comment_source_'+i).value = data.comments[i].comment_source;
+ − 206
}
+ − 207
+ − 208
}
+ − 209
+ − 210
function displayCommentForm()
+ − 211
{
+ − 212
document.getElementById('leave_comment_button').style.display = 'none';
+ − 213
document.getElementById('comment_form').style.display = 'block';
+ − 214
}
+ − 215
+ − 216
function hideCommentForm()
+ − 217
{
+ − 218
document.getElementById('leave_comment_button').style.display = 'inline';
+ − 219
document.getElementById('comment_form').style.display = 'none';
+ − 220
}
+ − 221
+ − 222
function editComment(id, link)
+ − 223
{
+ − 224
var ctr = document.getElementById('subject_'+id);
+ − 225
var subj = trim(ctr.firstChild.nodeValue); // If there's a span in there that says 'unapproved', this eliminates it
+ − 226
ctr.innerHTML = '';
+ − 227
var ipt = document.createElement('input');
+ − 228
ipt.id = 'subject_edit_'+id;
+ − 229
ipt.value = subj;
+ − 230
ctr.appendChild(ipt);
+ − 231
+ − 232
var src = document.getElementById('comment_source_'+id).value;
+ − 233
var cmt = document.getElementById('comment_'+id);
+ − 234
cmt.innerHTML = '';
+ − 235
var ta = document.createElement('textarea');
+ − 236
ta.rows = '10';
+ − 237
ta.cols = '40';
+ − 238
ta.value = src;
+ − 239
ta.id = 'comment_edit_'+id;
+ − 240
cmt.appendChild(ta);
+ − 241
+ − 242
link.style.fontWeight = 'bold';
+ − 243
link.innerHTML = 'save';
+ − 244
link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; };
+ − 245
}
+ − 246
+ − 247
function saveComment(id, link)
+ − 248
{
+ − 249
var data = document.getElementById('comment_edit_'+id).value;
+ − 250
var subj = document.getElementById('subject_edit_'+id).value;
+ − 251
var div = document.getElementById('comment_holder_'+id);
+ − 252
var real_id = div.getElementsByTagName('input')[0]['value'];
+ − 253
var req = {
+ − 254
'mode' : 'edit',
+ − 255
'id' : real_id,
+ − 256
'local_id' : id,
+ − 257
'data' : data,
+ − 258
'subj' : subj
+ − 259
};
+ − 260
link.style.fontWeight = 'normal';
+ − 261
link.innerHTML = 'edit';
+ − 262
link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; };
+ − 263
ajaxComments(req);
+ − 264
}
+ − 265
+ − 266
function deleteComment(id)
+ − 267
{
+ − 268
//var c = confirm('Do you really want to delete this comment?');
+ − 269
//if(!c);
+ − 270
// return false;
+ − 271
var div = document.getElementById('comment_holder_'+id);
+ − 272
var real_id = div.getElementsByTagName('input')[0]['value'];
+ − 273
var req = {
+ − 274
'mode' : 'delete',
+ − 275
'id' : real_id,
+ − 276
'local_id' : id
+ − 277
};
+ − 278
ajaxComments(req);
+ − 279
}
+ − 280
+ − 281
function submitComment()
+ − 282
{
+ − 283
var name = document.getElementById('commentform_name').value;
+ − 284
var subj = document.getElementById('commentform_subject').value;
+ − 285
var text = document.getElementById('commentform_message').value;
+ − 286
if ( document.getElementById('commentform_captcha') )
+ − 287
{
+ − 288
var captcha_code = document.getElementById('commentform_captcha').value;
+ − 289
var captcha_id = document.getElementById('commentform_captcha_id').value;
+ − 290
}
+ − 291
else
+ − 292
{
+ − 293
var captcha_code = '';
+ − 294
var captcha_id = '';
+ − 295
}
+ − 296
var req = {
+ − 297
'mode' : 'submit',
+ − 298
'name' : name,
+ − 299
'subj' : subj,
+ − 300
'text' : text,
+ − 301
'captcha_code' : captcha_code,
+ − 302
'captcha_id' : captcha_id
+ − 303
};
+ − 304
ajaxComments(req);
+ − 305
}
+ − 306
+ − 307
function redrawComment(data)
+ − 308
{
+ − 309
if ( data.subj )
+ − 310
{
+ − 311
document.getElementById('subject_' + data.id).innerHTML = data.subj;
+ − 312
}
+ − 313
if ( data.approved && data.approved != '1' )
+ − 314
{
+ − 315
document.getElementById('subject_' + data.id).innerHTML += ' <span style="color: #D84308">(Unapproved)</span>';
+ − 316
}
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 317
if ( data.approved && ( typeof(data.approve_updated) == 'string' && data.approve_updated == 'yes' ) )
1
+ − 318
{
+ − 319
var appr = ( data.approved == '1' ) ? 'Unapprove' : 'Approve';
+ − 320
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
diff
changeset
+ − 321
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
+ − 322
// Update approval status
1
+ − 323
var p = document.getElementById('comment_status');
+ − 324
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
diff
changeset
+ − 325
1
+ − 326
if ( p.firstChild.nextSibling )
+ − 327
{
+ − 328
var span = p.firstChild.nextSibling;
+ − 329
var is = ( data.approved == '1' ) ? -1 : 1;
+ − 330
var n_unapp = parseInt(span.firstChild.nodeValue.split(' ')[0]) + is;
+ − 331
n_unapp = n_unapp + '';
+ − 332
}
+ − 333
else
+ − 334
{
+ − 335
var span = document.createElement('span');
+ − 336
p.innerHTML += ' ';
+ − 337
span.innerHTML = ' ';
+ − 338
span.style.color = '#D84308';
+ − 339
var n_unapp = '1';
+ − 340
p.appendChild(span);
+ − 341
}
+ − 342
span.innerHTML = n_unapp + ' of those are unapproved.';
+ − 343
if ( n_unapp == '0' )
+ − 344
p.removeChild(span);
+ − 345
}
+ − 346
if ( data.text )
+ − 347
{
+ − 348
document.getElementById('comment_' + data.id).innerHTML = data.text;
+ − 349
}
+ − 350
if ( data.src )
+ − 351
{
+ − 352
document.getElementById('comment_source_' + data.id).value = data.src;
+ − 353
}
+ − 354
}
+ − 355
+ − 356
function approveComment(id)
+ − 357
{
+ − 358
var div = document.getElementById('comment_holder_'+id);
+ − 359
var real_id = div.getElementsByTagName('input')[0]['value'];
+ − 360
var req = {
+ − 361
'mode' : 'approve',
+ − 362
'id' : real_id,
+ − 363
'local_id' : id
+ − 364
};
+ − 365
ajaxComments(req);
+ − 366
}
+ − 367
+ − 368
// Does the actual DOM object removal
+ − 369
function annihiliateComment(id) // Did I spell that right?
+ − 370
{
+ − 371
// Approved?
+ − 372
var p = document.getElementById('comment_status');
+ − 373
+ − 374
if(document.getElementById('comment_approve_'+id))
+ − 375
{
+ − 376
var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue;
+ − 377
if ( p.firstChild.nextSibling && appr == 'Approve' )
+ − 378
{
+ − 379
var span = p.firstChild.nextSibling;
+ − 380
var t = span.firstChild.nodeValue;
+ − 381
var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1;
+ − 382
if ( n_unapp == 0 )
+ − 383
p.removeChild(span);
+ − 384
else
+ − 385
span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' '));
+ − 386
}
+ − 387
}
+ − 388
+ − 389
var div = document.getElementById('comment_holder_'+id);
+ − 390
div.parentNode.removeChild(div);
+ − 391
var t = p.firstChild.nodeValue.split(' ');
+ − 392
t[2] = ( parseInt(t[2]) - 1 ) + '';
+ − 393
delete(t.toJSONString);
+ − 394
if ( t[2] == '1' )
+ − 395
{
+ − 396
t[1] = 'is';
+ − 397
t[3] = 'comment';
+ − 398
}
+ − 399
else
+ − 400
{
+ − 401
t[1] = 'are';
+ − 402
t[3] = 'comments';
+ − 403
}
+ − 404
t = implode(' ', t);
+ − 405
p.firstChild.nodeValue = t;
+ − 406
}
+ − 407
+ − 408
function materializeComment(data)
+ − 409
{
+ − 410
// Intelligently get an ID
+ − 411
+ − 412
var i = 0;
+ − 413
var brother;
+ − 414
while ( true )
+ − 415
{
+ − 416
var x = document.getElementById('comment_holder_'+i);
+ − 417
if(!x)
+ − 418
break;
+ − 419
brother = x;
+ − 420
i++;
+ − 421
}
+ − 422
+ − 423
var parser = new templateParser(comment_template);
+ − 424
var tplvars = new Object();
+ − 425
+ − 426
if ( data.approved != '1' && !data.auth_mod_comments )
+ − 427
return false;
+ − 428
+ − 429
tplvars.ID = i;
+ − 430
tplvars.DATETIME = data.time;
+ − 431
tplvars.SUBJECT = data.subject;
+ − 432
tplvars.DATA = data.comment_data;
+ − 433
tplvars.SIGNATURE = data.signature;
+ − 434
+ − 435
tplvars.NAME = data.name;
+ − 436
if ( data.user_id > 1 )
+ − 437
tplvars.NAME = '<a href="' + makeUrlNS('User', data.name) + '">' + data.name + '</a>';
+ − 438
+ − 439
if ( data.approved != '1' )
+ − 440
tplvars.SUBJECT += ' <span style="color: #D84308">(Unapproved)</span>';
+ − 441
+ − 442
// User level
+ − 443
tplvars.USER_LEVEL = 'Guest';
+ − 444
if ( data.user_level >= data.user_level_list.member ) tplvars.USER_LEVEL = 'Member';
+ − 445
if ( data.user_level >= data.user_level_list.mod ) tplvars.USER_LEVEL = 'Moderator';
+ − 446
if ( data.user_level >= data.user_level_list.admin ) tplvars.USER_LEVEL = 'Administrator';
+ − 447
+ − 448
// Send PM link
+ − 449
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 />':'';
+ − 450
+ − 451
// Add buddy link
+ − 452
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 />':'';
+ − 453
+ − 454
// Edit link
+ − 455
tplvars.EDIT_LINK='<a href="#edit_'+i+'" onclick="editComment(\''+i+'\', this); return false;" id="cmteditlink_'+i+'">edit</a>';
+ − 456
+ − 457
// Delete link
+ − 458
tplvars.DELETE_LINK='<a href="#delete_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">delete</a>';
+ − 459
+ − 460
// Moderation: (Un)approve link
+ − 461
var appr = ( data.approved == 1 ) ? 'Unapprove' : 'Approve';
+ − 462
tplvars.MOD_APPROVE_LINK='<a href="#approve_'+i+'" id="comment_approve_'+i+'" onclick="approveComment(\''+i+'\'); return false;">'+appr+'</a>';
+ − 463
+ − 464
// Moderation: Delete post link
+ − 465
tplvars.MOD_DELETE_LINK='<a href="#mod_del_'+i+'" onclick="deleteComment(\''+i+'\'); return false;">Delete</a>';
+ − 466
+ − 467
var tplbool = new Object();
+ − 468
+ − 469
tplbool.signature = ( data.signature == '' ) ? false : true;
+ − 470
tplbool.can_edit = ( data.auth_edit_comments && ( ( data.user_id == data.user_id && data.logged_in ) || data.auth_mod_comments ) );
+ − 471
tplbool.auth_mod = data.auth_mod_comments;
+ − 472
+ − 473
parser.assign_vars(tplvars);
+ − 474
parser.assign_bool(tplbool);
+ − 475
+ − 476
var div = document.createElement('div');
+ − 477
div.id = 'comment_holder_'+i;
+ − 478
+ − 479
div.innerHTML = '<input type="hidden" value="'+data.comment_id+'" /><input type="hidden" id="comment_source_'+i+'" />' + parser.run();
+ − 480
+ − 481
if ( brother )
+ − 482
{
+ − 483
brother.parentNode.insertBefore(div, brother.nextSibling);
+ − 484
}
+ − 485
else
+ − 486
{
+ − 487
// No comments in ajaxEditContainer, insert it after the header
+ − 488
var aec = document.getElementById("ajaxEditContainer");
+ − 489
aec.insertBefore(div, aec.firstChild.nextSibling.nextSibling);
+ − 490
}
+ − 491
+ − 492
document.getElementById('comment_source_'+i).value = data.comment_source;
+ − 493
+ − 494
var p = document.getElementById('comment_status');
+ − 495
var t = p.firstChild.nodeValue.split(' ');
+ − 496
var n = ( isNaN(parseInt(t[2])) ) ? 0 : parseInt(t[2]);
+ − 497
t[2] = ( n + 1 ) + '';
+ − 498
delete(t.toJSONString);
+ − 499
if ( t[2] == '1' )
+ − 500
{
+ − 501
t[1] = 'is';
+ − 502
t[3] = 'comment';
+ − 503
}
+ − 504
else
+ − 505
{
+ − 506
t[1] = 'are';
+ − 507
t[3] = 'comments';
+ − 508
}
+ − 509
t = implode(' ', t);
+ − 510
p.firstChild.nodeValue = t;
+ − 511
+ − 512
if(document.getElementById('comment_approve_'+i))
+ − 513
{
+ − 514
var appr = document.getElementById('comment_approve_'+i).firstChild.nodeValue;
+ − 515
if ( p.firstChild.nextSibling && appr == 'Approve' )
+ − 516
{
+ − 517
var span = p.firstChild.nextSibling;
+ − 518
var t = span.firstChild.nodeValue;
+ − 519
var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1;
+ − 520
if ( n_unapp == 0 )
+ − 521
p.removeChild(span);
+ − 522
else
+ − 523
span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' '));
+ − 524
}
+ − 525
else if ( appr == 'Approve' && !p.firstChild.nextSibling )
+ − 526
{
+ − 527
var span = document.createElement('span');
+ − 528
p.innerHTML += ' ';
+ − 529
span.innerHTML = '1 of those are unapproved.';
+ − 530
span.style.color = '#D84308';
+ − 531
var n_unapp = '1';
+ − 532
p.appendChild(span);
+ − 533
}
+ − 534
}
+ − 535
+ − 536
}
+ − 537
+ − 538
function htmlspecialchars(text)
+ − 539
{
+ − 540
text = text.replace(/</g, '<');
+ − 541
text = text.replace(/>/g, '>');
+ − 542
return text;
+ − 543
}
+ − 544
+ − 545
// Equivalent to PHP trim() function
+ − 546
function trim(text)
+ − 547
{
+ − 548
text = text.replace(/^([\s]+)/, '');
+ − 549
text = text.replace(/([\s]+)$/, '');
+ − 550
return text;
+ − 551
}
+ − 552
+ − 553
// Equivalent to PHP implode() function
+ − 554
function implode(chr, arr)
+ − 555
{
+ − 556
if ( typeof ( arr.toJSONString ) == 'function' )
+ − 557
delete(arr.toJSONString);
+ − 558
+ − 559
var ret = '';
+ − 560
var c = 0;
+ − 561
for ( var i in arr )
+ − 562
{
+ − 563
if(i=='toJSONString')continue;
+ − 564
if ( c > 0 )
+ − 565
ret += chr;
+ − 566
ret += arr[i];
+ − 567
c++;
+ − 568
}
+ − 569
return ret;
+ − 570
}
+ − 571
+ − 572
function nl2br(text)
+ − 573
{
+ − 574
var regex = new RegExp(unescape('%0A'), 'g');
+ − 575
return text.replace(regex, '<br />' + unescape('%0A'));
+ − 576
}
+ − 577