scripts.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. $('body').on('click', '.spoiler', function() {
  2. $(this).toggle();
  3. $(this).next('div').toggle();
  4. });
  5. $('body').on('click', '.blur', function(e) {
  6. e.stopPropagation();
  7. $(this).prev().toggle();
  8. $(this).toggle();
  9. $(this).next('a').toggle();
  10. });
  11. $('body').on('click', '.toggleblur', function(e) {
  12. e.stopPropagation();
  13. $(this).toggle();
  14. $(this).next('a').next('a').toggle();
  15. $(this).next('a').toggle();
  16. });
  17. $('body').on('click', '#emoji', function(e) {
  18. $(this).closest(".element").find('.picker').toggle();
  19. $('#emojisearch').focus();
  20. });
  21. $('body').on('click', '#contact', function(e) {
  22. $(this).closest(".element").find('.contactpicker').toggle();
  23. $('#contactsearch').focus();
  24. });
  25. $('body').on('click', '.emoji', function(e) {
  26. var code = $(this).attr("title");
  27. console.log(code);
  28. boxtxt = $(this).closest(".element").find("#status").val();
  29. $(this).closest(".element").find("#status").val(boxtxt + ":"+code+":");
  30. });
  31. $('body').on('click', '.contact', function(e) {
  32. var code = $(this).attr("title");
  33. console.log(code);
  34. boxtxt = $(this).closest(".element").find("#status").val();
  35. $(this).closest(".element").find("#status").val(boxtxt + code+" ");
  36. });
  37. $(document).on("change paste keyup","#emojisearch",function () {
  38. var val = $(this).val();
  39. var list = $(this).closest('.element').find('.emojilist');
  40. console.log(val);
  41. $.get("action.php?a=true&emoji=" + val, function(data) {
  42. list.html(data);
  43. });
  44. });
  45. $(document).on("change paste keyup","#contactsearch",function () {
  46. var val = $(this).val();
  47. var list = $(this).closest('.element').find('.contactlist');
  48. console.log(val);
  49. $.get("action.php?a=true&contact=" + val, function(data) {
  50. list.html(data);
  51. });
  52. });
  53. // Open Lightbox
  54. $('body').on('click', '.open-lightbox', function(e) {
  55. e.preventDefault();
  56. e.stopPropagation();
  57. var image = $(this).attr('href');
  58. $('html').addClass('no-scroll');
  59. $('body').append('<div class="lightbox-opened"><img style="max-height:100%; max-width:100%;" src="' + image + '"></div>');
  60. });
  61. // Close Lightbox
  62. $('body').on('click', '.lightbox-opened', function() {
  63. $('html').removeClass('no-scroll');
  64. $('.lightbox-opened').remove();
  65. });
  66. window.addEventListener("scroll", function() {
  67. onScrollDiv()
  68. });
  69. window.addEventListener("DOMContentLoaded", function() {
  70. onScrollDiv()
  71. });
  72. function onScrollDiv() {
  73. var images = document.querySelectorAll('.lazyload');
  74. for (var i = 0, nb = images.length; i < nb; i++) {
  75. var img = images[i]
  76. var rect = img.getBoundingClientRect();
  77. var isVisible = ((rect.top - window.innerHeight) < 500 && (rect.bottom) > -50) ? true : false;
  78. if (isVisible) {
  79. if (!img.src) {
  80. img.src = img.dataset.src;
  81. }
  82. }
  83. }
  84. }
  85. $('body').on('click', '.replies', function(e) {
  86. e.preventDefault;
  87. $(".reply").remove();
  88. $(".element").removeClass("element_pad");
  89. $(this).closest(".element").addClass("element_pad");
  90. /*$('.replies_container').html('');*/
  91. var id = $(this).parent().parent().attr('id');
  92. if($('#' + id+'.replies_container').find('.reply').length < 1){
  93. $('#' + id+'.replies_container').html("<p><img src='img/loading.gif'></p>");
  94. }
  95. $.get("action.php?a=true&replies=" + id, function(data) {
  96. $('#' + id+'.replies_container').html(data);
  97. $('#' + id+'.replies_container').delay(800).fadeIn(400);
  98. $('#a' + id).html('');
  99. $('#' + id+".replies_container .ancestor").appendTo('#a' + id);
  100. });
  101. });
  102. $.fn.isOnScreen = function(){
  103. var win = $(window);
  104. var viewport = {
  105. top : win.scrollTop(),
  106. left : win.scrollLeft()
  107. };
  108. viewport.right = viewport.left + win.width();
  109. viewport.bottom = viewport.top + win.height();
  110. var bounds = this.offset();
  111. bounds.right = bounds.left + this.outerWidth();
  112. bounds.bottom = bounds.top + this.outerHeight();
  113. return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
  114. };
  115. /*
  116. $('body').on('click', '.postbody:not(a)', function(e) {
  117. e.preventDefault;
  118. $(".reply").remove();
  119. $(".element").removeClass("element_pad");
  120. $(this).closest(".element").addClass("element_pad");
  121. //$('.replies_container').html('');
  122. var id = $(this).closest(".post").attr('id');
  123. if($('#' + id+'.replies_container').find('.reply').length < 1){
  124. $('#' + id+'.replies_container').html("<p><img src='img/loading.gif'></p>");
  125. }
  126. $.get("action.php?a=true&replies=" + id, function(data) {
  127. $('#' + id+'.replies_container').html(data);
  128. $('#' + id+'.replies_container').delay(800).fadeIn(400);
  129. $('#a' + id).html('');
  130. $('#' + id+".replies_container .ancestor").appendTo('#a' + id);
  131. });
  132. });
  133. */
  134. /*
  135. $('body').on('click', '.postbody:not(a)', function(e) {
  136. e.preventDefault;
  137. $(".reply").remove();
  138. $(".element").removeClass("element_pad");
  139. $(this).closest(".element").addClass("element_pad");
  140. var id = $(this).closest(".post").attr('id');
  141. var offset = $('#'+id+' .postHeader').offset().top + 200;
  142. if($('#' + id+'.replies_container').find('.reply').length < 1){
  143. $('#' + id+'.replies_container').html("<p><img src='img/loading.gif'></p>");
  144. }
  145. $.get("action.php?a=true&replies=" + id, function(data) {
  146. $('#' + id+'.replies_container').html(data);
  147. $('#' + id+'.replies_container').delay(800).fadeIn(400);
  148. $('#a' + id).html('');
  149. $.when($('#' + id+".replies_container .ancestor").appendTo('#a' + id)).then(function() {
  150. if ($('#'+id+'.post_buttons').isOnScreen() == false) {
  151. $('html, body').animate({
  152. scrollTop: offset
  153. }, 1000);
  154. }
  155. });
  156. });
  157. });
  158. */
  159. $('body').on('click', '.ldr:not(.tlicon)', function(e) {
  160. $('.tlicon').each(function(a){
  161. $( this ).removeClass('tiselected')
  162. });
  163. });
  164. $('body').on('click', '.ldr', function(e) {
  165. e.preventDefault();
  166. location.hash = "#top";
  167. $('#loader').html('');
  168. $('#loaded').remove();
  169. var url = $(this).attr('href');
  170. var id = $(this).attr('id');
  171. localStorage.setItem("content", $('#content .element').detach());
  172. $('#content').html('<center><div class="loadingImage"></div></center>');
  173. $.get(url + "&ajax=1", function(data) {
  174. $('#content').html(data);
  175. history.pushState({}, "Dashboard FE", url);
  176. var thread = getUrlParameter('thread');
  177. });
  178. });
  179. $('body').on('click', '.gotop a', function(e) {
  180. e.preventDefault();
  181. $('html, body').animate({
  182. scrollTop: 0
  183. }, 800);
  184. return false;
  185. });
  186. $('body').on('click', '.topbar:not(a)', function(e) {
  187. if(e.target !== e.currentTarget) return;
  188. e.preventDefault();
  189. $('html, body').animate({
  190. scrollTop: 0
  191. }, 800);
  192. return false;
  193. });
  194. $('body').on('click', '#loader', function() {
  195. var cnt = $("#loaded").contents();
  196. // $("#content").prepend(cnt);
  197. $('#content').find('.element').first().after(cnt);
  198. $("#loaded").remove();
  199. $("#loader").html('');
  200. });
  201. $('body').on('click', '.nsfw', function() {
  202. var id = $(this).attr('id');
  203. $.get("action.php?a=true&nsfw=" + id, function(data) {
  204. if (data == '1') {
  205. $('#' + id + '.nsfw').toggleClass('nsfw unnsfw');
  206. $('#' + id + '.unnsfw').html('NSFW <span class="fontello">&#xf205;</span>');
  207. }
  208. });
  209. });
  210. $('body').on('click', '.unnsfw', function() {
  211. var id = $(this).attr('id');
  212. $.get("action.php?a=true&nsfw=" + id, function(data) {
  213. if (data == '1') {
  214. $('#' + id + '.unnsfw').toggleClass('unnsfw nsfw');
  215. $('#' + id + '.nsfw').html('NSFW <span class="fontello">&#xf204;</span>');
  216. }
  217. });
  218. });
  219. $('body').on('click', '.block', function() {
  220. var id = $(this).attr('id');
  221. $.get("action.php?a=true&mode=true&block=" + id, function(data) {
  222. $('#' + id + '.block').removeClass('block').addClass('unblock');
  223. $('#' + id + '.unblock').html('Unblock');
  224. });
  225. });
  226. $('body').on('click', '.unblock', function() {
  227. var id = $(this).attr('id');
  228. $.get("action.php?a=true&mode=off&block=" + id, function(data) {
  229. $('#' + id + '.unblock').removeClass('unblock').addClass('block');
  230. $('#' + id + '.block').html('Block');
  231. });
  232. });
  233. $('body').on('click', '.autl', function() {
  234. var id = $(this).attr('id');
  235. var list = $(this).attr('list');
  236. $.get("action.php?a=true&mode=true&user=" + id + "&list=" + list, function(data) {
  237. $('#' + id + '.autl').removeClass('autl').addClass('rutl');
  238. /* $('#' + id + '.rutl li').html('Added'); */
  239. });
  240. });
  241. $('body').on('click', '.rutl', function() {
  242. var elem = $(this);
  243. var id = $(this).attr('id');
  244. var list = $(this).attr('list');
  245. $.get("action.php?a=true&mode=off&user=" + id + "&list=" + list, function(data) {
  246. $('#' + id + '.rutl').removeClass('rutl').addClass('autl');
  247. /* $(elem).find('li').html('Removed');*/
  248. });
  249. });
  250. $('body').on('click', '.hide', function() {
  251. var id = $(this).attr('id');
  252. $.get("action.php?a=true&mode=true&hide=" + id, function(data) {
  253. $('#' + id + '.hide').removeClass('hide').addClass('unhide');
  254. $('#' + id + '.unhide').html('Unhide Thread');
  255. console.log(data);
  256. });
  257. });
  258. $('body').on('click', '.unhide', function() {
  259. var id = $(this).attr('id');
  260. $.get("action.php?a=true&mode=off&hide=" + id, function(data) {
  261. $('#' + id + '.unhide').removeClass('unhide').addClass('hide');
  262. $('#' + id + '.hide').html('Hide Thread');
  263. console.log(data);
  264. });
  265. });
  266. $('body').on('click', '.bookmark', function() {
  267. var id = $(this).attr('id');
  268. $.get("action.php?a=true&mode=true&bookmark=" + id, function(data) {
  269. $('#' + id + '.bookmark').removeClass('bookmark').addClass('unbookmark');
  270. $('#' + id + '.unbookmark').html('Unbookmark');
  271. console.log(data);
  272. });
  273. });
  274. $('body').on('click', '.unbookmark', function() {
  275. var id = $(this).attr('id');
  276. $.get("action.php?a=true&mode=off&bookmark=" + id, function(data) {
  277. $('#' + id + '.unbookmark').removeClass('unbookmark').addClass('bookmark');
  278. $('#' + id + '.bookmark').html('Bookmark');
  279. console.log(data);
  280. });
  281. });
  282. $('body').on('click', '.follow', function() {
  283. var id = $(this).attr('id');
  284. $.get("action.php?a=true&follow=" + id, function(data) {
  285. console.log(data);
  286. if (data == '1') {
  287. $('#' + id + '.follow').removeClass('follow').addClass('unfollow');
  288. $('#' + id + '.unfollow').html('<span class=\'fontello\'></span> Following');
  289. }
  290. });
  291. });
  292. $('body').on('click', '.unfollow', function() {
  293. var id = $(this).attr('id');
  294. $.get("action.php?a=true&unfollow=" + id, function(data) {
  295. if (data == '1') {
  296. $('#' + id + '.unfollow').removeClass('unfollow').addClass('follow');
  297. $('#' + id + '.follow').html('Follow');
  298. }
  299. });
  300. });
  301. $('.container').on('mouseenter', '.user', function(event) {
  302. event.stopPropagation();
  303. event.stopImmediatePropagation();
  304. var id = $(this).attr('id');
  305. console.log(id);
  306. $(this).append("<div class='userinfo' id='" + id + "'><img src='loading.gif'></div>");
  307. $.when($.get("action.php?a=true&userinfo=" + id, function(data) {
  308. $('#' + id + '.userinfo').html(data);
  309. })).then(function(){
  310. $('#' + id + '.userinfo').fadeIn();
  311. });
  312. });
  313. $('.container').on('mouseleave', '.user', function(event) {
  314. event.stopPropagation();
  315. event.stopImmediatePropagation();
  316. $(this).find('.userinfo').fadeOut(300, function() { $(this).remove(); });
  317. });
  318. $('.container').on('mouseenter', '.preview', function(event) {
  319. event.stopPropagation();
  320. event.stopImmediatePropagation();
  321. var id = $(this).attr('id');
  322. console.log(id);
  323. $(this).before("<div class='notif previewpost' id='" + id + "'></div>");
  324. $.when($.get("action.php?a=true&previewpost=" + id, function(data) {
  325. $('#' + id + '.previewpost').html(data);
  326. })).then(function(){
  327. $('#' + id + '.previewpost').fadeIn();
  328. });
  329. });
  330. $('.container').on('mouseleave', '.preview', function(event) {
  331. event.stopPropagation();
  332. event.stopImmediatePropagation();
  333. $('.container').find('.previewpost').fadeOut(300, function() { $(this).remove(); });
  334. });
  335. var getUrlParameter = function getUrlParameter(sParam) {
  336. var sPageURL = window.location.search.substring(1),
  337. sURLVariables = sPageURL.split('&'),
  338. sParameterName,
  339. i;
  340. for (i = 0; i < sURLVariables.length; i++) {
  341. sParameterName = sURLVariables[i].split('=');
  342. if (sParameterName[0] === sParam) {
  343. return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
  344. }
  345. }
  346. };
  347. function getMode() {
  348. if (typeof getUrlParameter('user') !== 'undefined') {
  349. console.log('list');
  350. return "&user=" + getUrlParameter('user');
  351. }
  352. if (typeof getUrlParameter('list') !== 'undefined') {
  353. console.log('list');
  354. return "&list=" + getUrlParameter('list');
  355. }
  356. if (typeof getUrlParameter('mode') !== 'undefined') {
  357. console.log('mode');
  358. return "&mode=" + getUrlParameter('mode');
  359. }
  360. if (typeof getUrlParameter('tag') !== 'undefined') {
  361. console.log('tag');
  362. return "&tag=" + getUrlParameter('tag');
  363. }
  364. if (typeof getUrlParameter('search') !== 'undefined') {
  365. console.log('tag');
  366. return "&search=" + getUrlParameter('search');
  367. }
  368. return "&mode=federated";
  369. };
  370. function loadmore(){
  371. var thread = getUrlParameter('thread');
  372. if (typeof thread !== 'undefined') {
  373. return false;
  374. }
  375. if (typeof getUrlParameter('search') !== 'undefined') {
  376. return false;
  377. }
  378. var thread = getUrlParameter('thread');
  379. if (typeof thread === 'undefined') {
  380. var error = $(".error").length;
  381. if (error < 1) {
  382. pageMode = getMode();
  383. var id = $('.post').last().attr('pid');
  384. $('.loadmore').html("<img src='img/loading.gif'>")
  385. $.get("index.php?ajax=1&next=" + id + "" + pageMode, function(data) {
  386. $('.loadmore').parent().before(data);
  387. $('.loadmore').html("Load More Posts")
  388. /*$('.loadmore').parent().detach();
  389. $('#content').append(data);
  390. $('.loadmore').parent().appendTo('#content');
  391. */
  392. });
  393. }
  394. }
  395. }
  396. $(window).scroll(function() {
  397. if ($(window).scrollTop() == $(document).height() - $(window).height()) {
  398. loadmore();
  399. }
  400. });
  401. $('body').on('click', '.loadmore', function() {
  402. loadmore();
  403. });
  404. function newPosts() {
  405. var url = window.location.href;
  406. var thread = getUrlParameter('thread');
  407. if (typeof thread !== 'undefined') {
  408. return false;
  409. }
  410. var search = getUrlParameter('search');
  411. if (typeof search !== 'undefined') {
  412. return false;
  413. }
  414. var error = $(".error").length;
  415. if (error >= 1) {
  416. return false;
  417. }
  418. var id = $(".post").first().attr('pid');
  419. pageMode = getMode();
  420. if (getUrlParameter('mode') == 'bookmarks') {
  421. return false;
  422. }
  423. var page = getUrlParameter('page');
  424. if (typeof page !== 'undefined') {
  425. return false;
  426. }
  427. $.get("index.php?ajax=1&since=" + id + "" + pageMode, function(data) {
  428. if (window.location.href !== url){
  429. return false;
  430. }
  431. if (data) {
  432. var scroll = $(window).scrollTop();
  433. if (scroll > 1000) {
  434. $('#loader').html("<div class='avatar' style='height:0px;'></div><div class='loader' style='display:table-cell; height:50px; line-height:50px;'><a class='link' style='margin:5px;' href='#'>Load Newer Posts</a></div>");
  435. if ($('#loaded').length) {
  436. $('#loaded').prepend(data);
  437. } else {
  438. $('#loader').after("<div id='loaded' style='display:none'></div>");
  439. $('#loaded').prepend(data);
  440. }
  441. } else {
  442. if ($('#loaded').length) {
  443. $('#loaded').prepend(data);
  444. } else {
  445. $('#content').find('.element').first().after(data);
  446. }
  447. }
  448. }
  449. });
  450. };
  451. window.setInterval(function() {
  452. var timestamp;
  453. $('.postAge').each(function(a){
  454. timestamp = $(this).attr('id');
  455. $(this).html(timeSince(timestamp)+' ago');
  456. });
  457. newPosts();
  458. }, 25000);
  459. function themecheck(name){
  460. if(name.value == "custom"){
  461. $('#customtheme').css("display","block");
  462. }
  463. else{
  464. $('#customtheme').css("display","none");
  465. }
  466. };
  467. function timeSince(date) {
  468. /* https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site */
  469. var seconds = Math.floor((new Date() - (date*1000)) / 1000);
  470. var interval = Math.floor(seconds / 31536000);
  471. if (interval >= 1) {
  472. return interval + " year"+(interval > 1 ? "s" : "");
  473. }
  474. interval = Math.floor(seconds / 2592000);
  475. if (interval >= 1) {
  476. return interval + " month"+(interval > 1 ? "s" : "");
  477. }
  478. interval = Math.floor(seconds / 604800);
  479. if (interval >= 1) {
  480. return interval + " week"+(interval > 1 ? "s" : "");
  481. }
  482. interval = Math.floor(seconds / 86400);
  483. if (interval >= 1) {
  484. return interval + " day"+(interval > 1 ? "s" : "");
  485. }
  486. interval = Math.floor(seconds / 3600);
  487. if (interval >= 1) {
  488. return interval + " hour"+(interval > 1 ? "s" : "");
  489. }
  490. interval = Math.floor(seconds / 60);
  491. if (interval >= 1) {
  492. return interval + " minute"+(interval > 1 ? "s" : "");
  493. }
  494. if (interval < 0) {
  495. return " just now";
  496. }
  497. return Math.floor(seconds) + " seconds";
  498. }