topic.js 25 KB

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