Chris@76
|
1 var cur_topic_id, cur_msg_id, buff_subject, cur_subject_div, in_edit_mode = 0;
|
Chris@76
|
2 var hide_prefixes = Array();
|
Chris@76
|
3
|
Chris@76
|
4 function modify_topic(topic_id, first_msg_id)
|
Chris@76
|
5 {
|
Chris@76
|
6 if (!('XMLHttpRequest' in window))
|
Chris@76
|
7 return;
|
Chris@76
|
8
|
Chris@76
|
9 if ('opera' in window)
|
Chris@76
|
10 {
|
Chris@76
|
11 var oTest = new XMLHttpRequest();
|
Chris@76
|
12 if (!('setRequestHeader' in oTest))
|
Chris@76
|
13 return;
|
Chris@76
|
14 }
|
Chris@76
|
15
|
Chris@76
|
16 // Add backwards compatibility with old themes.
|
Chris@76
|
17 if (typeof(cur_session_var) == 'undefined')
|
Chris@76
|
18 cur_session_var = 'sesc';
|
Chris@76
|
19
|
Chris@76
|
20 if (in_edit_mode == 1)
|
Chris@76
|
21 {
|
Chris@76
|
22 if (cur_topic_id == topic_id)
|
Chris@76
|
23 return;
|
Chris@76
|
24 else
|
Chris@76
|
25 modify_topic_cancel();
|
Chris@76
|
26 }
|
Chris@76
|
27
|
Chris@76
|
28 in_edit_mode = 1;
|
Chris@76
|
29 mouse_on_div = 1;
|
Chris@76
|
30 cur_topic_id = topic_id;
|
Chris@76
|
31
|
Chris@76
|
32 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
33 ajax_indicator(true);
|
Chris@76
|
34 getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "action=quotefast;quote=" + first_msg_id + ";modify;xml", onDocReceived_modify_topic);
|
Chris@76
|
35 }
|
Chris@76
|
36
|
Chris@76
|
37 function onDocReceived_modify_topic(XMLDoc)
|
Chris@76
|
38 {
|
Chris@76
|
39 cur_msg_id = XMLDoc.getElementsByTagName("message")[0].getAttribute("id");
|
Chris@76
|
40
|
Chris@76
|
41 cur_subject_div = document.getElementById('msg_' + cur_msg_id.substr(4));
|
Chris@76
|
42 buff_subject = getInnerHTML(cur_subject_div);
|
Chris@76
|
43
|
Chris@76
|
44 // Here we hide any other things they want hiding on edit.
|
Chris@76
|
45 set_hidden_topic_areas('none');
|
Chris@76
|
46
|
Chris@76
|
47 modify_topic_show_edit(XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue);
|
Chris@76
|
48 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
49 ajax_indicator(false);
|
Chris@76
|
50 }
|
Chris@76
|
51
|
Chris@76
|
52 function modify_topic_cancel()
|
Chris@76
|
53 {
|
Chris@76
|
54 setInnerHTML(cur_subject_div, buff_subject);
|
Chris@76
|
55 set_hidden_topic_areas('');
|
Chris@76
|
56
|
Chris@76
|
57 in_edit_mode = 0;
|
Chris@76
|
58 return false;
|
Chris@76
|
59 }
|
Chris@76
|
60
|
Chris@76
|
61 function modify_topic_save(cur_session_id, cur_session_var)
|
Chris@76
|
62 {
|
Chris@76
|
63 if (!in_edit_mode)
|
Chris@76
|
64 return true;
|
Chris@76
|
65
|
Chris@76
|
66 // Add backwards compatibility with old themes.
|
Chris@76
|
67 if (typeof(cur_session_var) == 'undefined')
|
Chris@76
|
68 cur_session_var = 'sesc';
|
Chris@76
|
69
|
Chris@76
|
70 var i, x = new Array();
|
Chris@76
|
71 x[x.length] = 'subject=' + document.forms.quickModForm['subject'].value.replace(/&#/g, "&#").php_to8bit().php_urlencode();
|
Chris@76
|
72 x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value);
|
Chris@76
|
73 x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value);
|
Chris@76
|
74
|
Chris@76
|
75 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
76 ajax_indicator(true);
|
Chris@76
|
77 sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements['topic'].value) + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), modify_topic_done);
|
Chris@76
|
78
|
Chris@76
|
79 return false;
|
Chris@76
|
80 }
|
Chris@76
|
81
|
Chris@76
|
82 function modify_topic_done(XMLDoc)
|
Chris@76
|
83 {
|
Chris@76
|
84 if (!XMLDoc)
|
Chris@76
|
85 {
|
Chris@76
|
86 modify_topic_cancel();
|
Chris@76
|
87 return true;
|
Chris@76
|
88 }
|
Chris@76
|
89
|
Chris@76
|
90 var message = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("message")[0];
|
Chris@76
|
91 var subject = message.getElementsByTagName("subject")[0];
|
Chris@76
|
92 var error = message.getElementsByTagName("error")[0];
|
Chris@76
|
93
|
Chris@76
|
94 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
95 ajax_indicator(false);
|
Chris@76
|
96
|
Chris@76
|
97 if (!subject || error)
|
Chris@76
|
98 return false;
|
Chris@76
|
99
|
Chris@76
|
100 subjectText = subject.childNodes[0].nodeValue;
|
Chris@76
|
101
|
Chris@76
|
102 modify_topic_hide_edit(subjectText);
|
Chris@76
|
103
|
Chris@76
|
104 set_hidden_topic_areas('');
|
Chris@76
|
105
|
Chris@76
|
106 in_edit_mode = 0;
|
Chris@76
|
107
|
Chris@76
|
108 return false;
|
Chris@76
|
109 }
|
Chris@76
|
110
|
Chris@76
|
111 // Simply restore any hidden bits during topic editing.
|
Chris@76
|
112 function set_hidden_topic_areas(set_style)
|
Chris@76
|
113 {
|
Chris@76
|
114 for (var i = 0; i < hide_prefixes.length; i++)
|
Chris@76
|
115 {
|
Chris@76
|
116 if (document.getElementById(hide_prefixes[i] + cur_msg_id.substr(4)) != null)
|
Chris@76
|
117 document.getElementById(hide_prefixes[i] + cur_msg_id.substr(4)).style.display = set_style;
|
Chris@76
|
118 }
|
Chris@76
|
119 }
|
Chris@76
|
120
|
Chris@76
|
121 // *** QuickReply object.
|
Chris@76
|
122 function QuickReply(oOptions)
|
Chris@76
|
123 {
|
Chris@76
|
124 this.opt = oOptions;
|
Chris@76
|
125 this.bCollapsed = this.opt.bDefaultCollapsed;
|
Chris@76
|
126 }
|
Chris@76
|
127
|
Chris@76
|
128 // When a user presses quote, put it in the quick reply box (if expanded).
|
Chris@76
|
129 QuickReply.prototype.quote = function (iMessageId, xDeprecated)
|
Chris@76
|
130 {
|
Chris@76
|
131 // Compatibility with older templates.
|
Chris@76
|
132 if (typeof(xDeprecated) != 'undefined')
|
Chris@76
|
133 return true;
|
Chris@76
|
134
|
Chris@76
|
135 if (this.bCollapsed)
|
Chris@76
|
136 {
|
Chris@76
|
137 window.location.href = smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=post;quote=' + iMessageId + ';topic=' + this.opt.iTopicId + '.' + this.opt.iStart;
|
Chris@76
|
138 return false;
|
Chris@76
|
139 }
|
Chris@76
|
140 else
|
Chris@76
|
141 {
|
Chris@76
|
142 // Doing it the XMLhttp way?
|
Chris@76
|
143 if (window.XMLHttpRequest)
|
Chris@76
|
144 {
|
Chris@76
|
145 ajax_indicator(true);
|
Chris@76
|
146 getXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId + ';xml', this.onQuoteReceived);
|
Chris@76
|
147 }
|
Chris@76
|
148 // Or with a smart popup!
|
Chris@76
|
149 else
|
Chris@76
|
150 reqWin(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId, 240, 90);
|
Chris@76
|
151
|
Chris@76
|
152 // Move the view to the quick reply box.
|
Chris@76
|
153 if (navigator.appName == 'Microsoft Internet Explorer')
|
Chris@76
|
154 window.location.hash = this.opt.sJumpAnchor;
|
Chris@76
|
155 else
|
Chris@76
|
156 window.location.hash = '#' + this.opt.sJumpAnchor;
|
Chris@76
|
157
|
Chris@76
|
158 return false;
|
Chris@76
|
159 }
|
Chris@76
|
160 }
|
Chris@76
|
161
|
Chris@76
|
162 // This is the callback function used after the XMLhttp request.
|
Chris@76
|
163 QuickReply.prototype.onQuoteReceived = function (oXMLDoc)
|
Chris@76
|
164 {
|
Chris@76
|
165 var sQuoteText = '';
|
Chris@76
|
166
|
Chris@76
|
167 for (var i = 0; i < oXMLDoc.getElementsByTagName('quote')[0].childNodes.length; i++)
|
Chris@76
|
168 sQuoteText += oXMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue;
|
Chris@76
|
169
|
Chris@76
|
170 replaceText(sQuoteText, document.forms.postmodify.message);
|
Chris@76
|
171
|
Chris@76
|
172 ajax_indicator(false);
|
Chris@76
|
173 }
|
Chris@76
|
174
|
Chris@76
|
175 // The function handling the swapping of the quick reply.
|
Chris@76
|
176 QuickReply.prototype.swap = function ()
|
Chris@76
|
177 {
|
Chris@76
|
178 document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
|
Chris@76
|
179 document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
|
Chris@76
|
180
|
Chris@76
|
181 this.bCollapsed = !this.bCollapsed;
|
Chris@76
|
182 }
|
Chris@76
|
183
|
Chris@76
|
184 // *** QuickModify object.
|
Chris@76
|
185 function QuickModify(oOptions)
|
Chris@76
|
186 {
|
Chris@76
|
187 this.opt = oOptions;
|
Chris@76
|
188 this.bInEditMode = false;
|
Chris@76
|
189 this.sCurMessageId = '';
|
Chris@76
|
190 this.oCurMessageDiv = null;
|
Chris@76
|
191 this.oCurSubjectDiv = null;
|
Chris@76
|
192 this.sMessageBuffer = '';
|
Chris@76
|
193 this.sSubjectBuffer = '';
|
Chris@76
|
194 this.bXmlHttpCapable = this.isXmlHttpCapable();
|
Chris@76
|
195
|
Chris@76
|
196 // Show the edit buttons
|
Chris@76
|
197 if (this.bXmlHttpCapable)
|
Chris@76
|
198 {
|
Chris@76
|
199 for (var i = document.images.length - 1; i >= 0; i--)
|
Chris@76
|
200 if (document.images[i].id.substr(0, 14) == 'modify_button_')
|
Chris@76
|
201 document.images[i].style.display = '';
|
Chris@76
|
202 }
|
Chris@76
|
203 }
|
Chris@76
|
204
|
Chris@76
|
205 // Determine whether the quick modify can actually be used.
|
Chris@76
|
206 QuickModify.prototype.isXmlHttpCapable = function ()
|
Chris@76
|
207 {
|
Chris@76
|
208 if (typeof(window.XMLHttpRequest) == 'undefined')
|
Chris@76
|
209 return false;
|
Chris@76
|
210
|
Chris@76
|
211 // Opera didn't always support POST requests. So test it first.
|
Chris@76
|
212 if ('opera' in window)
|
Chris@76
|
213 {
|
Chris@76
|
214 var oTest = new XMLHttpRequest();
|
Chris@76
|
215 if (!('setRequestHeader' in oTest))
|
Chris@76
|
216 return false;
|
Chris@76
|
217 }
|
Chris@76
|
218
|
Chris@76
|
219 return true;
|
Chris@76
|
220 }
|
Chris@76
|
221
|
Chris@76
|
222 // Function called when a user presses the edit button.
|
Chris@76
|
223 QuickModify.prototype.modifyMsg = function (iMessageId)
|
Chris@76
|
224 {
|
Chris@76
|
225 if (!this.bXmlHttpCapable)
|
Chris@76
|
226 return;
|
Chris@76
|
227
|
Chris@76
|
228 // Add backwards compatibility with old themes.
|
Chris@76
|
229 if (typeof(sSessionVar) == 'undefined')
|
Chris@76
|
230 sSessionVar = 'sesc';
|
Chris@76
|
231
|
Chris@76
|
232 // First cancel if there's another message still being edited.
|
Chris@76
|
233 if (this.bInEditMode)
|
Chris@76
|
234 this.modifyCancel();
|
Chris@76
|
235
|
Chris@76
|
236 // At least NOW we're in edit mode
|
Chris@76
|
237 this.bInEditMode = true;
|
Chris@76
|
238
|
Chris@76
|
239 // Send out the XMLhttp request to get more info
|
Chris@76
|
240 ajax_indicator(true);
|
Chris@76
|
241
|
Chris@76
|
242 // For IE 5.0 support, 'call' is not yet used.
|
Chris@76
|
243 this.tmpMethod = getXMLDocument;
|
Chris@76
|
244 this.tmpMethod(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId + ';modify;xml', this.onMessageReceived);
|
Chris@76
|
245 delete this.tmpMethod;
|
Chris@76
|
246 }
|
Chris@76
|
247
|
Chris@76
|
248 // The callback function used for the XMLhttp request retrieving the message.
|
Chris@76
|
249 QuickModify.prototype.onMessageReceived = function (XMLDoc)
|
Chris@76
|
250 {
|
Chris@76
|
251 var sBodyText = '', sSubjectText = '';
|
Chris@76
|
252
|
Chris@76
|
253 // No longer show the 'loading...' sign.
|
Chris@76
|
254 ajax_indicator(false);
|
Chris@76
|
255
|
Chris@76
|
256 // Grab the message ID.
|
Chris@76
|
257 this.sCurMessageId = XMLDoc.getElementsByTagName('message')[0].getAttribute('id');
|
Chris@76
|
258
|
Chris@76
|
259 // If this is not valid then simply give up.
|
Chris@76
|
260 if (!document.getElementById(this.sCurMessageId))
|
Chris@76
|
261 return this.modifyCancel();
|
Chris@76
|
262
|
Chris@76
|
263 // Replace the body part.
|
Chris@76
|
264 for (var i = 0; i < XMLDoc.getElementsByTagName("message")[0].childNodes.length; i++)
|
Chris@76
|
265 sBodyText += XMLDoc.getElementsByTagName("message")[0].childNodes[i].nodeValue;
|
Chris@76
|
266 this.oCurMessageDiv = document.getElementById(this.sCurMessageId);
|
Chris@76
|
267 this.sMessageBuffer = getInnerHTML(this.oCurMessageDiv);
|
Chris@76
|
268
|
Chris@76
|
269 // We have to force the body to lose its dollar signs thanks to IE.
|
Chris@76
|
270 sBodyText = sBodyText.replace(/\$/g, '{&dollarfix;$}');
|
Chris@76
|
271
|
Chris@76
|
272 // Actually create the content, with a bodge for disappearing dollar signs.
|
Chris@76
|
273 setInnerHTML(this.oCurMessageDiv, this.opt.sTemplateBodyEdit.replace(/%msg_id%/g, this.sCurMessageId.substr(4)).replace(/%body%/, sBodyText).replace(/\{&dollarfix;\$\}/g, '$'));
|
Chris@76
|
274
|
Chris@76
|
275 // Replace the subject part.
|
Chris@76
|
276 this.oCurSubjectDiv = document.getElementById('subject_' + this.sCurMessageId.substr(4));
|
Chris@76
|
277 this.sSubjectBuffer = getInnerHTML(this.oCurSubjectDiv);
|
Chris@76
|
278
|
Chris@76
|
279 sSubjectText = XMLDoc.getElementsByTagName('subject')[0].childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}');
|
Chris@76
|
280 setInnerHTML(this.oCurSubjectDiv, this.opt.sTemplateSubjectEdit.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'));
|
Chris@76
|
281
|
Chris@76
|
282 return true;
|
Chris@76
|
283 }
|
Chris@76
|
284
|
Chris@76
|
285 // Function in case the user presses cancel (or other circumstances cause it).
|
Chris@76
|
286 QuickModify.prototype.modifyCancel = function ()
|
Chris@76
|
287 {
|
Chris@76
|
288 // Roll back the HTML to its original state.
|
Chris@76
|
289 if (this.oCurMessageDiv)
|
Chris@76
|
290 {
|
Chris@76
|
291 setInnerHTML(this.oCurMessageDiv, this.sMessageBuffer);
|
Chris@76
|
292 setInnerHTML(this.oCurSubjectDiv, this.sSubjectBuffer);
|
Chris@76
|
293 }
|
Chris@76
|
294
|
Chris@76
|
295 // No longer in edit mode, that's right.
|
Chris@76
|
296 this.bInEditMode = false;
|
Chris@76
|
297
|
Chris@76
|
298 return false;
|
Chris@76
|
299 }
|
Chris@76
|
300
|
Chris@76
|
301 // The function called after a user wants to save his precious message.
|
Chris@76
|
302 QuickModify.prototype.modifySave = function (sSessionId, sSessionVar)
|
Chris@76
|
303 {
|
Chris@76
|
304 // We cannot save if we weren't in edit mode.
|
Chris@76
|
305 if (!this.bInEditMode)
|
Chris@76
|
306 return true;
|
Chris@76
|
307
|
Chris@76
|
308 // Add backwards compatibility with old themes.
|
Chris@76
|
309 if (typeof(sSessionVar) == 'undefined')
|
Chris@76
|
310 sSessionVar = 'sesc';
|
Chris@76
|
311
|
Chris@76
|
312 var i, x = new Array();
|
Chris@76
|
313 x[x.length] = 'subject=' + escape(document.forms.quickModForm['subject'].value.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B");
|
Chris@76
|
314 x[x.length] = 'message=' + escape(document.forms.quickModForm['message'].value.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B");
|
Chris@76
|
315 x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value);
|
Chris@76
|
316 x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value);
|
Chris@76
|
317
|
Chris@76
|
318 // Send in the XMLhttp request and let's hope for the best.
|
Chris@76
|
319 ajax_indicator(true);
|
Chris@76
|
320 sendXMLDocument.call(this, smf_prepareScriptUrl(this.opt.sScriptUrl) + "action=jsmodify;topic=" + this.opt.iTopicId + ";" + sSessionVar + "=" + sSessionId + ";xml", x.join("&"), this.onModifyDone);
|
Chris@76
|
321
|
Chris@76
|
322 return false;
|
Chris@76
|
323 }
|
Chris@76
|
324
|
Chris@76
|
325 // Callback function of the XMLhttp request sending the modified message.
|
Chris@76
|
326 QuickModify.prototype.onModifyDone = function (XMLDoc)
|
Chris@76
|
327 {
|
Chris@76
|
328 // We've finished the loading stuff.
|
Chris@76
|
329 ajax_indicator(false);
|
Chris@76
|
330
|
Chris@76
|
331 // If we didn't get a valid document, just cancel.
|
Chris@76
|
332 if (!XMLDoc || !XMLDoc.getElementsByTagName('smf')[0])
|
Chris@76
|
333 {
|
Chris@76
|
334 // Mozilla will nicely tell us what's wrong.
|
Chris@76
|
335 if (XMLDoc.childNodes.length > 0 && XMLDoc.firstChild.nodeName == 'parsererror')
|
Chris@76
|
336 setInnerHTML(document.getElementById('error_box'), XMLDoc.firstChild.textContent);
|
Chris@76
|
337 else
|
Chris@76
|
338 this.modifyCancel();
|
Chris@76
|
339 return;
|
Chris@76
|
340 }
|
Chris@76
|
341
|
Chris@76
|
342 var message = XMLDoc.getElementsByTagName('smf')[0].getElementsByTagName('message')[0];
|
Chris@76
|
343 var body = message.getElementsByTagName('body')[0];
|
Chris@76
|
344 var error = message.getElementsByTagName('error')[0];
|
Chris@76
|
345
|
Chris@76
|
346 if (body)
|
Chris@76
|
347 {
|
Chris@76
|
348 // Show new body.
|
Chris@76
|
349 var bodyText = '';
|
Chris@76
|
350 for (var i = 0; i < body.childNodes.length; i++)
|
Chris@76
|
351 bodyText += body.childNodes[i].nodeValue;
|
Chris@76
|
352
|
Chris@76
|
353 this.sMessageBuffer = this.opt.sTemplateBodyNormal.replace(/%body%/, bodyText.replace(/\$/g, '{&dollarfix;$}')).replace(/\{&dollarfix;\$\}/g,'$');
|
Chris@76
|
354 setInnerHTML(this.oCurMessageDiv, this.sMessageBuffer);
|
Chris@76
|
355
|
Chris@76
|
356 // Show new subject.
|
Chris@76
|
357 var oSubject = message.getElementsByTagName('subject')[0];
|
Chris@76
|
358 var sSubjectText = oSubject.childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}');
|
Chris@76
|
359 this.sSubjectBuffer = this.opt.sTemplateSubjectNormal.replace(/%msg_id%/g, this.sCurMessageId.substr(4)).replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g,'$');
|
Chris@76
|
360 setInnerHTML(this.oCurSubjectDiv, this.sSubjectBuffer);
|
Chris@76
|
361
|
Chris@76
|
362 // If this is the first message, also update the topic subject.
|
Chris@76
|
363 if (oSubject.getAttribute('is_first') == '1')
|
Chris@76
|
364 setInnerHTML(document.getElementById('top_subject'), this.opt.sTemplateTopSubject.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'));
|
Chris@76
|
365
|
Chris@76
|
366 // Show this message as 'modified on x by y'.
|
Chris@76
|
367 if (this.opt.bShowModify)
|
Chris@76
|
368 setInnerHTML(document.getElementById('modified_' + this.sCurMessageId.substr(4)), message.getElementsByTagName('modified')[0].childNodes[0].nodeValue);
|
Chris@76
|
369 }
|
Chris@76
|
370 else if (error)
|
Chris@76
|
371 {
|
Chris@76
|
372 setInnerHTML(document.getElementById('error_box'), error.childNodes[0].nodeValue);
|
Chris@76
|
373 document.forms.quickModForm.message.style.border = error.getAttribute('in_body') == '1' ? this.opt.sErrorBorderStyle : '';
|
Chris@76
|
374 document.forms.quickModForm.subject.style.border = error.getAttribute('in_subject') == '1' ? this.opt.sErrorBorderStyle : '';
|
Chris@76
|
375 }
|
Chris@76
|
376 }
|
Chris@76
|
377
|
Chris@76
|
378 function InTopicModeration(oOptions)
|
Chris@76
|
379 {
|
Chris@76
|
380 this.opt = oOptions;
|
Chris@76
|
381 this.bButtonsShown = false;
|
Chris@76
|
382 this.iNumSelected = 0;
|
Chris@76
|
383
|
Chris@76
|
384 // Add backwards compatibility with old themes.
|
Chris@76
|
385 if (typeof(this.opt.sSessionVar) == 'undefined')
|
Chris@76
|
386 this.opt.sSessionVar = 'sesc';
|
Chris@76
|
387
|
Chris@76
|
388 this.init();
|
Chris@76
|
389 }
|
Chris@76
|
390
|
Chris@76
|
391 InTopicModeration.prototype.init = function()
|
Chris@76
|
392 {
|
Chris@76
|
393 // Add checkboxes to all the messages.
|
Chris@76
|
394 for (var i = 0, n = this.opt.aMessageIds.length; i < n; i++)
|
Chris@76
|
395 {
|
Chris@76
|
396 // Create the checkbox.
|
Chris@76
|
397 var oCheckbox = document.createElement('input');
|
Chris@76
|
398 oCheckbox.type = 'checkbox';
|
Chris@76
|
399 oCheckbox.className = 'input_check';
|
Chris@76
|
400 oCheckbox.name = 'msgs[]';
|
Chris@76
|
401 oCheckbox.value = this.opt.aMessageIds[i];
|
Chris@76
|
402 oCheckbox.instanceRef = this;
|
Chris@76
|
403 oCheckbox.onclick = function () {
|
Chris@76
|
404 this.instanceRef.handleClick(this);
|
Chris@76
|
405 }
|
Chris@76
|
406
|
Chris@76
|
407 // Append it to the container
|
Chris@76
|
408 var oCheckboxContainer = document.getElementById(this.opt.sCheckboxContainerMask + this.opt.aMessageIds[i]);
|
Chris@76
|
409 oCheckboxContainer.appendChild(oCheckbox);
|
Chris@76
|
410 oCheckboxContainer.style.display = '';
|
Chris@76
|
411 }
|
Chris@76
|
412 }
|
Chris@76
|
413
|
Chris@76
|
414 InTopicModeration.prototype.handleClick = function(oCheckbox)
|
Chris@76
|
415 {
|
Chris@76
|
416 if (!this.bButtonsShown && this.opt.sButtonStripDisplay)
|
Chris@76
|
417 {
|
Chris@76
|
418 var oButtonStrip = document.getElementById(this.opt.sButtonStrip);
|
Chris@76
|
419 var oButtonStripDisplay = document.getElementById(this.opt.sButtonStripDisplay);
|
Chris@76
|
420
|
Chris@76
|
421 // Make sure it can go somewhere.
|
Chris@76
|
422 if (typeof(oButtonStripDisplay) == 'object' && oButtonStripDisplay != null)
|
Chris@76
|
423 oButtonStripDisplay.style.display = "";
|
Chris@76
|
424 else
|
Chris@76
|
425 {
|
Chris@76
|
426 var oNewDiv = document.createElement('div');
|
Chris@76
|
427 var oNewList = document.createElement('ul');
|
Chris@76
|
428
|
Chris@76
|
429 oNewDiv.id = this.opt.sButtonStripDisplay;
|
Chris@76
|
430 oNewDiv.className = this.opt.sButtonStripClass ? this.opt.sButtonStripClass : 'buttonlist floatbottom';
|
Chris@76
|
431
|
Chris@76
|
432 oNewDiv.appendChild(oNewList);
|
Chris@76
|
433 oButtonStrip.appendChild(oNewDiv);
|
Chris@76
|
434 }
|
Chris@76
|
435
|
Chris@76
|
436 // Add the 'remove selected items' button.
|
Chris@76
|
437 if (this.opt.bCanRemove)
|
Chris@76
|
438 smf_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, {
|
Chris@76
|
439 sId: this.opt.sSelf + '_remove_button',
|
Chris@76
|
440 sText: this.opt.sRemoveButtonLabel,
|
Chris@76
|
441 sImage: this.opt.sRemoveButtonImage,
|
Chris@76
|
442 sUrl: '#',
|
Chris@76
|
443 sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'remove\')"'
|
Chris@76
|
444 });
|
Chris@76
|
445
|
Chris@76
|
446 // Add the 'restore selected items' button.
|
Chris@76
|
447 if (this.opt.bCanRestore)
|
Chris@76
|
448 smf_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, {
|
Chris@76
|
449 sId: this.opt.sSelf + '_restore_button',
|
Chris@76
|
450 sText: this.opt.sRestoreButtonLabel,
|
Chris@76
|
451 sImage: this.opt.sRestoreButtonImage,
|
Chris@76
|
452 sUrl: '#',
|
Chris@76
|
453 sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'restore\')"'
|
Chris@76
|
454 });
|
Chris@76
|
455
|
Chris@76
|
456 // Adding these buttons once should be enough.
|
Chris@76
|
457 this.bButtonsShown = true;
|
Chris@76
|
458 }
|
Chris@76
|
459
|
Chris@76
|
460 // Keep stats on how many items were selected.
|
Chris@76
|
461 this.iNumSelected += oCheckbox.checked ? 1 : -1;
|
Chris@76
|
462
|
Chris@76
|
463 // Show the number of messages selected in the button.
|
Chris@76
|
464 if (this.opt.bCanRemove && !this.opt.bUseImageButton)
|
Chris@76
|
465 {
|
Chris@76
|
466 setInnerHTML(document.getElementById(this.opt.sSelf + '_remove_button'), this.opt.sRemoveButtonLabel + ' [' + this.iNumSelected + ']');
|
Chris@76
|
467 document.getElementById(this.opt.sSelf + '_remove_button').style.display = this.iNumSelected < 1 ? "none" : "";
|
Chris@76
|
468 }
|
Chris@76
|
469
|
Chris@76
|
470 if (this.opt.bCanRestore && !this.opt.bUseImageButton)
|
Chris@76
|
471 {
|
Chris@76
|
472 setInnerHTML(document.getElementById(this.opt.sSelf + '_restore_button'), this.opt.sRestoreButtonLabel + ' [' + this.iNumSelected + ']');
|
Chris@76
|
473 document.getElementById(this.opt.sSelf + '_restore_button').style.display = this.iNumSelected < 1 ? "none" : "";
|
Chris@76
|
474 }
|
Chris@76
|
475
|
Chris@76
|
476 // Try to restore the correct position.
|
Chris@76
|
477 var aItems = document.getElementById(this.opt.sButtonStrip).getElementsByTagName('span');
|
Chris@76
|
478 if (aItems.length > 3)
|
Chris@76
|
479 {
|
Chris@76
|
480 if (this.iNumSelected < 1)
|
Chris@76
|
481 {
|
Chris@76
|
482 aItems[aItems.length - 3].className = aItems[aItems.length - 3].className.replace(/\s*position_holder/, 'last');
|
Chris@76
|
483 aItems[aItems.length - 2].className = aItems[aItems.length - 2].className.replace(/\s*position_holder/, 'last');
|
Chris@76
|
484 }
|
Chris@76
|
485 else
|
Chris@76
|
486 {
|
Chris@76
|
487 aItems[aItems.length - 2].className = aItems[aItems.length - 2].className.replace(/\s*last/, 'position_holder');
|
Chris@76
|
488 aItems[aItems.length - 3].className = aItems[aItems.length - 3].className.replace(/\s*last/, 'position_holder');
|
Chris@76
|
489 }
|
Chris@76
|
490 }
|
Chris@76
|
491 }
|
Chris@76
|
492
|
Chris@76
|
493 InTopicModeration.prototype.handleSubmit = function (sSubmitType)
|
Chris@76
|
494 {
|
Chris@76
|
495 var oForm = document.getElementById(this.opt.sFormId);
|
Chris@76
|
496
|
Chris@76
|
497 // Make sure this form isn't submitted in another way than this function.
|
Chris@76
|
498 var oInput = document.createElement('input');
|
Chris@76
|
499 oInput.type = 'hidden';
|
Chris@76
|
500 oInput.name = this.opt.sSessionVar;
|
Chris@76
|
501 oInput.value = this.opt.sSessionId;
|
Chris@76
|
502 oForm.appendChild(oInput);
|
Chris@76
|
503
|
Chris@76
|
504 switch (sSubmitType)
|
Chris@76
|
505 {
|
Chris@76
|
506 case 'remove':
|
Chris@76
|
507 if (!confirm(this.opt.sRemoveButtonConfirm))
|
Chris@76
|
508 return false;
|
Chris@76
|
509
|
Chris@76
|
510 oForm.action = oForm.action.replace(/;restore_selected=1/, '');
|
Chris@76
|
511 break;
|
Chris@76
|
512
|
Chris@76
|
513 case 'restore':
|
Chris@76
|
514 if (!confirm(this.opt.sRestoreButtonConfirm))
|
Chris@76
|
515 return false;
|
Chris@76
|
516
|
Chris@76
|
517 oForm.action = oForm.action + ';restore_selected=1';
|
Chris@76
|
518 break;
|
Chris@76
|
519
|
Chris@76
|
520 default:
|
Chris@76
|
521 return false;
|
Chris@76
|
522 break;
|
Chris@76
|
523 }
|
Chris@76
|
524
|
Chris@76
|
525 oForm.submit();
|
Chris@76
|
526 return true;
|
Chris@76
|
527 }
|
Chris@76
|
528
|
Chris@76
|
529
|
Chris@76
|
530 // *** Other functions...
|
Chris@76
|
531 function expandThumb(thumbID)
|
Chris@76
|
532 {
|
Chris@76
|
533 var img = document.getElementById('thumb_' + thumbID);
|
Chris@76
|
534 var link = document.getElementById('link_' + thumbID);
|
Chris@76
|
535 var tmp = img.src;
|
Chris@76
|
536 img.src = link.href;
|
Chris@76
|
537 link.href = tmp;
|
Chris@76
|
538 img.style.width = '';
|
Chris@76
|
539 img.style.height = '';
|
Chris@76
|
540 return false;
|
Chris@76
|
541 } |