equal
deleted
inserted
replaced
1 // Comments |
1 // Comments |
2 |
2 |
3 var comment_template = false; |
3 var comment_template = false; |
4 var comment_render_track = 0; |
4 var comment_render_track = 0; |
5 |
5 |
6 function ajaxComments(parms) |
6 window.ajaxComments = function(parms) |
7 { |
7 { |
|
8 load_component('l10n'); |
|
9 load_component('paginate'); |
|
10 load_component('template-compiler'); |
8 setAjaxLoading(); |
11 setAjaxLoading(); |
9 var pid = strToPageID(title); |
12 var pid = strToPageID(title); |
10 if(!parms) |
13 if(!parms) |
11 { |
14 { |
12 var parms = { |
15 var parms = { |
61 } |
64 } |
62 } |
65 } |
63 }); |
66 }); |
64 } |
67 } |
65 |
68 |
66 function renderComments(data) |
69 window.renderComments = function(data) |
67 { |
70 { |
68 |
71 |
69 var html = ''; |
72 var html = ''; |
70 |
73 |
71 // Header |
74 // Header |
252 ret += parser.run(); |
255 ret += parser.run(); |
253 ret += '</div>'; |
256 ret += '</div>'; |
254 return ret; |
257 return ret; |
255 } |
258 } |
256 |
259 |
257 function displayCommentForm() |
260 window.displayCommentForm = function() |
258 { |
261 { |
259 document.getElementById('leave_comment_button').style.display = 'none'; |
262 document.getElementById('leave_comment_button').style.display = 'none'; |
260 document.getElementById('comment_form').style.display = 'block'; |
263 document.getElementById('comment_form').style.display = 'block'; |
261 } |
264 } |
262 |
265 |
263 function hideCommentForm() |
266 window.hideCommentForm = function() |
264 { |
267 { |
265 document.getElementById('leave_comment_button').style.display = 'inline'; |
268 document.getElementById('leave_comment_button').style.display = 'inline'; |
266 document.getElementById('comment_form').style.display = 'none'; |
269 document.getElementById('comment_form').style.display = 'none'; |
267 } |
270 } |
268 |
271 |
269 function editComment(id, link) |
272 window.editComment = function(id, link) |
270 { |
273 { |
271 var ctr = document.getElementById('subject_'+id); |
274 var ctr = document.getElementById('subject_'+id); |
272 var subj = ( ctr.firstChild ) ? trim(ctr.firstChild.nodeValue) : ''; // If there's a span in there that says 'unapproved', this eliminates it |
275 var subj = ( ctr.firstChild ) ? trim(ctr.firstChild.nodeValue) : ''; // If there's a span in there that says 'unapproved', this eliminates it |
273 ctr.innerHTML = ''; |
276 ctr.innerHTML = ''; |
274 var ipt = document.createElement('input'); |
277 var ipt = document.createElement('input'); |
290 link.style.fontWeight = 'bold'; |
293 link.style.fontWeight = 'bold'; |
291 link.innerHTML = $lang.get('comment_btn_save'); |
294 link.innerHTML = $lang.get('comment_btn_save'); |
292 link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; }; |
295 link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; }; |
293 } |
296 } |
294 |
297 |
295 function saveComment(id, link) |
298 window.saveComment = function(id, link) |
296 { |
299 { |
297 var data = document.getElementById('comment_edit_'+id).value; |
300 var data = document.getElementById('comment_edit_'+id).value; |
298 var subj = document.getElementById('subject_edit_'+id).value; |
301 var subj = document.getElementById('subject_edit_'+id).value; |
299 var div = document.getElementById('comment_holder_'+id); |
302 var div = document.getElementById('comment_holder_'+id); |
300 var real_id = div.getElementsByTagName('input')[0]['value']; |
303 var real_id = div.getElementsByTagName('input')[0]['value']; |
309 link.innerHTML = $lang.get('comment_btn_edit'); |
312 link.innerHTML = $lang.get('comment_btn_edit'); |
310 link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; }; |
313 link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; }; |
311 ajaxComments(req); |
314 ajaxComments(req); |
312 } |
315 } |
313 |
316 |
314 function deleteComment(id) |
317 window.deleteComment = function(id) |
315 { |
318 { |
316 if ( !shift ) |
319 if ( !shift ) |
317 { |
320 { |
318 var c = confirm($lang.get('comment_msg_delete_confirm')); |
321 var c = confirm($lang.get('comment_msg_delete_confirm')); |
319 if(!c) |
322 if(!c) |
327 'local_id' : id |
330 'local_id' : id |
328 }; |
331 }; |
329 ajaxComments(req); |
332 ajaxComments(req); |
330 } |
333 } |
331 |
334 |
332 function submitComment() |
335 window.submitComment = function() |
333 { |
336 { |
334 var name = document.getElementById('commentform_name').value; |
337 var name = document.getElementById('commentform_name').value; |
335 var subj = document.getElementById('commentform_subject').value; |
338 var subj = document.getElementById('commentform_subject').value; |
336 var text = document.getElementById('commentform_message').value; |
339 var text = document.getElementById('commentform_message').value; |
337 if ( document.getElementById('commentform_captcha') ) |
340 if ( document.getElementById('commentform_captcha') ) |
363 'captcha_id' : captcha_id |
366 'captcha_id' : captcha_id |
364 }; |
367 }; |
365 ajaxComments(req); |
368 ajaxComments(req); |
366 } |
369 } |
367 |
370 |
368 function redrawComment(data) |
371 window.redrawComment = function(data) |
369 { |
372 { |
370 if ( data.subj ) |
373 if ( data.subj ) |
371 { |
374 { |
372 document.getElementById('subject_' + data.id).innerHTML = data.subj; |
375 document.getElementById('subject_' + data.id).innerHTML = data.subj; |
373 } |
376 } |
400 return false; |
403 return false; |
401 span.innerHTML = $lang.get('comment_msg_ip_address') + ' <a href="#rdns" onclick="ajaxReverseDNS(this); return false;">' + data.ip_addr + '</a>'; |
404 span.innerHTML = $lang.get('comment_msg_ip_address') + ' <a href="#rdns" onclick="ajaxReverseDNS(this); return false;">' + data.ip_addr + '</a>'; |
402 } |
405 } |
403 } |
406 } |
404 |
407 |
405 function approveComment(id) |
408 window.approveComment = function(id) |
406 { |
409 { |
407 var div = document.getElementById('comment_holder_'+id); |
410 var div = document.getElementById('comment_holder_'+id); |
408 var real_id = div.getElementsByTagName('input')[0]['value']; |
411 var real_id = div.getElementsByTagName('input')[0]['value']; |
409 var req = { |
412 var req = { |
410 'mode' : 'approve', |
413 'mode' : 'approve', |
413 }; |
416 }; |
414 ajaxComments(req); |
417 ajaxComments(req); |
415 } |
418 } |
416 |
419 |
417 // Does the actual DOM object removal |
420 // Does the actual DOM object removal |
418 function annihiliateComment(id) // Did I spell that right? |
421 window.annihiliateComment = function(id) // Did I spell that right? |
419 { |
422 { |
420 var approved = true; |
423 var approved = true; |
421 if(document.getElementById('comment_approve_'+id)) |
424 if(document.getElementById('comment_approve_'+id)) |
422 { |
425 { |
423 var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue; |
426 var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue; |
435 { |
438 { |
436 comment_decrement_unapproval(); |
439 comment_decrement_unapproval(); |
437 } |
440 } |
438 } |
441 } |
439 |
442 |
440 function materializeComment(data) |
443 window.materializeComment = function(data) |
441 { |
444 { |
442 // Intelligently get an ID |
445 // Intelligently get an ID |
443 |
446 |
444 var i = 0; |
447 var i = 0; |
445 var brother; |
448 var brother; |
559 } |
562 } |
560 } |
563 } |
561 |
564 |
562 } |
565 } |
563 |
566 |
564 function comment_decrement_unapproval() |
567 window.comment_decrement_unapproval = function() |
565 { |
568 { |
566 if ( document.getElementById('comment_count_unapp_inner') ) |
569 if ( document.getElementById('comment_count_unapp_inner') ) |
567 { |
570 { |
568 var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML); |
571 var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML); |
569 if ( !isNaN(num_unapp) ) |
572 if ( !isNaN(num_unapp) ) |
582 } |
585 } |
583 } |
586 } |
584 } |
587 } |
585 } |
588 } |
586 |
589 |
587 function comment_increment_unapproval() |
590 window.comment_increment_unapproval = function() |
588 { |
591 { |
589 if ( document.getElementById('comment_count_unapp_inner') ) |
592 if ( document.getElementById('comment_count_unapp_inner') ) |
590 { |
593 { |
591 var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML); |
594 var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML); |
592 if ( isNaN(num_unapp) ) |
595 if ( isNaN(num_unapp) ) |
607 span.innerHTML = count_msg; |
610 span.innerHTML = count_msg; |
608 status.appendChild(span); |
611 status.appendChild(span); |
609 } |
612 } |
610 } |
613 } |
611 |
614 |
612 function viewCommentIP(id, local_id) |
615 window.viewCommentIP = function(id, local_id) |
613 { |
616 { |
614 // set "loading" indicator on IP button |
617 // set "loading" indicator on IP button |
615 var span = $dynano('comment_ip_' + local_id).object; |
618 var span = $dynano('comment_ip_' + local_id).object; |
616 if ( !span ) |
619 if ( !span ) |
617 return false; |
620 return false; |
623 local_id: local_id |
626 local_id: local_id |
624 } |
627 } |
625 ajaxComments(parms); |
628 ajaxComments(parms); |
626 } |
629 } |
627 |
630 |
628 function htmlspecialchars(text) |
|
629 { |
|
630 text = text.replace(/</g, '<'); |
|
631 text = text.replace(/>/g, '>'); |
|
632 return text; |
|
633 } |
|
634 |
|
635 // Equivalent to PHP trim() function |
|
636 function trim(text) |
|
637 { |
|
638 text = text.replace(/^([\s]+)/, ''); |
|
639 text = text.replace(/([\s]+)$/, ''); |
|
640 return text; |
|
641 } |
|
642 |
|
643 // Equivalent to PHP implode() function |
|
644 function implode(chr, arr) |
|
645 { |
|
646 if ( typeof ( arr.toJSONString ) == 'function' ) |
|
647 delete(arr.toJSONString); |
|
648 |
|
649 var ret = ''; |
|
650 var c = 0; |
|
651 for ( var i in arr ) |
|
652 { |
|
653 if(i=='toJSONString')continue; |
|
654 if ( c > 0 ) |
|
655 ret += chr; |
|
656 ret += arr[i]; |
|
657 c++; |
|
658 } |
|
659 return ret; |
|
660 } |
|
661 |
|
662 function nl2br(text) |
|
663 { |
|
664 var regex = new RegExp(unescape('%0A'), 'g'); |
|
665 return text.replace(regex, '<br />' + unescape('%0A')); |
|
666 } |
|
667 |
|