topic.js 22 KB

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