PageRenderTime 27ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/resources/admin/forum/MyBB/jscripts/thread.js

https://github.com/canercandan/agat-engine
JavaScript | 423 lines | 393 code | 29 blank | 1 comment | 78 complexity | 801aee6fb85e3b8e9247a5ccaf0d9295 MD5 | raw file
  1. var Thread = {
  2. init: function()
  3. {
  4. Thread.qeCache = new Array();
  5. Thread.initMultiQuote();
  6. Thread.initQuickReply();
  7. },
  8. initMultiQuote: function()
  9. {
  10. var quoted = Cookie.get("multiquote");
  11. if(quoted)
  12. {
  13. var post_ids = quoted.split("|");
  14. post_ids.each(function(post_id) {
  15. if($("multiquote_"+post_id))
  16. {
  17. element = $("multiquote_"+post_id);
  18. element.src = element.src.replace("postbit_multiquote.gif", "postbit_multiquote_on.gif");
  19. }
  20. });
  21. if($('quickreply_multiquote'))
  22. {
  23. $('quickreply_multiquote').show();
  24. }
  25. }
  26. return true;
  27. },
  28. multiQuote: function(pid)
  29. {
  30. var new_post_ids = new Array();
  31. var quoted = Cookie.get("multiquote");
  32. var is_new = true;
  33. if(quoted)
  34. {
  35. var post_ids = quoted.split("|");
  36. post_ids.each(function(post_id) {
  37. if(post_id != pid && post_id != '')
  38. {
  39. new_post_ids[new_post_ids.length] = post_id;
  40. }
  41. else if(post_id == pid)
  42. {
  43. is_new = false;
  44. }
  45. });
  46. }
  47. element = $("multiquote_"+pid);
  48. if(is_new == true)
  49. {
  50. element.src = element.src.replace("postbit_multiquote.gif", "postbit_multiquote_on.gif");
  51. new_post_ids[new_post_ids.length] = pid;
  52. }
  53. else
  54. {
  55. element.src = element.src.replace("postbit_multiquote_on.gif", "postbit_multiquote.gif");
  56. }
  57. if($('quickreply_multiquote'))
  58. {
  59. if(new_post_ids.length > 0)
  60. {
  61. $('quickreply_multiquote').show();
  62. }
  63. else
  64. {
  65. $('quickreply_multiquote').hide();
  66. }
  67. }
  68. Cookie.set("multiquote", new_post_ids.join("|"));
  69. },
  70. loadMultiQuoted: function()
  71. {
  72. if(use_xmlhttprequest == 1)
  73. {
  74. this.spinner = new ActivityIndicator("body", {image: imagepath + "/spinner_big.gif"});
  75. new Ajax.Request('xmlhttp.php?action=get_multiquoted&load_all=1', {method: 'get', onComplete: function(request) {Thread.multiQuotedLoaded(request); }});
  76. return false;
  77. }
  78. else
  79. {
  80. return true;
  81. }
  82. },
  83. multiQuotedLoaded: function(request)
  84. {
  85. if(request.responseText.match(/<error>(.*)<\/error>/))
  86. {
  87. message = request.responseText.match(/<error>(.*)<\/error>/);
  88. if(!message[1])
  89. {
  90. message[1] = "An unknown error occurred.";
  91. }
  92. if(this.spinner)
  93. {
  94. this.spinner.destroy();
  95. this.spinner = '';
  96. }
  97. alert('There was an error fetching the posts.\n\n'+message[1]);
  98. }
  99. else if(request.responseText)
  100. {
  101. var id = 'message';
  102. if(typeof clickableEditor != 'undefined')
  103. {
  104. id = clickableEditor.textarea;
  105. }
  106. if($(id).value)
  107. {
  108. $(id).value += "\n";
  109. }
  110. $(id).value += request.responseText;
  111. }
  112. Thread.clearMultiQuoted();
  113. $('quickreply_multiquote').hide();
  114. $('quoted_ids').value = 'all';
  115. if(this.spinner)
  116. {
  117. this.spinner.destroy();
  118. this.spinner = '';
  119. }
  120. $('message').focus();
  121. },
  122. clearMultiQuoted: function()
  123. {
  124. $('quickreply_multiquote').hide();
  125. var quoted = Cookie.get("multiquote");
  126. if(quoted)
  127. {
  128. var post_ids = quoted.split("|");
  129. post_ids.each(function(post_id) {
  130. if($("multiquote_"+post_id))
  131. {
  132. element = $("multiquote_"+post_id);
  133. element.src = element.src.replace("postbit_multiquote_on.gif", "postbit_multiquote.gif");
  134. }
  135. });
  136. }
  137. Cookie.unset('multiquote');
  138. },
  139. deletePost: function(pid)
  140. {
  141. confirmReturn = confirm(quickdelete_confirm);
  142. if(confirmReturn == true)
  143. {
  144. form = document.createElement("form");
  145. form.setAttribute("method", "post");
  146. form.setAttribute("action", "editpost.php?action=deletepost&delete=1");
  147. form.setAttribute("style", "display: none;");
  148. if(my_post_key)
  149. {
  150. if(MyBB.browser == "ie")
  151. {
  152. var input = document.createElement("<input name=\"my_post_key\">");
  153. }
  154. else
  155. {
  156. var input = document.createElement("input");
  157. input.setAttribute("name", "my_post_key");
  158. }
  159. input.setAttribute("type", "hidden");
  160. input.setAttribute("value", my_post_key);
  161. form.appendChild(input);
  162. }
  163. if(MyBB.browser == "ie")
  164. {
  165. var input = document.createElement("<input name=\"pid\">");
  166. }
  167. else
  168. {
  169. var input = document.createElement("input");
  170. input.setAttribute("name", "pid");
  171. }
  172. input.setAttribute("type", "hidden");
  173. input.setAttribute("value", pid);
  174. form.appendChild(input);
  175. document.getElementsByTagName("body")[0].appendChild(form);
  176. form.submit();
  177. }
  178. },
  179. reportPost: function(pid)
  180. {
  181. MyBB.popupWindow("report.php?pid="+pid, "reportPost", 400, 300)
  182. },
  183. quickEdit: function(pid)
  184. {
  185. if(!$("pid_"+pid))
  186. {
  187. return false;
  188. }
  189. if(Thread.qeCache[pid])
  190. {
  191. return false;
  192. }
  193. Thread.qeCache[pid] = $("pid_"+pid).innerHTML;
  194. this.spinner = new ActivityIndicator("body", {image: imagepath + "/spinner_big.gif"});
  195. new Ajax.Request('xmlhttp.php?action=edit_post&do=get_post&pid='+pid, {method: 'get', onComplete: function(request) { Thread.quickEditLoaded(request, pid); }});
  196. return false;
  197. },
  198. quickEditLoaded: function(request, pid)
  199. {
  200. if(request.responseText.match(/<error>(.*)<\/error>/))
  201. {
  202. message = request.responseText.match(/<error>(.*)<\/error>/);
  203. if(!message[1])
  204. {
  205. message[1] = "An unknown error occurred.";
  206. }
  207. if(this.spinner)
  208. {
  209. this.spinner.destroy();
  210. this.spinner = '';
  211. }
  212. alert('There was an error performing the update.\n\n'+message[1]);
  213. Thread.qeCache[pid] = "";
  214. }
  215. else if(request.responseText)
  216. {
  217. $("pid_"+pid).innerHTML = request.responseText;
  218. element = $("quickedit_"+pid);
  219. element.focus();
  220. offsetTop = -60;
  221. do
  222. {
  223. offsetTop += element.offsetTop || 0;
  224. element = element.offsetParent;
  225. }
  226. while(element);
  227. scrollTo(0, offsetTop);
  228. }
  229. if(this.spinner)
  230. {
  231. this.spinner.destroy();
  232. this.spinner = '';
  233. }
  234. },
  235. quickEditSave: function(pid)
  236. {
  237. message = $("quickedit_"+pid).value;
  238. if(message == "")
  239. {
  240. return false;
  241. }
  242. this.spinner = new ActivityIndicator("body", {image: imagepath + "/spinner_big.gif"});
  243. postData = "value="+encodeURIComponent(message).replace(/\+/g, "%2B");
  244. new Ajax.Request('xmlhttp.php?action=edit_post&do=update_post&pid='+pid+"&my_post_key="+my_post_key, {method: 'post', postBody: postData, onComplete: function(request) { Thread.quickEditSaved(request, pid); }});
  245. },
  246. quickEditCancel: function(pid)
  247. {
  248. $("pid_"+pid).innerHTML = Thread.qeCache[pid];
  249. Thread.qeCache[pid] = "";
  250. if(this.spinner)
  251. {
  252. this.spinner.destroy();
  253. this.spinner = '';
  254. }
  255. },
  256. quickEditSaved: function(request, pid)
  257. {
  258. if(request.responseText.match(/<error>(.*)<\/error>/))
  259. {
  260. message = request.responseText.match(/<error>(.*)<\/error>/);
  261. if(!message[1])
  262. {
  263. message[1] = "An unknown error occurred.";
  264. }
  265. if(this.spinner)
  266. {
  267. this.spinner.destroy();
  268. this.spinner = '';
  269. }
  270. alert('There was an error performing the update.\n\n'+message[1]);
  271. }
  272. else if(request.responseText)
  273. {
  274. var message = request.responseText;
  275. var edited_regex = new RegExp("<editedmsg>(.*)</editedmsg>", "m");
  276. if(request.responseText.match(edited_regex))
  277. {
  278. var edited_message = request.responseText.match(edited_regex)[1];
  279. if($('edited_by_'+pid))
  280. {
  281. $('edited_by_'+pid).innerHTML = edited_message;
  282. }
  283. message = message.replace(edited_regex, '')
  284. }
  285. $("pid_"+pid).innerHTML = message;
  286. Thread.qeCache[pid] = "";
  287. }
  288. if(this.spinner)
  289. {
  290. this.spinner.destroy();
  291. this.spinner = '';
  292. }
  293. },
  294. initQuickReply: function()
  295. {
  296. if($('quick_reply_form') && use_xmlhttprequest == 1)
  297. {
  298. Event.observe($('quick_reply_submit'), "click", Thread.quickReply.bindAsEventListener(this));
  299. }
  300. },
  301. quickReply: function(e)
  302. {
  303. Event.stop(e);
  304. if(this.quick_replying)
  305. {
  306. return false;
  307. }
  308. this.quick_replying = 1;
  309. var post_body = Form.serialize('quick_reply_form');
  310. this.spinner = new ActivityIndicator("body", {image: imagepath + "/spinner_big.gif"});
  311. new Ajax.Request('newreply.php?ajax=1', {method: 'post', postBody: post_body, onComplete: function(request) { Thread.quickReplyDone(request); }});
  312. return false;
  313. },
  314. quickReplyDone: function(request)
  315. {
  316. if($('captcha_img'))
  317. {
  318. captcha = request.responseText.match(/^<captcha>([0-9a-zA-Z]+)(\|([0-9a-zA-Z]+)|)<\/captcha>/);
  319. if(captcha)
  320. {
  321. request.responseText = request.responseText.replace(/^<captcha>(.*)<\/captcha>/, '');
  322. if(captcha[1])
  323. {
  324. imghash = captcha[1];
  325. $('imagehash').value = imghash;
  326. if(captcha[3])
  327. {
  328. $('imagestring').type = "hidden";
  329. $('imagestring').value = captcha[3];
  330. // hide the captcha
  331. $('captcha_trow').style.display = "none";
  332. }
  333. else
  334. {
  335. $('captcha_img').src = "captcha.php?action=regimage&imagehash="+imghash;
  336. $('imagestring').type = "text";
  337. $('imagestring').value = "";
  338. $('captcha_trow').style.display = "";
  339. }
  340. }
  341. }
  342. }
  343. if(request.responseText.match(/<error>([^<]*)<\/error>/))
  344. {
  345. message = request.responseText.match(/<error>([^<]*)<\/error>/);
  346. if(!message[1])
  347. {
  348. message[1] = "An unknown error occurred.";
  349. }
  350. if(this.spinner)
  351. {
  352. this.spinner.destroy();
  353. this.spinner = '';
  354. }
  355. alert('There was an error posting your reply:\n\n'+message[1]);
  356. }
  357. else if(request.responseText.match(/id="post_([0-9]+)"/))
  358. {
  359. var pid = request.responseText.match(/id="post_([0-9]+)"/)[1];
  360. var post = document.createElement("div");
  361. post.innerHTML = request.responseText;
  362. $('posts').appendChild(post);
  363. if(MyBB.browser == "ie" || MyBB.browser == "opera" || MyBB.browser == "safari" || MyBB.browser == "chrome")
  364. {
  365. var scripts = request.responseText.extractScripts();
  366. scripts.each(function(script)
  367. {
  368. eval(script);
  369. });
  370. }
  371. Form.reset('quick_reply_form');
  372. if($('lastpid'))
  373. {
  374. $('lastpid').value = pid;
  375. }
  376. }
  377. else
  378. {
  379. request.responseText.evalScripts();
  380. }
  381. if(this.spinner)
  382. {
  383. this.spinner.destroy();
  384. this.spinner = '';
  385. }
  386. this.quick_replying = 0;
  387. },
  388. showIgnoredPost: function(pid)
  389. {
  390. $('ignored_post_'+pid).hide();
  391. $('post_'+pid).show();
  392. }
  393. };
  394. Event.observe(document, 'dom:loaded', Thread.init);