Advertisement
Guest User

Untitled

a guest
Aug 19th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.22 KB | None | 0 0
  1. var MyBB = {
  2. init: function()
  3. {
  4. $(function()
  5. {
  6. MyBB.pageLoaded();
  7. });
  8.  
  9. return true;
  10. },
  11.  
  12. pageLoaded: function()
  13. {
  14. expandables.init();
  15.  
  16. /* Create the Check All feature */
  17. $('[name="allbox"]').each(function(key, value) {
  18. $(this).change(function() {
  19. var checkboxes = $(this).closest('form').find(':checkbox');
  20. if($(this).is(':checked')) {
  21. checkboxes.prop('checked', true);
  22. } else {
  23. checkboxes.removeAttr('checked');
  24. }
  25. });
  26. });
  27.  
  28. // Initialise "initial focus" field if we have one
  29. var initialfocus = $(".initial_focus");
  30. if(initialfocus.length)
  31. {
  32. initialfocus.focus();
  33. }
  34.  
  35. if(typeof(use_xmlhttprequest) != "undefined" && use_xmlhttprequest == 1)
  36. {
  37. mark_read_imgs = $(".ajax_mark_read");
  38. mark_read_imgs.each(function()
  39. {
  40. var element = $(this);
  41. if(element.hasClass('forum_off') || element.hasClass('forum_offlock') || element.hasClass('forum_offlink') || element.hasClass('subforum_minioff') || element.hasClass('subforum_miniofflock') || element.hasClass('subforum_miniofflink') || (element.attr("title") && element.attr("title") == lang.no_new_posts)) return;
  42.  
  43. element.click(function()
  44. {
  45. MyBB.markForumRead(this);
  46. });
  47.  
  48. element.css("cursor", "pointer");
  49. if(element.attr("title"))
  50. {
  51. element.attr("title", element.attr("title") + " - ");
  52. }
  53. element.attr("title", element.attr("title") + lang.click_mark_read);
  54. });
  55. }
  56.  
  57. if(typeof $.modal !== "undefined")
  58. {
  59. $(document).on($.modal.OPEN, function(event, modal) {
  60. $("body").css("overflow", "hidden");
  61. if(initialfocus.length > 0)
  62. {
  63. initialfocus.focus();
  64. }
  65. });
  66.  
  67. $(document).on($.modal.CLOSE, function(event, modal) {
  68. $("body").css("overflow", "auto");
  69. });
  70. }
  71. },
  72.  
  73. popupWindow: function(url, options, root)
  74. {
  75. if(!options) options = { fadeDuration: 250, zIndex: (typeof modal_zindex !== 'undefined' ? modal_zindex : 9999) }
  76. if(root != true)
  77. url = rootpath + url;
  78.  
  79. $.get(url, function(html)
  80. {
  81. $(html).appendTo('body').modal(options);
  82. });
  83. },
  84.  
  85. deleteEvent: function(eid)
  86. {
  87. $.prompt(deleteevent_confirm, {
  88. buttons:[
  89. {title: yes_confirm, value: true},
  90. {title: no_confirm, value: false}
  91. ],
  92. submit: function(e,v,m,f){
  93. if(v == true)
  94. {
  95. var form = $("<form />",
  96. {
  97. method: "post",
  98. action: "calendar.php",
  99. style: "display: none;"
  100. });
  101.  
  102. form.append(
  103. $("<input />",
  104. {
  105. name: "action",
  106. type: "hidden",
  107. value: "do_editevent"
  108. })
  109. );
  110.  
  111. if(my_post_key)
  112. {
  113. form.append(
  114. $("<input />",
  115. {
  116. name: "my_post_key",
  117. type: "hidden",
  118. value: my_post_key
  119. })
  120. );
  121. }
  122.  
  123. form.append(
  124. $("<input />",
  125. {
  126. name: "eid",
  127. type: "hidden",
  128. value: eid
  129. })
  130. );
  131.  
  132. form.append(
  133. $("<input />",
  134. {
  135. name: "delete",
  136. type: "hidden",
  137. value: 1
  138. })
  139. );
  140.  
  141. $("body").append(form);
  142. form.submit();
  143. }
  144. }
  145. });
  146. },
  147.  
  148. reputation: function(uid, pid)
  149. {
  150. if(!pid)
  151. {
  152. var pid = 0;
  153. }
  154.  
  155. MyBB.popupWindow("/reputation.php?action=add&uid="+uid+"&pid="+pid+"&modal=1");
  156. },
  157.  
  158. viewNotes: function(uid)
  159. {
  160. MyBB.popupWindow("/member.php?action=viewnotes&uid="+uid+"&modal=1");
  161. },
  162.  
  163. deleteReputation: function(uid, rid)
  164. {
  165. $.prompt(delete_reputation_confirm, {
  166. buttons:[
  167. {title: yes_confirm, value: true},
  168. {title: no_confirm, value: false}
  169. ],
  170. submit: function(e,v,m,f){
  171. if(v == true)
  172. {
  173. var form = $("<form />",
  174. {
  175. method: "post",
  176. action: "reputation.php?action=delete",
  177. style: "display: none;"
  178. });
  179.  
  180. form.append(
  181. $("<input />",
  182. {
  183. name: "rid",
  184. type: "hidden",
  185. value: rid
  186. })
  187. );
  188.  
  189. if(my_post_key)
  190. {
  191. form.append(
  192. $("<input />",
  193. {
  194. name: "my_post_key",
  195. type: "hidden",
  196. value: my_post_key
  197. })
  198. );
  199. }
  200.  
  201. form.append(
  202. $("<input />",
  203. {
  204. name: "uid",
  205. type: "hidden",
  206. value: uid
  207. })
  208. );
  209.  
  210. $("body").append(form);
  211. form.submit();
  212. }
  213. }
  214. });
  215.  
  216. return false;
  217. },
  218.  
  219. whoPosted: function(tid)
  220. {
  221. MyBB.popupWindow("/misc.php?action=whoposted&tid="+tid+"&modal=1");
  222. },
  223.  
  224. markForumRead: function(event)
  225. {
  226. var element = $(event);
  227. if(!element.length)
  228. {
  229. return false;
  230. }
  231. var fid = element.attr("id").replace("mark_read_", "");
  232. if(!fid)
  233. {
  234. return false;
  235. }
  236.  
  237. $.ajax(
  238. {
  239. url: 'misc.php?action=markread&fid=' + fid + '&ajax=1&my_post_key=' + my_post_key,
  240. async: true,
  241. success: function (request)
  242. {
  243. MyBB.forumMarkedRead(fid, request);
  244. }
  245. });
  246. },
  247.  
  248. forumMarkedRead: function(fid, request)
  249. {
  250. if(request == 1)
  251. {
  252. var markreadfid = $("#mark_read_"+fid);
  253. if(markreadfid.hasClass('subforum_minion'))
  254. {
  255. markreadfid.removeClass('subforum_minion').addClass('subforum_minioff');
  256. }
  257. else
  258. {
  259. markreadfid.removeClass('forum_on').addClass('forum_off');
  260. }
  261. markreadfid.css("cursor", "default").attr("title", lang.no_new_posts);
  262. }
  263. },
  264.  
  265. unHTMLchars: function(text)
  266. {
  267. text = text.replace(/&lt;/g, "<");
  268. text = text.replace(/&gt;/g, ">");
  269. text = text.replace(/&nbsp;/g, " ");
  270. text = text.replace(/&quot;/g, "\"");
  271. text = text.replace(/&amp;/g, "&");
  272. return text;
  273. },
  274.  
  275. HTMLchars: function(text)
  276. {
  277. text = text.replace(new RegExp("&(?!#[0-9]+;)", "g"), "&amp;");
  278. text = text.replace(/</g, "&lt;");
  279. text = text.replace(/>/g, "&gt;");
  280. text = text.replace(/"/g, "&quot;");
  281. return text;
  282. },
  283.  
  284. changeLanguage: function()
  285. {
  286. form = $("#lang_select");
  287. if(!form.length)
  288. {
  289. return false;
  290. }
  291. form.submit();
  292. },
  293.  
  294. changeTheme: function()
  295. {
  296. form = $("#theme_select");
  297. if(!form.length)
  298. {
  299. return false;
  300. }
  301. form.submit();
  302. },
  303.  
  304. detectDSTChange: function(timezone_with_dst)
  305. {
  306. var date = new Date();
  307. var local_offset = date.getTimezoneOffset() / 60;
  308. if(Math.abs(parseInt(timezone_with_dst) + local_offset) == 1)
  309. {
  310. $.ajax(
  311. {
  312. url: 'misc.php?action=dstswitch&ajax=1',
  313. async: true,
  314. method: 'post',
  315. error: function (request)
  316. {
  317. if(use_xmlhttprequest != 1)
  318. {
  319. var form = $("<form />",
  320. {
  321. method: "post",
  322. action: "misc.php",
  323. style: "display: none;"
  324. });
  325.  
  326. form.append(
  327. $("<input />",
  328. {
  329. name: "action",
  330. type: "hidden",
  331. value: "dstswitch"
  332. })
  333. );
  334.  
  335. $("body").append(form);
  336. form.submit();
  337. }
  338. }
  339. });
  340. }
  341. },
  342.  
  343. dismissPMNotice: function(bburl)
  344. {
  345. var pm_notice = $("#pm_notice");
  346. if(!pm_notice.length)
  347. {
  348. return false;
  349. }
  350.  
  351. if(use_xmlhttprequest != 1)
  352. {
  353. return true;
  354. }
  355.  
  356. $.ajax(
  357. {
  358. type: 'post',
  359. url: bburl + 'private.php?action=dismiss_notice',
  360. data: { ajax: 1, my_post_key: my_post_key },
  361. async: true
  362. });
  363. pm_notice.remove();
  364. return false;
  365. },
  366.  
  367. submitReputation: function(uid, pid, del)
  368. {
  369. // Get form, serialize it and send it
  370. var datastring = $(".reputation_"+uid+"_"+pid).serialize();
  371.  
  372. if(del == 1)
  373. datastring = datastring + '&delete=1';
  374.  
  375. $.ajax({
  376. type: "POST",
  377. url: "reputation.php?modal=1",
  378. data: datastring,
  379. dataType: "html",
  380. success: function(data) {
  381. // Replace modal HTML (we have to access by class because the modals are appended to the end of the body, and when we get by class we get the last element of that class - which is what we want)
  382. $(".modal_"+uid+"_"+pid).fadeOut('slow', function() {
  383. $(".modal_"+uid+"_"+pid).html(data);
  384. $(".modal_"+uid+"_"+pid).fadeIn('slow');
  385. $(".modal").fadeIn('slow');
  386. });
  387. },
  388. error: function(){
  389. alert(lang.unknown_error);
  390. }
  391. });
  392.  
  393. return false;
  394. },
  395.  
  396. deleteAnnouncement: function(data)
  397. {
  398. $.prompt(announcement_quickdelete_confirm, {
  399. buttons:[
  400. {title: yes_confirm, value: true},
  401. {title: no_confirm, value: false}
  402. ],
  403. submit: function(e,v,m,f){
  404. if(v == true)
  405. {
  406. window.location=data.href.replace('action=delete_announcement','action=do_delete_announcement');
  407. }
  408. }
  409. });
  410.  
  411. return false;
  412. },
  413.  
  414. // Fixes https://github.com/mybb/mybb/issues/1232
  415. select2: function()
  416. {
  417. if(typeof $.fn.select2 !== "undefined")
  418. {
  419. $.extend($.fn.select2.defaults, {
  420. formatMatches: function (matches) {
  421. if(matches == 1)
  422. {
  423. return lang.select2_match;
  424. }
  425. else
  426. {
  427. return lang.select2_matches.replace('{1}',matches);
  428. }
  429. },
  430. formatNoMatches: function () {
  431. return lang.select2_nomatches;
  432. },
  433. formatInputTooShort: function (input, min) {
  434. var n = min - input.length;
  435. if( n == 1)
  436. {
  437. return lang.select2_inputtooshort_single;
  438. }
  439. else
  440. {
  441. return lang.select2_inputtooshort_plural.replace('{1}', n);
  442. }
  443. },
  444. formatInputTooLong: function (input, max) {
  445. var n = input.length - max;
  446. if( n == 1)
  447. {
  448. return lang.select2_inputtoolong_single;
  449. }
  450. else
  451. {
  452. return lang.select2_inputtoolong_plural.replace('{1}', n);
  453. }
  454. },
  455. formatSelectionTooBig: function (limit) {
  456. if( limit == 1)
  457. {
  458. return lang.select2_selectiontoobig_single;
  459. }
  460. else
  461. {
  462. return lang.select2_selectiontoobig_plural.replace('{1}', limit);
  463. }
  464. },
  465. formatLoadMore: function (pageNumber) {
  466. return lang.select2_loadmore;
  467. },
  468. formatSearching: function () {
  469. return lang.select2_searching;
  470. }
  471. });
  472. }
  473. }
  474. };
  475.  
  476. var Cookie = {
  477. get: function(name)
  478. {
  479. name = cookiePrefix + name;
  480. return $.cookie(name);
  481. },
  482.  
  483. set: function(name, value, expires)
  484. {
  485. name = cookiePrefix + name;
  486. if(!expires)
  487. {
  488. expires = 315360000; // 10*365*24*60*60 => 10 years
  489. }
  490.  
  491. expire = new Date();
  492. expire.setTime(expire.getTime()+(expires*1000));
  493.  
  494. options = {
  495. expires: expire,
  496. path: cookiePath,
  497. domain: cookieDomain
  498. };
  499.  
  500. return $.cookie(name, value, options);
  501. },
  502.  
  503. unset: function(name)
  504. {
  505. name = cookiePrefix + name;
  506.  
  507. options = {
  508. path: cookiePath,
  509. domain: cookieDomain
  510. };
  511. return $.removeCookie(name, options);
  512. }
  513. };
  514.  
  515. var expandables = {
  516.  
  517. init: function()
  518. {
  519. var expanders = $(".expcolimage .expander");
  520. if(expanders.length)
  521. {
  522. expanders.each(function()
  523. {
  524. var expander = $(this);
  525. if(expander.attr("id") == false)
  526. {
  527. return;
  528. }
  529.  
  530. expander.click(function()
  531. {
  532. controls = expander.attr("id").replace("_img", "");
  533. expandables.expandCollapse(this, controls);
  534. });
  535.  
  536. if(MyBB.browser == "ie")
  537. {
  538. expander.css("cursor", "hand");
  539. }
  540. else
  541. {
  542. expander.css("cursor", "pointer");
  543. }
  544. });
  545. }
  546. },
  547.  
  548. expandCollapse: function(e, controls)
  549. {
  550. element = $(e);
  551.  
  552. if(!element || controls == false)
  553. {
  554. return false;
  555. }
  556. var expandedItem = $("#"+controls+"_e");
  557. var collapsedItem = $("#"+controls+"_c");
  558.  
  559. if(expandedItem.length && collapsedItem.length)
  560. {
  561. // Expanding
  562. if(expandedItem.is(":hidden"))
  563. {
  564. expandedItem.toggle("fast");
  565. collapsedItem.toggle("fast");
  566. this.saveCollapsed(controls);
  567. }
  568. // Collapsing
  569. else
  570. {
  571. expandedItem.toggle("fast");
  572. collapsedItem.toggle("fast");
  573. this.saveCollapsed(controls, 1);
  574. }
  575. }
  576. else if(expandedItem.length && !collapsedItem.length)
  577. {
  578. // Expanding
  579. if(expandedItem.is(":hidden"))
  580. {
  581. expandedItem.toggle("fast");
  582. element.attr("src", element.attr("src").replace(/collapse_collapsed\.(gif|jpg|jpeg|bmp|png)$/i, "collapse.$1"))
  583. .attr("alt", "[-]")
  584. .attr("title", "[-]");
  585. element.parent().parent('td').removeClass('tcat_collapse_collapsed');
  586. element.parent().parent('.thead').removeClass('thead_collapsed');
  587. this.saveCollapsed(controls);
  588. }
  589. // Collapsing
  590. else
  591. {
  592. expandedItem.toggle("fast");
  593. element.attr("src", element.attr("src").replace(/collapse\.(gif|jpg|jpeg|bmp|png)$/i, "collapse_collapsed.$1"))
  594. .attr("alt", "[+]")
  595. .attr("title", "[+]");
  596. element.parent().parent('td').addClass('tcat_collapse_collapsed');
  597. element.parent().parent('.thead').addClass('thead_collapsed');
  598. this.saveCollapsed(controls, 1);
  599. }
  600. }
  601. return true;
  602. },
  603.  
  604. saveCollapsed: function(id, add)
  605. {
  606. var saved = [];
  607. var newCollapsed = [];
  608. var collapsed = Cookie.get('collapsed');
  609.  
  610. if(collapsed)
  611. {
  612. saved = collapsed.split("|");
  613.  
  614. $.each(saved, function(intIndex, objValue)
  615. {
  616. if(objValue != id && objValue != "")
  617. {
  618. newCollapsed[newCollapsed.length] = objValue;
  619. }
  620. });
  621. }
  622.  
  623. if(add == 1)
  624. {
  625. newCollapsed[newCollapsed.length] = id;
  626. }
  627. Cookie.set('collapsed', newCollapsed.join("|"));
  628. }
  629. };
  630.  
  631. /* Lang this! */
  632. var lang = {
  633.  
  634. };
  635.  
  636. MyBB.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement