Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comments.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. var username;
  2. var postid;
  3. var url = {path: window.location.pathname.split('/').reverse()[0].split('.')[0]};
  4. function QuoteJump(event, post) {
  5. var button = event.button;
  6. var url, pattern;
  7. if (isNaN(post.charAt(0))) {
  8. switch (post.charAt(0)) {
  9. case 'a': // artist comment
  10. url = 'artist';
  11. break;
  12. case 't': // torrent comment
  13. url = 'torrents';
  14. break;
  15. case 'c': // collage comment
  16. url = 'collages';
  17. break;
  18. case 'r': // request comment
  19. url = 'requests';
  20. break;
  21. default:
  22. return;
  23. }
  24. pattern = new RegExp(url + '\.php');
  25. post = post.substr(1);
  26. url = 'comments.php?action=jump&postid=' + post;
  27. } else {
  28. // forum post
  29. url = 'forums.php?action=viewthread&postid=' + post;
  30. pattern = /forums\.php/;
  31. }
  32. var hash = "#post" + post;
  33. if (button == 0) {
  34. if ($(hash).raw() != null && location.href.match(pattern)) {
  35. window.location.hash = hash;
  36. } else {
  37. window.open(url, '_self');
  38. }
  39. } else if (button == 1) {
  40. window.open(url, '_window');
  41. }
  42. }
  43. var original_post;
  44. function Quote(post, user, link = false) {
  45. username = user;
  46. postid = post;
  47. // check if reply_box element exists and that user is in the forums
  48. if (!$('#reply_box').length && url.path == "forums") {
  49. if ($("#quote_" + postid).text() == "Quote") {
  50. original_post = $("#content" + postid).html();
  51. $("#quote_" + postid).text("Unquote");
  52. $.ajax({
  53. type : "POST",
  54. url : "ajax.php?action=raw_bbcode",
  55. dataType : "json",
  56. data : {
  57. "postid" : postid
  58. }
  59. }).done(function(response) {
  60. $("#content" + postid).html(response['response']['body']);
  61. var range = document.createRange();
  62. range.selectNodeContents($("#content" + postid).get(0));
  63. var sel = window.getSelection();
  64. sel.removeAllRanges();
  65. sel.addRange(range);
  66. });
  67. } else {
  68. document.getSelection().removeAllRanges();
  69. $("#content" + postid).html(original_post);
  70. $("#quote_" + postid).text("Quote");
  71. }
  72. } else {
  73. var target = '';
  74. var requrl = '';
  75. if (url.path == "inbox") {
  76. requrl = 'inbox.php?action=get_post&post=' + post;
  77. } else {
  78. requrl = 'comments.php?action=get&postid=' + post;
  79. }
  80. if (link == true) {
  81. if (url.path == "artist") {
  82. // artist comment
  83. target = 'a';
  84. } else if (url.path == "torrents") {
  85. // torrent comment
  86. target = 't';
  87. } else if (url.path == "collages") {
  88. // collage comment
  89. target = 'c';
  90. } else if (url.path == "requests") {
  91. // request comment
  92. target = 'r';
  93. } else {
  94. // forum post
  95. requrl = 'forums.php?action=get_post&post=' + post;
  96. }
  97. target += post;
  98. }
  99. ajax.get(requrl, function(response) {
  100. if ($('#quickpost').raw().value !== '') {
  101. $('#quickpost').raw().value = $('#quickpost').raw().value + "\n\n";
  102. }
  103. $('#quickpost').raw().value = $('#quickpost').raw().value + "[quote=" + username + (link == true ? "|" + target : "") + "]" +
  104. //response.replace(/(img|aud)(\]|=)/ig,'url$2').replace(/\[url\=(https?:\/\/[^\s\[\]<>"\'()]+?)\]\[url\](.+?)\[\/url\]\[\/url\]/gi, "[url]$1[/url]")
  105. html_entity_decode(response)
  106. + "[/quote]";
  107. resize('quickpost');
  108. });
  109. }
  110. }
  111. function Edit_Form(post,key) {
  112. postid = post;
  113. var boxWidth, postuserid, pmbox, inputname;
  114. //If no edit is already going underway or a previous edit was finished, make the necessary dom changes.
  115. if (!$('#editbox' + postid).results() || $('#editbox' + postid + '.hidden').results()) {
  116. $('#reply_box').ghide();
  117. if (location.href.match(/torrents\.php/)
  118. || location.href.match(/artist\.php/)) {
  119. boxWidth = "50";
  120. } else {
  121. boxWidth = "80";
  122. }
  123. postuserid = $('#post' + postid + ' strong a').attr('href').split('=')[1];
  124. if (postuserid != userid) {
  125. pmbox = '<span id="pmbox' + postid + '"><label>PM user on edit? <input type="checkbox" name="pm" value="1" /></label></span>';
  126. } else {
  127. pmbox = '';
  128. };
  129. if (location.href.match(/forums\.php/)) {
  130. inputname = "post";
  131. } else {
  132. inputname = "postid";
  133. }
  134. $('#bar' + postid).raw().cancel = $('#content' + postid).raw().innerHTML;
  135. $('#bar' + postid).raw().oldbar = $('#bar' + postid).raw().innerHTML;
  136. $('#content' + postid).raw().innerHTML = "<div id=\"preview" + postid + "\"></div><form id=\"form" + postid + "\" method=\"post\" action=\"\">" + pmbox + "<input type=\"hidden\" name=\"auth\" value=\"" + authkey + "\" /><input type=\"hidden\" name=\"key\" value=\"" + key + "\" /><input type=\"hidden\" name=\"" + inputname + "\" value=\"" + postid + "\" /><textarea id=\"editbox" + postid + "\" onkeyup=\"resize('editbox" + postid + "');\" name=\"body\" cols=\"" + boxWidth + "\" rows=\"10\"></textarea></form>";
  137. $('#bar' + postid).raw().innerHTML = '<input type="button" value="Preview" onclick="Preview_Edit(' + postid + ');" /><input type="button" value="Post" onclick="Save_Edit(' + postid + ')" /><input type="button" value="Cancel" onclick="Cancel_Edit(' + postid + ');" />';
  138. }
  139. /* If it's the initial edit, fetch the post content to be edited.
  140. * If editing is already underway and edit is pressed again, reset the post
  141. * (keeps current functionality, move into brackets to stop from happening).
  142. */
  143. if (location.href.match(/forums\.php/)) {
  144. ajax.get("?action=get_post&post=" + postid, function(response) {
  145. $('#editbox' + postid).raw().value = html_entity_decode(response);
  146. resize('editbox' + postid);
  147. });
  148. } else {
  149. ajax.get("comments.php?action=get&postid=" + postid, function(response) {
  150. $('#editbox' + postid).raw().value = html_entity_decode(response);
  151. resize('editbox' + postid);
  152. });
  153. }
  154. }
  155. function Cancel_Edit(postid) {
  156. var answer = confirm("Are you sure you want to cancel?");
  157. if (answer) {
  158. $('#reply_box').gshow();
  159. $('#bar' + postid).raw().innerHTML = $('#bar' + postid).raw().oldbar;
  160. $('#content' + postid).raw().innerHTML = $('#bar' + postid).raw().cancel;
  161. }
  162. }
  163. function Preview_Edit(postid) {
  164. $('#bar' + postid).raw().innerHTML = "<input type=\"button\" value=\"Editor\" onclick=\"Cancel_Preview(" + postid + ");\" /><input type=\"button\" value=\"Post\" onclick=\"Save_Edit(" + postid + ")\" /><input type=\"button\" value=\"Cancel\" onclick=\"Cancel_Edit(" + postid + ");\" />";
  165. ajax.post("ajax.php?action=preview","form" + postid, function(response) {
  166. $('#preview' + postid).raw().innerHTML = response;
  167. $('#editbox' + postid).ghide();
  168. });
  169. }
  170. function Cancel_Preview(postid) {
  171. $('#bar' + postid).raw().innerHTML = "<input type=\"button\" value=\"Preview\" onclick=\"Preview_Edit(" + postid + ");\" /><input type=\"button\" value=\"Post\" onclick=\"Save_Edit(" + postid + ")\" /><input type=\"button\" value=\"Cancel\" onclick=\"Cancel_Edit(" + postid + ");\" />";
  172. $('#preview' + postid).raw().innerHTML = "";
  173. $('#editbox' + postid).gshow();
  174. }
  175. function Save_Edit(postid) {
  176. $('#reply_box').gshow();
  177. if (location.href.match(/forums\.php/)) {
  178. ajax.post("forums.php?action=takeedit","form" + postid, function (response) {
  179. $('#bar' + postid).raw().innerHTML = "<a href=\"reports.php?action=report&amp;type=post&amp;id="+postid+"\" class=\"brackets\">Report</a>&nbsp;<a href=\"#\">&uarr;</a>";
  180. $('#preview' + postid).raw().innerHTML = response;
  181. $('#editbox' + postid).ghide();
  182. $('#pmbox' + postid).ghide();
  183. });
  184. } else {
  185. ajax.post("comments.php?action=take_edit","form" + postid, function (response) {
  186. $('#bar' + postid).raw().innerHTML = "";
  187. $('#preview' + postid).raw().innerHTML = response;
  188. $('#editbox' + postid).ghide();
  189. $('#pmbox' + postid).ghide();
  190. });
  191. }
  192. }
  193. function Delete(post) {
  194. postid = post;
  195. if (confirm('Are you sure you wish to delete this post?') == true) {
  196. if (location.href.match(/forums\.php/)) {
  197. ajax.get("forums.php?action=delete&auth=" + authkey + "&postid=" + postid, function () {
  198. $('#post' + postid).ghide();
  199. });
  200. } else {
  201. ajax.get("comments.php?action=take_delete&auth=" + authkey + "&postid=" + postid, function () {
  202. $('#post' + postid).ghide();
  203. });
  204. }
  205. }
  206. }
  207. function Quick_Preview() {
  208. var quickreplybuttons;
  209. $('#post_preview').raw().value = "Make changes";
  210. $('#post_preview').raw().preview = true;
  211. ajax.post("ajax.php?action=preview", "quickpostform", function(response) {
  212. $('#quickreplypreview').gshow();
  213. $('#contentpreview').raw().innerHTML = response;
  214. $('#quickreplytext').ghide();
  215. });
  216. }
  217. function Quick_Edit() {
  218. var quickreplybuttons;
  219. $('#post_preview').raw().value = "Preview";
  220. $('#post_preview').raw().preview = false;
  221. $('#quickreplypreview').ghide();
  222. $('#quickreplytext').gshow();
  223. }
  224. function Newthread_Preview(mode) {
  225. $('#newthreadpreviewbutton').gtoggle();
  226. $('#newthreadeditbutton').gtoggle();
  227. if (mode) { // Preview
  228. ajax.post("ajax.php?action=preview", "newthreadform", function(response) {
  229. $('#contentpreview').raw().innerHTML = response;
  230. });
  231. $('#newthreadtitle').raw().innerHTML = $('#title').raw().value;
  232. var pollanswers = $('#answer_block').raw();
  233. if (pollanswers && pollanswers.children.length > 4) {
  234. pollanswers = pollanswers.children;
  235. $('#pollquestion').raw().innerHTML = $('#pollquestionfield').raw().value;
  236. for (var i = 0; i < pollanswers.length; i += 2) {
  237. if (!pollanswers[i].value) {
  238. continue;
  239. }
  240. var el = document.createElement('input');
  241. el.id = 'answer_' + (i + 1);
  242. el.type = 'radio';
  243. el.name = 'vote';
  244. $('#pollanswers').raw().appendChild(el);
  245. $('#pollanswers').raw().appendChild(document.createTextNode(' '));
  246. el = document.createElement('label');
  247. el.htmlFor = 'answer_' + (i + 1);
  248. el.innerHTML = pollanswers[i].value;
  249. $('#pollanswers').raw().appendChild(el);
  250. $('#pollanswers').raw().appendChild(document.createElement('br'));
  251. }
  252. if ($('#pollanswers').raw().children.length > 4) {
  253. $('#pollpreview').gshow();
  254. }
  255. }
  256. } else { // Back to editor
  257. $('#pollpreview').ghide();
  258. $('#newthreadtitle').raw().innerHTML = 'New Topic';
  259. var pollanswers = $('#pollanswers').raw();
  260. if (pollanswers) {
  261. var el = document.createElement('div');
  262. el.id = 'pollanswers';
  263. pollanswers.parentNode.replaceChild(el, pollanswers);
  264. }
  265. }
  266. $('#newthreadtext').gtoggle();
  267. $('#newthreadpreview').gtoggle();
  268. $('#subscribediv').gtoggle();
  269. }
  270. function LoadEdit(type, post, depth) {
  271. ajax.get("forums.php?action=ajax_get_edit&postid=" + post + "&depth=" + depth + "&type=" + type, function(response) {
  272. $('#content' + post).raw().innerHTML = response;
  273. }
  274. );
  275. }
  276. function AddPollOption(id) {
  277. var list = $('#poll_options').raw();
  278. var item = document.createElement("li");
  279. var form = document.createElement("form");
  280. form.method = "POST";
  281. var auth = document.createElement("input");
  282. auth.type = "hidden";
  283. auth.name = "auth";
  284. auth.value = authkey;
  285. form.appendChild(auth);
  286. var action = document.createElement("input");
  287. action.type = "hidden";
  288. action.name = "action";
  289. action.value = "add_poll_option";
  290. form.appendChild(action);
  291. var threadid = document.createElement("input");
  292. threadid.type = "hidden";
  293. threadid.name = "threadid";
  294. threadid.value = id;
  295. form.appendChild(threadid);
  296. var input = document.createElement("input");
  297. input.type = "text";
  298. input.name = "new_option";
  299. input.size = "50";
  300. form.appendChild(input);
  301. var submit = document.createElement("input");
  302. submit.type = "submit";
  303. submit.id = "new_submit";
  304. submit.value = "Add";
  305. form.appendChild(submit);
  306. item.appendChild(form);
  307. list.appendChild(item);
  308. }
  309. /**
  310. * HTML5-compatible storage system
  311. * Tries to use 'oninput' event to detect text changes and sessionStorage to save it.
  312. *
  313. * new StoreText('some_textarea_id', 'some_form_id', 'some_topic_id')
  314. * The form is required to remove the stored text once it is submitted.
  315. *
  316. * Topic ID is required to retrieve the right text on the right topic
  317. **/
  318. function StoreText (field, form, topic) {
  319. this.field = document.getElementById(field);
  320. this.form = document.getElementById(form);
  321. this.key = 'auto_save_temp';
  322. this.keyID = 'auto_save_temp_id';
  323. this.topic = +topic;
  324. this.load();
  325. }
  326. StoreText.prototype = {
  327. constructor : StoreText,
  328. load : function () {
  329. if (this.enabled() && this.valid()) {
  330. this.retrieve();
  331. this.autosave();
  332. this.clearForm();
  333. }
  334. },
  335. valid : function () {
  336. return this.field && this.form && !isNaN(this.topic);
  337. },
  338. enabled : function () {
  339. return window.sessionStorage && typeof window.sessionStorage === 'object';
  340. },
  341. retrieve : function () {
  342. var r = sessionStorage.getItem(this.key);
  343. if (this.topic === +sessionStorage.getItem(this.keyID) && r) {
  344. this.field.value = r;
  345. }
  346. },
  347. remove : function () {
  348. sessionStorage.removeItem(this.keyID);
  349. sessionStorage.removeItem(this.key);
  350. },
  351. save : function () {
  352. sessionStorage.setItem(this.keyID, this.topic);
  353. sessionStorage.setItem(this.key, this.field.value);
  354. },
  355. autosave : function () {
  356. $(this.field).on(this.getInputEvent(), $.proxy(this.save, this));
  357. },
  358. getInputEvent : function () {
  359. var e;
  360. if ('oninput' in this.field) {
  361. e = 'input';
  362. } else if (document.body.addEventListener) {
  363. e = 'change keyup paste cut';
  364. } else {
  365. e = 'propertychange';
  366. }
  367. return e;
  368. },
  369. clearForm : function () {
  370. $(this.form).submit($.proxy(this.remove, this));
  371. }
  372. };
  373. $(document).ready(function() {
  374. var fadeSpeed = 0
  375. var avatars = new Array()
  376. $(".double_avatar").each(function() {
  377. if ($(this).data("gazelle-second-avatar")) {
  378. var secondAvatar = $(this).data("gazelle-second-avatar")
  379. var originalAvatar = $(this).attr("src")
  380. if ($.inArray(secondAvatar, avatars) == -1) {
  381. avatars.push(secondAvatar)
  382. image = new Image()
  383. image.src = secondAvatar
  384. }
  385. var that = $(this)
  386. $($(this).raw().parentNode.parentNode).hover(
  387. function() {
  388. that.attr("src", secondAvatar)
  389. },
  390. function() {
  391. that.attr("src", originalAvatar)
  392. }
  393. );
  394. $(this).one("load", function() {
  395. var par = $(this).parents('.avatar')
  396. if (par.height()) {
  397. par.raw().style.height = par.height()-2+'px'
  398. }
  399. })
  400. if (this.complete) $(this).load()
  401. }
  402. })
  403. document.querySelectorAll('[quote-jump]').forEach(function(el) {
  404. el.addEventListener('click', function(event) {
  405. QuoteJump(event, el.attributes['quote-jump'].value)
  406. })
  407. })
  408. })