topic.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. // redo tips if they are on since we just pulled the rug out on this one
  145. if ($.isFunction($.fn.SMFtooltip));
  146. $('.preview').SMFtooltip().smf_tooltip_off;
  147. return false;
  148. }
  149. // Done with the edit, put in new subject and link.
  150. QuickModifyTopic.prototype.modify_topic_hide_edit = function (subject)
  151. {
  152. // Re-template the subject!
  153. setInnerHTML(this.oCurSubjectDiv, '<a href="' + smf_scripturl + '?topic=' + this.iCurTopicId + '.0">' + subject + '<' +'/a>');
  154. }
  155. // keypress event ... like enter or escape
  156. QuickModifyTopic.prototype.modify_topic_keypress = function (oEvent)
  157. {
  158. if (typeof(oEvent.keyCode) != "undefined" && this.bInEditMode)
  159. {
  160. if (oEvent.keyCode == 27)
  161. {
  162. this.modify_topic_cancel();
  163. if (typeof(oEvent.preventDefault) == "undefined")
  164. oEvent.returnValue = false;
  165. else
  166. oEvent.preventDefault();
  167. }
  168. else if (oEvent.keyCode == 13)
  169. {
  170. this.modify_topic_save(smf_session_id, smf_session_var);
  171. if (typeof(oEvent.preventDefault) == "undefined")
  172. oEvent.returnValue = false;
  173. else
  174. oEvent.preventDefault();
  175. }
  176. }
  177. }
  178. // A click event to signal the finish of the edit
  179. QuickModifyTopic.prototype.modify_topic_click = function (oEvent)
  180. {
  181. if (this.bInEditMode && !this.bMouseOnDiv)
  182. this.modify_topic_save(smf_session_id, smf_session_var);
  183. }
  184. // Moved out of the editing div
  185. QuickModifyTopic.prototype.modify_topic_mouseout = function (oEvent)
  186. {
  187. this.bMouseOnDiv = false;
  188. }
  189. // Moved back over the editing div
  190. QuickModifyTopic.prototype.modify_topic_mouseover = function (oEvent)
  191. {
  192. this.bMouseOnDiv = true;
  193. }
  194. // *** QuickReply object.
  195. function QuickReply(oOptions)
  196. {
  197. this.opt = oOptions;
  198. this.bCollapsed = this.opt.bDefaultCollapsed;
  199. this.bIsFull = this.opt.bIsFull;
  200. }
  201. // When a user presses quote, put it in the quick reply box (if expanded).
  202. QuickReply.prototype.quote = function (iMessageId, xDeprecated)
  203. {
  204. // Compatibility with older templates.
  205. if (typeof(xDeprecated) != 'undefined')
  206. return true;
  207. if (this.bCollapsed)
  208. {
  209. window.location.href = smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=post;quote=' + iMessageId + ';topic=' + this.opt.iTopicId + '.' + this.opt.iStart;
  210. return false;
  211. }
  212. else
  213. {
  214. // Doing it the XMLhttp way?
  215. if (window.XMLHttpRequest)
  216. {
  217. ajax_indicator(true);
  218. if (this.bIsFull)
  219. insertQuoteFast(iMessageId);
  220. else
  221. getXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId + ';xml', this.onQuoteReceived);
  222. }
  223. // Or with a smart popup!
  224. else
  225. reqWin(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=quotefast;quote=' + iMessageId, 240, 90);
  226. // Move the view to the quick reply box.
  227. if (navigator.appName == 'Microsoft Internet Explorer')
  228. window.location.hash = this.opt.sJumpAnchor;
  229. else
  230. window.location.hash = '#' + this.opt.sJumpAnchor;
  231. return false;
  232. }
  233. }
  234. // This is the callback function used after the XMLhttp request.
  235. QuickReply.prototype.onQuoteReceived = function (oXMLDoc)
  236. {
  237. var sQuoteText = '';
  238. for (var i = 0; i < oXMLDoc.getElementsByTagName('quote')[0].childNodes.length; i++)
  239. sQuoteText += oXMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue;
  240. replaceText(sQuoteText, document.forms.postmodify.message);
  241. ajax_indicator(false);
  242. }
  243. // The function handling the swapping of the quick reply.
  244. QuickReply.prototype.swap = function ()
  245. {
  246. document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
  247. $('#' + this.opt.sContainerId).slideToggle();
  248. this.bCollapsed = !this.bCollapsed;
  249. }
  250. // *** QuickModify object.
  251. function QuickModify(oOptions)
  252. {
  253. this.opt = oOptions;
  254. this.bInEditMode = false;
  255. this.sCurMessageId = '';
  256. this.oCurMessageDiv = null;
  257. this.oCurSubjectDiv = null;
  258. this.sMessageBuffer = '';
  259. this.sSubjectBuffer = '';
  260. this.bXmlHttpCapable = this.isXmlHttpCapable();
  261. this.aAccessKeys = new Array();
  262. // Show the edit buttons
  263. if (this.bXmlHttpCapable)
  264. {
  265. var aShowQuickModify = document.getElementsByClassName(this.opt.sClassName);
  266. for (var i = 0, length = aShowQuickModify.length; i < length; i++) {
  267. aShowQuickModify[i].style.display = "inline";
  268. }
  269. }
  270. }
  271. // Determine whether the quick modify can actually be used.
  272. QuickModify.prototype.isXmlHttpCapable = function ()
  273. {
  274. if (typeof(window.XMLHttpRequest) == 'undefined')
  275. return false;
  276. // Opera didn't always support POST requests. So test it first.
  277. if ('opera' in window)
  278. {
  279. var oTest = new XMLHttpRequest();
  280. if (!('setRequestHeader' in oTest))
  281. return false;
  282. }
  283. return true;
  284. }
  285. // Function called when a user presses the edit button.
  286. QuickModify.prototype.modifyMsg = function (iMessageId)
  287. {
  288. if (!this.bXmlHttpCapable)
  289. return;
  290. // Add backwards compatibility with old themes.
  291. if (typeof(sSessionVar) == 'undefined')
  292. sSessionVar = 'sesc';
  293. // Removes the accesskeys from the quickreply inputs and saves them in an array to use them later
  294. if (typeof(this.opt.sFormRemoveAccessKeys) != 'undefined')
  295. {
  296. if (typeof(document.forms[this.opt.sFormRemoveAccessKeys]))
  297. {
  298. var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input');
  299. for (var i = 0; i < aInputs.length; i++)
  300. {
  301. if (aInputs[i].accessKey != '')
  302. {
  303. this.aAccessKeys[aInputs[i].name] = aInputs[i].accessKey;
  304. aInputs[i].accessKey = '';
  305. }
  306. }
  307. }
  308. }
  309. // First cancel if there's another message still being edited.
  310. if (this.bInEditMode)
  311. this.modifyCancel();
  312. // At least NOW we're in edit mode
  313. this.bInEditMode = true;
  314. // Send out the XMLhttp request to get more info
  315. ajax_indicator(true);
  316. sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + 'action=quotefast;quote=' + iMessageId + ';modify;xml', '', this.onMessageReceived);
  317. }
  318. // The callback function used for the XMLhttp request retrieving the message.
  319. QuickModify.prototype.onMessageReceived = function (XMLDoc)
  320. {
  321. var sBodyText = '', sSubjectText = '';
  322. // No longer show the 'loading...' sign.
  323. ajax_indicator(false);
  324. // Grab the message ID.
  325. this.sCurMessageId = XMLDoc.getElementsByTagName('message')[0].getAttribute('id');
  326. // If this is not valid then simply give up.
  327. if (!document.getElementById(this.sCurMessageId))
  328. return this.modifyCancel();
  329. // Replace the body part.
  330. for (var i = 0; i < XMLDoc.getElementsByTagName("message")[0].childNodes.length; i++)
  331. sBodyText += XMLDoc.getElementsByTagName("message")[0].childNodes[i].nodeValue;
  332. this.oCurMessageDiv = document.getElementById(this.sCurMessageId);
  333. this.sMessageBuffer = getInnerHTML(this.oCurMessageDiv);
  334. // We have to force the body to lose its dollar signs thanks to IE.
  335. sBodyText = sBodyText.replace(/\$/g, '{&dollarfix;$}');
  336. // Actually create the content, with a bodge for disappearing dollar signs.
  337. setInnerHTML(this.oCurMessageDiv, this.opt.sTemplateBodyEdit.replace(/%msg_id%/g, this.sCurMessageId.substr(4)).replace(/%body%/, sBodyText).replace(/\{&dollarfix;\$\}/g, '$'));
  338. // Replace the subject part.
  339. this.oCurSubjectDiv = document.getElementById('subject_' + this.sCurMessageId.substr(4));
  340. this.sSubjectBuffer = getInnerHTML(this.oCurSubjectDiv);
  341. sSubjectText = XMLDoc.getElementsByTagName('subject')[0].childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}');
  342. setInnerHTML(this.oCurSubjectDiv, this.opt.sTemplateSubjectEdit.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'));
  343. return true;
  344. }
  345. // Function in case the user presses cancel (or other circumstances cause it).
  346. QuickModify.prototype.modifyCancel = function ()
  347. {
  348. // Roll back the HTML to its original state.
  349. if (this.oCurMessageDiv)
  350. {
  351. setInnerHTML(this.oCurMessageDiv, this.sMessageBuffer);
  352. setInnerHTML(this.oCurSubjectDiv, this.sSubjectBuffer);
  353. }
  354. // No longer in edit mode, that's right.
  355. this.bInEditMode = false;
  356. // Let's put back the accesskeys to their original place
  357. if (typeof(this.opt.sFormRemoveAccessKeys) != 'undefined')
  358. {
  359. if (typeof(document.forms[this.opt.sFormRemoveAccessKeys]))
  360. {
  361. var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input');
  362. for (var i = 0; i < aInputs.length; i++)
  363. {
  364. if (typeof(this.aAccessKeys[aInputs[i].name]) != 'undefined')
  365. {
  366. aInputs[i].name = this.aAccessKeys[aInputs[i].name];
  367. }
  368. }
  369. }
  370. }
  371. return false;
  372. }
  373. // The function called after a user wants to save his precious message.
  374. QuickModify.prototype.modifySave = function (sSessionId, sSessionVar)
  375. {
  376. // We cannot save if we weren't in edit mode.
  377. if (!this.bInEditMode)
  378. return true;
  379. // Add backwards compatibility with old themes.
  380. if (typeof(sSessionVar) == 'undefined')
  381. sSessionVar = 'sesc';
  382. // Let's put back the accesskeys to their original place
  383. if (typeof(this.opt.sFormRemoveAccessKeys) != 'undefined')
  384. {
  385. if (typeof(document.forms[this.opt.sFormRemoveAccessKeys]))
  386. {
  387. var aInputs = document.forms[this.opt.sFormRemoveAccessKeys].getElementsByTagName('input');
  388. for (var i = 0; i < aInputs.length; i++)
  389. {
  390. if (typeof(this.aAccessKeys[aInputs[i].name]) != 'undefined')
  391. {
  392. aInputs[i].name = this.aAccessKeys[aInputs[i].name];
  393. }
  394. }
  395. }
  396. }
  397. var i, x = new Array();
  398. x[x.length] = 'subject=' + escape(document.forms.quickModForm['subject'].value.replace(/&#/g, "&#38;#").php_to8bit()).replace(/\+/g, "%2B");
  399. x[x.length] = 'message=' + escape(document.forms.quickModForm['message'].value.replace(/&#/g, "&#38;#").php_to8bit()).replace(/\+/g, "%2B");
  400. x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value);
  401. x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value);
  402. // Send in the XMLhttp request and let's hope for the best.
  403. ajax_indicator(true);
  404. 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);
  405. return false;
  406. }
  407. // Callback function of the XMLhttp request sending the modified message.
  408. QuickModify.prototype.onModifyDone = function (XMLDoc)
  409. {
  410. // We've finished the loading stuff.
  411. ajax_indicator(false);
  412. // If we didn't get a valid document, just cancel.
  413. if (!XMLDoc || !XMLDoc.getElementsByTagName('smf')[0])
  414. {
  415. // Mozilla will nicely tell us what's wrong.
  416. if (XMLDoc.childNodes.length > 0 && XMLDoc.firstChild.nodeName == 'parsererror')
  417. setInnerHTML(document.getElementById('error_box'), XMLDoc.firstChild.textContent);
  418. else
  419. this.modifyCancel();
  420. return;
  421. }
  422. var message = XMLDoc.getElementsByTagName('smf')[0].getElementsByTagName('message')[0];
  423. var body = message.getElementsByTagName('body')[0];
  424. var error = message.getElementsByTagName('error')[0];
  425. if (body)
  426. {
  427. // Show new body.
  428. var bodyText = '';
  429. for (var i = 0; i < body.childNodes.length; i++)
  430. bodyText += body.childNodes[i].nodeValue;
  431. this.sMessageBuffer = this.opt.sTemplateBodyNormal.replace(/%body%/, bodyText.replace(/\$/g, '{&dollarfix;$}')).replace(/\{&dollarfix;\$\}/g,'$');
  432. setInnerHTML(this.oCurMessageDiv, this.sMessageBuffer);
  433. // Show new subject.
  434. var oSubject = message.getElementsByTagName('subject')[0];
  435. var sSubjectText = oSubject.childNodes[0].nodeValue.replace(/\$/g, '{&dollarfix;$}');
  436. this.sSubjectBuffer = this.opt.sTemplateSubjectNormal.replace(/%msg_id%/g, this.sCurMessageId.substr(4)).replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g,'$');
  437. setInnerHTML(this.oCurSubjectDiv, this.sSubjectBuffer);
  438. // If this is the first message, also update the topic subject.
  439. if (oSubject.getAttribute('is_first') == '1')
  440. setInnerHTML(document.getElementById('top_subject'), this.opt.sTemplateTopSubject.replace(/%subject%/, sSubjectText).replace(/\{&dollarfix;\$\}/g, '$'));
  441. // Show this message as 'modified on x by y'.
  442. if (this.opt.bShowModify)
  443. setInnerHTML(document.getElementById('modified_' + this.sCurMessageId.substr(4)), message.getElementsByTagName('modified')[0].childNodes[0].nodeValue);
  444. }
  445. else if (error)
  446. {
  447. setInnerHTML(document.getElementById('error_box'), error.childNodes[0].nodeValue);
  448. document.forms.quickModForm.message.style.border = error.getAttribute('in_body') == '1' ? this.opt.sErrorBorderStyle : '';
  449. document.forms.quickModForm.subject.style.border = error.getAttribute('in_subject') == '1' ? this.opt.sErrorBorderStyle : '';
  450. }
  451. }
  452. function InTopicModeration(oOptions)
  453. {
  454. this.opt = oOptions;
  455. this.bButtonsShown = false;
  456. this.iNumSelected = 0;
  457. // Add backwards compatibility with old themes.
  458. if (typeof(this.opt.sSessionVar) == 'undefined')
  459. this.opt.sSessionVar = 'sesc';
  460. this.init();
  461. }
  462. InTopicModeration.prototype.init = function()
  463. {
  464. // Add checkboxes to all the messages.
  465. for (var i = 0, n = this.opt.aMessageIds.length; i < n; i++)
  466. {
  467. // Create the checkbox.
  468. var oCheckbox = document.createElement('input');
  469. oCheckbox.type = 'checkbox';
  470. oCheckbox.className = 'input_check';
  471. oCheckbox.name = 'msgs[]';
  472. oCheckbox.value = this.opt.aMessageIds[i];
  473. oCheckbox.instanceRef = this;
  474. oCheckbox.onclick = function () {
  475. this.instanceRef.handleClick(this);
  476. }
  477. // Append it to the container
  478. var oCheckboxContainer = document.getElementById(this.opt.sCheckboxContainerMask + this.opt.aMessageIds[i]);
  479. oCheckboxContainer.appendChild(oCheckbox);
  480. oCheckboxContainer.style.display = '';
  481. }
  482. }
  483. InTopicModeration.prototype.handleClick = function(oCheckbox)
  484. {
  485. if (!this.bButtonsShown && this.opt.sButtonStripDisplay)
  486. {
  487. var oButtonStrip = document.getElementById(this.opt.sButtonStrip);
  488. var oButtonStripDisplay = document.getElementById(this.opt.sButtonStripDisplay);
  489. // Make sure it can go somewhere.
  490. if (typeof(oButtonStripDisplay) == 'object' && oButtonStripDisplay != null)
  491. oButtonStripDisplay.style.display = "";
  492. else
  493. {
  494. var oNewDiv = document.createElement('div');
  495. var oNewList = document.createElement('ul');
  496. oNewDiv.id = this.opt.sButtonStripDisplay;
  497. oNewDiv.className = this.opt.sButtonStripClass ? this.opt.sButtonStripClass : 'buttonlist floatbottom';
  498. oNewDiv.appendChild(oNewList);
  499. oButtonStrip.appendChild(oNewDiv);
  500. }
  501. // Add the 'remove selected items' button.
  502. if (this.opt.bCanRemove)
  503. smf_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, {
  504. sId: this.opt.sSelf + '_remove_button',
  505. sText: this.opt.sRemoveButtonLabel,
  506. sImage: this.opt.sRemoveButtonImage,
  507. sUrl: '#',
  508. sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'remove\')"'
  509. });
  510. // Add the 'restore selected items' button.
  511. if (this.opt.bCanRestore)
  512. smf_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, {
  513. sId: this.opt.sSelf + '_restore_button',
  514. sText: this.opt.sRestoreButtonLabel,
  515. sImage: this.opt.sRestoreButtonImage,
  516. sUrl: '#',
  517. sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'restore\')"'
  518. });
  519. // Add the 'split selected items' button.
  520. if (this.opt.bCanSplit)
  521. smf_addButton(this.opt.sButtonStrip, this.opt.bUseImageButton, {
  522. sId: this.opt.sSelf + '_split_button',
  523. sText: this.opt.sSplitButtonLabel,
  524. sImage: this.opt.sSplitButtonImage,
  525. sUrl: '#',
  526. sCustom: ' onclick="return ' + this.opt.sSelf + '.handleSubmit(\'split\')"'
  527. });
  528. // Adding these buttons once should be enough.
  529. this.bButtonsShown = true;
  530. }
  531. // Keep stats on how many items were selected.
  532. this.iNumSelected += oCheckbox.checked ? 1 : -1;
  533. // Show the number of messages selected in the button.
  534. if (this.opt.bCanRemove && !this.opt.bUseImageButton)
  535. {
  536. setInnerHTML(document.getElementById(this.opt.sSelf + '_remove_button_text'), this.opt.sRemoveButtonLabel + ' [' + this.iNumSelected + ']');
  537. document.getElementById(this.opt.sSelf + '_remove_button').style.display = this.iNumSelected < 1 ? "none" : "";
  538. }
  539. if (this.opt.bCanRestore && !this.opt.bUseImageButton)
  540. {
  541. setInnerHTML(document.getElementById(this.opt.sSelf + '_restore_button_text'), this.opt.sRestoreButtonLabel + ' [' + this.iNumSelected + ']');
  542. document.getElementById(this.opt.sSelf + '_restore_button').style.display = this.iNumSelected < 1 ? "none" : "";
  543. }
  544. if (this.opt.bCanSplit && !this.opt.bUseImageButton)
  545. {
  546. setInnerHTML(document.getElementById(this.opt.sSelf + '_split_button_text'), this.opt.sSplitButtonLabel + ' [' + this.iNumSelected + ']');
  547. document.getElementById(this.opt.sSelf + '_split_button').style.display = this.iNumSelected < 1 ? "none" : "";
  548. }
  549. if(typeof smf_fixButtonClass == 'function')
  550. smf_fixButtonClass(this.opt.sButtonStrip);
  551. }
  552. InTopicModeration.prototype.handleSubmit = function (sSubmitType)
  553. {
  554. var oForm = document.getElementById(this.opt.sFormId);
  555. // Make sure this form isn't submitted in another way than this function.
  556. var oInput = document.createElement('input');
  557. oInput.type = 'hidden';
  558. oInput.name = this.opt.sSessionVar;
  559. oInput.value = this.opt.sSessionId;
  560. oForm.appendChild(oInput);
  561. switch (sSubmitType)
  562. {
  563. case 'remove':
  564. if (!confirm(this.opt.sRemoveButtonConfirm))
  565. return false;
  566. oForm.action = oForm.action.replace(/;split_selection=1/, '');
  567. oForm.action = oForm.action.replace(/;restore_selected=1/, '');
  568. break;
  569. case 'restore':
  570. if (!confirm(this.opt.sRestoreButtonConfirm))
  571. return false;
  572. oForm.action = oForm.action.replace(/;split_selection=1/, '');
  573. oForm.action = oForm.action + ';restore_selected=1';
  574. break;
  575. case 'split':
  576. if (!confirm(this.opt.sRestoreButtonConfirm))
  577. return false;
  578. oForm.action = oForm.action.replace(/;restore_selected=1/, '');
  579. oForm.action = oForm.action + ';split_selection=1';
  580. break;
  581. default:
  582. return false;
  583. break;
  584. }
  585. oForm.submit();
  586. return true;
  587. }
  588. // *** Other functions...
  589. function expandThumb(thumbID)
  590. {
  591. var img = document.getElementById('thumb_' + thumbID);
  592. var link = document.getElementById('link_' + thumbID);
  593. // save the currently displayed image attributes
  594. var tmp_src = img.src;
  595. var tmp_height = img.style.height;
  596. var tmp_width = img.style.width;
  597. // set the displayed image attributes to the link attributes, this will expand in place
  598. img.src = link.href;
  599. img.style.width = link.style.width;
  600. img.style.height = link.style.height;
  601. // place the image attributes back
  602. link.href = tmp_src;
  603. link.style.width = tmp_width;
  604. link.style.height = tmp_height;
  605. return false;
  606. }
  607. function ignore_toggles(msgids, text)
  608. {
  609. for (i = 0; i < msgids.length; i++)
  610. {
  611. var msgid = msgids[i];
  612. new smc_Toggle({
  613. bToggleEnabled: true,
  614. bCurrentlyCollapsed: true,
  615. aSwappableContainers: [
  616. 'msg_' + msgid + '_extra_info',
  617. 'msg_' + msgid,
  618. 'msg_' + msgid + '_footer',
  619. 'msg_' + msgid + '_quick_mod',
  620. 'modify_button_' + msgid,
  621. 'msg_' + msgid + '_signature'
  622. ],
  623. aSwapLinks: [
  624. {
  625. sId: 'msg_' + msgid + '_ignored_link',
  626. msgExpanded: '',
  627. msgCollapsed: text
  628. }
  629. ]
  630. });
  631. }
  632. }