# HG changeset patch
# User Dan
# Date 1193615849 14400
# Node ID 30b857a6b811aa64fda6c8db486b1584323ac653
# Parent 753dabeca1ee98abd00d3edcd9e9a3b328abb17d
Reworked comment system to not use HACKISH FIXES; AJAX comment framework is completely localized now
diff -r 753dabeca1ee -r 30b857a6b811 includes/clientside/static/comments.js
--- a/includes/clientside/static/comments.js Sun Oct 28 17:46:54 2007 -0400
+++ b/includes/clientside/static/comments.js Sun Oct 28 19:57:29 2007 -0400
@@ -48,7 +48,7 @@
annihiliateComment(response.id);
break;
case 'materialize':
- alert('Your comment has been posted. If it does not appear right away, it is probably awaiting approval.');
+ alert($lang.get('comment_msg_comment_posted'));
hideCommentForm();
materializeComment(response);
break;
@@ -70,36 +70,43 @@
// Header
- html += '
Article Comments
';
+ html += '' + $lang.get('comment_heading') + '
';
- var ns = ( strToPageID(title)[1]=='Article' ) ? 'article' : ( strToPageID(title)[1].toLowerCase() ) + ' page';
+ var ns = ENANO_PAGE_TYPE;
// Counters
if ( data.auth_mod_comments )
{
var cnt = ( data.auth_mod_comments ) ? data.count_total : data.count_appr;
- if ( cnt == 0 ) cnt = 'no';
- var s = ( cnt == 1 ) ? '' : 's';
- var is = ( cnt == 1 ) ? 'is' : 'are';
- html += "';
}
else
{
var cnt = data.count_appr;
- if ( cnt == 0 ) cnt = 'no';
- var s = ( cnt == 1 ) ? '' : 's';
- var is = ( cnt == 1 ) ? 'is' : 'are';
- html += "';
}
@@ -118,28 +125,28 @@
// Posting form
- html += 'Got something to say?
';
- html += 'If you have comments or suggestions on this article, you can shout it out here.';
+ html += '
' + $lang.get('comment_postform_title') + '
';
+ html += '' + $lang.get('comment_postform_blurb');
if ( data.approval_needed )
- html+=' Before your post will be visible to the public, a moderator will have to approve it.';
- html += '
';
+ html+=' ' + $lang.get('comment_postform_blurb_unapp');
+ html += ' ';
html += '';
@@ -171,7 +178,7 @@
tplvars.SIGNATURE = this_comment.signature;
if ( this_comment.approved != '1' )
- tplvars.SUBJECT += ' (Unapproved)';
+ tplvars.SUBJECT += ' ' + $lang.get('comment_msg_note_unapp') + '';
// Name
tplvars.NAME = this_comment.name;
@@ -179,29 +186,29 @@
tplvars.NAME = '' + this_comment.name + '';
// User level
- tplvars.USER_LEVEL = 'Guest';
- if ( this_comment.user_level >= data.user_level.member ) tplvars.USER_LEVEL = 'Member';
- if ( this_comment.user_level >= data.user_level.mod ) tplvars.USER_LEVEL = 'Moderator';
- if ( this_comment.user_level >= data.user_level.admin ) tplvars.USER_LEVEL = 'Administrator';
-
+ tplvars.USER_LEVEL = $lang.get('user_type_guest');
+ if ( this_comment.user_level >= data.user_level.member ) tplvars.USER_LEVEL = $lang.get('user_type_member');
+ if ( this_comment.user_level >= data.user_level.mod ) tplvars.USER_LEVEL = $lang.get('user_type_mod');
+ if ( this_comment.user_level >= data.user_level.admin ) tplvars.USER_LEVEL = $lang.get('user_type_admin');
+
// Send PM link
- tplvars.SEND_PM_LINK=(this_comment.user_id>1 && data.logged_in)?'Send private message
':'';
+ tplvars.SEND_PM_LINK=(this_comment.user_id>1)?'' + $lang.get('comment_btn_send_privmsg') + '
':'';
// Add buddy link
- tplvars.ADD_BUDDY_LINK=(this_comment.user_id>1 && data.logged_in && this_comment.is_buddy != 1)?'Add to buddy list
':'';
+ tplvars.ADD_BUDDY_LINK=(this_comment.user_id>1)?'' + $lang.get('comment_btn_add_buddy') + '
':'';
// Edit link
- tplvars.EDIT_LINK='edit';
+ tplvars.EDIT_LINK='' + $lang.get('comment_btn_edit') + '';
// Delete link
- tplvars.DELETE_LINK='delete';
+ tplvars.DELETE_LINK='' + $lang.get('comment_btn_delete') + '';
// Moderation: (Un)approve link
- var appr = ( this_comment.approved == 1 ) ? 'Unapprove' : 'Approve';
+ var appr = ( this_comment.approved == 1 ) ? $lang.get('comment_btn_mod_unapprove') : $lang.get('comment_btn_mod_approve');
tplvars.MOD_APPROVE_LINK='';
// Moderation: Delete post link
- tplvars.MOD_DELETE_LINK='Delete';
+ tplvars.MOD_DELETE_LINK='' + $lang.get('comment_btn_mod_delete') + '';
var tplbool = new Object();
@@ -255,7 +262,7 @@
cmt.appendChild(ta);
link.style.fontWeight = 'bold';
- link.innerHTML = 'save';
+ link.innerHTML = $lang.get('comment_btn_save');
link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); saveComment(id, this); return false; };
}
@@ -273,7 +280,7 @@
'subj' : subj
};
link.style.fontWeight = 'normal';
- link.innerHTML = 'edit';
+ link.innerHTML = $lang.get('comment_btn_edit');
link.onclick = function() { var id = this.id.substr(this.id.indexOf('_')+1); editComment(id, this); return false; };
ajaxComments(req);
}
@@ -282,7 +289,7 @@
{
if ( !shift )
{
- var c = confirm('Do you really want to delete this comment?');
+ var c = confirm($lang.get('comment_msg_delete_confirm'));
if(!c)
return false;
}
@@ -340,36 +347,17 @@
}
if ( data.approved && data.approved != '1' )
{
- document.getElementById('subject_' + data.id).innerHTML += ' (Unapproved)';
+ document.getElementById('subject_' + data.id).innerHTML += ' ' + $lang.get('comment_msg_note_unapp') + '';
}
if ( data.approved && ( typeof(data.approve_updated) == 'string' && data.approve_updated == 'yes' ) )
{
- var appr = ( data.approved == '1' ) ? 'Unapprove' : 'Approve';
+ var appr = ( data.approved == '1' ) ? $lang.get('comment_btn_mod_unapprove') : $lang.get('comment_btn_mod_approve');
document.getElementById('comment_approve_'+data.id).innerHTML = appr;
- // Update approval status
- var p = document.getElementById('comment_status');
- var count = p.firstChild.nodeValue.split(' ')[2];
-
- if ( p.firstChild.nextSibling )
- {
- var span = p.firstChild.nextSibling;
- var is = ( data.approved == '1' ) ? -1 : 1;
- var n_unapp = parseInt(span.firstChild.nodeValue.split(' ')[0]) + is;
- n_unapp = n_unapp + '';
- }
+ if ( data.approved == '1' )
+ comment_decrement_unapproval();
else
- {
- var span = document.createElement('span');
- p.innerHTML += ' ';
- span.innerHTML = ' ';
- span.style.color = '#D84308';
- var n_unapp = '1';
- p.appendChild(span);
- }
- span.innerHTML = n_unapp + ' of those are unapproved.';
- if ( n_unapp == '0' )
- p.removeChild(span);
+ comment_increment_unapproval();
}
if ( data.text )
{
@@ -396,41 +384,24 @@
// Does the actual DOM object removal
function annihiliateComment(id) // Did I spell that right?
{
- // Approved?
- var p = document.getElementById('comment_status');
-
+ var approved = true;
if(document.getElementById('comment_approve_'+id))
{
var appr = document.getElementById('comment_approve_'+id).firstChild.nodeValue;
- if ( p.firstChild.nextSibling && appr == 'Approve' )
+ if ( appr == $lang.get('comment_btn_mod_approve') )
{
- var span = p.firstChild.nextSibling;
- var t = span.firstChild.nodeValue;
- var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1;
- if ( n_unapp == 0 )
- p.removeChild(span);
- else
- span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' '));
+ approved = false;
}
}
var div = document.getElementById('comment_holder_'+id);
div.parentNode.removeChild(div);
- var t = p.firstChild.nodeValue.split(' ');
- t[2] = ( parseInt(t[2]) - 1 ) + '';
- delete(t.toJSONString);
- if ( t[2] == '1' )
+
+ // update approval status
+ if ( document.getElementById('comment_count_unapp_inner') && !approved )
{
- t[1] = 'is';
- t[3] = 'comment';
+ comment_decrement_unapproval();
}
- else
- {
- t[1] = 'are';
- t[3] = 'comments';
- }
- t = implode(' ', t);
- p.firstChild.nodeValue = t;
}
function materializeComment(data)
@@ -465,32 +436,32 @@
tplvars.NAME = '' + data.name + '';
if ( data.approved != '1' )
- tplvars.SUBJECT += ' (Unapproved)';
+ tplvars.SUBJECT += ' ' + $lang.get('comment_msg_note_unapp') + '';
// User level
- tplvars.USER_LEVEL = 'Guest';
- if ( data.user_level >= data.user_level_list.member ) tplvars.USER_LEVEL = 'Member';
- if ( data.user_level >= data.user_level_list.mod ) tplvars.USER_LEVEL = 'Moderator';
- if ( data.user_level >= data.user_level_list.admin ) tplvars.USER_LEVEL = 'Administrator';
+ tplvars.USER_LEVEL = $lang.get('user_type_guest');
+ if ( data.user_level >= data.user_level_list.member ) tplvars.USER_LEVEL = $lang.get('user_type_member');
+ if ( data.user_level >= data.user_level_list.mod ) tplvars.USER_LEVEL = $lang.get('user_type_mod');
+ if ( data.user_level >= data.user_level_list.admin ) tplvars.USER_LEVEL = $lang.get('user_type_admin');
// Send PM link
- tplvars.SEND_PM_LINK=(data.user_id>1)?'Send private message
':'';
+ tplvars.SEND_PM_LINK=(data.user_id>1)?'' + $lang.get('comment_btn_send_privmsg') + '
':'';
// Add buddy link
- tplvars.ADD_BUDDY_LINK=(data.user_id>1)?'Add to buddy list
':'';
+ tplvars.ADD_BUDDY_LINK=(data.user_id>1)?'' + $lang.get('comment_btn_add_buddy') + '
':'';
// Edit link
- tplvars.EDIT_LINK='edit';
+ tplvars.EDIT_LINK='' + $lang.get('comment_btn_edit') + '';
// Delete link
- tplvars.DELETE_LINK='delete';
+ tplvars.DELETE_LINK='' + $lang.get('comment_btn_delete') + '';
// Moderation: (Un)approve link
- var appr = ( data.approved == 1 ) ? 'Unapprove' : 'Approve';
+ var appr = ( data.approved == 1 ) ? $lang.get('comment_btn_mod_unapprove') : $lang.get('comment_btn_mod_approve');
tplvars.MOD_APPROVE_LINK='';
// Moderation: Delete post link
- tplvars.MOD_DELETE_LINK='Delete';
+ tplvars.MOD_DELETE_LINK='' + $lang.get('comment_btn_mod_delete') + '';
var tplbool = new Object();
@@ -519,50 +490,80 @@
document.getElementById('comment_source_'+i).value = data.comment_source;
- var p = document.getElementById('comment_status');
- var t = p.firstChild.nodeValue.split(' ');
- var n = ( isNaN(parseInt(t[2])) ) ? 0 : parseInt(t[2]);
- t[2] = ( n + 1 ) + '';
- delete(t.toJSONString);
- if ( t[2] == '1' )
- {
- t[1] = 'is';
- t[3] = 'comment';
+ var cnt = document.getElementById('comment_count_inner').innerHTML;
+ cnt = parseInt(cnt);
+ if ( isNaN(cnt) )
+ cnt = 0;
+
+ var subst = {
+ num_comments: cnt,
+ page_type: ENANO_PAGE_TYPE
}
- else
- {
- t[1] = 'are';
- t[3] = 'comments';
- }
- t = implode(' ', t);
- p.firstChild.nodeValue = t;
+
+ var count_msg = ( cnt == 0 ) ? $lang.get('comment_msg_count_zero', subst) : ( ( cnt == 1 ) ? $lang.get('comment_msg_count_one', subst) : $lang.get('comment_msg_count_plural', subst) );
+
+ document.getElementById('comment_status').firstChild.innerHTML = count_msg;
if(document.getElementById('comment_approve_'+i))
{
- var appr = document.getElementById('comment_approve_'+i).firstChild.nodeValue;
- if ( p.firstChild.nextSibling && appr == 'Approve' )
+ var is_unappr = document.getElementById('comment_approve_'+i).firstChild.nodeValue;
+ is_unappr = ( is_unappr == $lang.get('comment_btn_mod_approve') );
+ if ( is_unappr )
{
- var span = p.firstChild.nextSibling;
- var t = span.firstChild.nodeValue;
- var n_unapp = ( parseInt(t.split(' ')[0]) ) - 1;
- if ( n_unapp == 0 )
- p.removeChild(span);
- else
- span.firstChild.nodeValue = n_unapp + t.substr(t.indexOf(' '));
- }
- else if ( appr == 'Approve' && !p.firstChild.nextSibling )
- {
- var span = document.createElement('span');
- p.innerHTML += ' ';
- span.innerHTML = '1 of those are unapproved.';
- span.style.color = '#D84308';
- var n_unapp = '1';
- p.appendChild(span);
+ comment_increment_unapproval();
}
}
}
+function comment_decrement_unapproval()
+{
+ if ( document.getElementById('comment_count_unapp_inner') )
+ {
+ var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML);
+ if ( !isNaN(num_unapp) )
+ {
+ num_unapp = num_unapp - 1;
+ if ( num_unapp == 0 )
+ {
+ var p = document.getElementById('comment_status');
+ p.removeChild(p.childNodes[2]);
+ p.removeChild(p.childNodes[1]);
+ }
+ else
+ {
+ var count_msg = $lang.get('comment_msg_count_unapp_mod', { num_unapp: num_unapp });
+ document.getElementById('comment_count_unapp_inner').parentNode.innerHTML = count_msg;
+ }
+ }
+ }
+}
+
+function comment_increment_unapproval()
+{
+ if ( document.getElementById('comment_count_unapp_inner') )
+ {
+ var num_unapp = parseInt(document.getElementById('comment_count_unapp_inner').innerHTML);
+ if ( isNaN(num_unapp) )
+ num_unapp = 0;
+ num_unapp = num_unapp + 1;
+ var count_msg = $lang.get('comment_msg_count_unapp_mod', { num_unapp: num_unapp });
+ document.getElementById('comment_count_unapp_inner').parentNode.innerHTML = count_msg;
+ }
+ else
+ {
+ var count_msg = $lang.get('comment_msg_count_unapp_mod', { num_unapp: 1 });
+ var status = document.getElementById('comment_status');
+ if ( !status.childNodes[1] )
+ status.appendChild(document.createTextNode(' '));
+ var span = document.createElement('span');
+ span.id = 'comment_status_unapp';
+ span.style.color = '#D84308';
+ span.innerHTML = count_msg;
+ status.appendChild(span);
+ }
+}
+
function htmlspecialchars(text)
{
text = text.replace(/([\s\S]*?)\
- Moderation options: {MOD_APPROVE_LINK} {MOD_DELETE_LINK}
+ {lang:comment_lbl_mod_options} {MOD_APPROVE_LINK} {MOD_DELETE_LINK}
|