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