diff --git a/js/scripts.js b/js/scripts.js index 4c6f394..9eb68fa 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -1,66 +1,66 @@ -$('body').on('click', '.spoiler', function() { +$('body').on('click', '.spoiler', function () { $(this).toggle(); $(this).next('div').toggle(); }); -$('body').on('click', '.blur', function(e) { +$('body').on('click', '.blur', function (e) { e.stopPropagation(); $(this).prev().toggle(); $(this).toggle(); $(this).next('a').toggle(); }); -$('body').on('click', '.toggleblur', function(e) { +$('body').on('click', '.toggleblur', function (e) { e.stopPropagation(); $(this).toggle(); $(this).next('a').next('a').toggle(); $(this).next('a').toggle(); }); -$('body').on('click', '#emoji', function(e) { +$('body').on('click', '#emoji', function (e) { $(this).closest(".element").find('.picker').toggle(); $('#emojisearch').focus(); }); -$('body').on('click', '#contact', function(e) { +$('body').on('click', '#contact', function (e) { $(this).closest(".element").find('.contactpicker').toggle(); $('#contactsearch').focus(); }); -$('body').on('click', '.emoji', function(e) { +$('body').on('click', '.emoji', function (e) { var code = $(this).attr("title"); console.log(code); boxtxt = $(this).closest(".element").find("#status").val(); - $(this).closest(".element").find("#status").val(boxtxt + ":"+code+":"); + $(this).closest(".element").find("#status").val(boxtxt + ":" + code + ":"); }); -$('body').on('click', '.contact', function(e) { +$('body').on('click', '.contact', function (e) { var code = $(this).attr("title"); console.log(code); boxtxt = $(this).closest(".element").find("#status").val(); - $(this).closest(".element").find("#status").val(boxtxt + code+" "); + $(this).closest(".element").find("#status").val(boxtxt + code + " "); }); -$(document).on("change paste keyup","#emojisearch",function () { - var val = $(this).val(); - var list = $(this).closest('.element').find('.emojilist'); - console.log(val); - $.get("action.php?a=true&emoji=" + val, function(data) { +$(document).on("change paste keyup", "#emojisearch", function () { + var val = $(this).val(); + var list = $(this).closest('.element').find('.emojilist'); + console.log(val); + $.get("action.php?a=true&emoji=" + val, function (data) { list.html(data); }); }); -$(document).on("change paste keyup","#contactsearch",function () { - var val = $(this).val(); - var list = $(this).closest('.element').find('.contactlist'); - console.log(val); - $.get("action.php?a=true&contact=" + val, function(data) { +$(document).on("change paste keyup", "#contactsearch", function () { + var val = $(this).val(); + var list = $(this).closest('.element').find('.contactlist'); + console.log(val); + $.get("action.php?a=true&contact=" + val, function (data) { list.html(data); }); }); // Open Lightbox -$('body').on('click', '.open-lightbox', function(e) { +$('body').on('click', '.open-lightbox', function (e) { e.preventDefault(); e.stopPropagation(); var image = $(this).attr('href'); @@ -69,15 +69,15 @@ $('body').on('click', '.open-lightbox', function(e) { }); // Close Lightbox -$('body').on('click', '.lightbox-opened', function() { +$('body').on('click', '.lightbox-opened', function () { $('html').removeClass('no-scroll'); $('.lightbox-opened').remove(); }); -window.addEventListener("scroll", function() { +window.addEventListener("scroll", function () { onScrollDiv() }); -window.addEventListener("DOMContentLoaded", function() { +window.addEventListener("DOMContentLoaded", function () { onScrollDiv() }); @@ -96,40 +96,40 @@ function onScrollDiv() { } } -$('body').on('click', '.replies', function(e) { +$('body').on('click', '.replies', function (e) { e.preventDefault; $(".reply").remove(); $(".element").removeClass("element_pad"); $(this).closest(".element").addClass("element_pad"); /*$('.replies_container').html('');*/ var id = $(this).parent().parent().attr('id'); - if($('#' + id+'.replies_container').find('.reply').length < 1){ - $('#' + id+'.replies_container').html("

"); + if ($('#' + id + '.replies_container').find('.reply').length < 1) { + $('#' + id + '.replies_container').html("

"); } - $.get("action.php?a=true&replies=" + id, function(data) { - $('#' + id+'.replies_container').html(data); - $('#' + id+'.replies_container').delay(800).fadeIn(400); + $.get("action.php?a=true&replies=" + id, function (data) { + $('#' + id + '.replies_container').html(data); + $('#' + id + '.replies_container').delay(800).fadeIn(400); $('#a' + id).html(''); - $('#' + id+".replies_container .ancestor").appendTo('#a' + id); + $('#' + id + ".replies_container .ancestor").appendTo('#a' + id); }); }); -$.fn.isOnScreen = function(){ +$.fn.isOnScreen = function () { - var win = $(window); + var win = $(window); - var viewport = { - top : win.scrollTop(), - left : win.scrollLeft() - }; - viewport.right = viewport.left + win.width(); - viewport.bottom = viewport.top + win.height(); + var viewport = { + top: win.scrollTop(), + left: win.scrollLeft() + }; + viewport.right = viewport.left + win.width(); + viewport.bottom = viewport.top + win.height(); - var bounds = this.offset(); - bounds.right = bounds.left + this.outerWidth(); - bounds.bottom = bounds.top + this.outerHeight(); + var bounds = this.offset(); + bounds.right = bounds.left + this.outerWidth(); + bounds.bottom = bounds.top + this.outerHeight(); - return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); + return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); }; /* @@ -178,13 +178,13 @@ $('body').on('click', '.postbody:not(a)', function(e) { }); */ -$('body').on('click', '.ldr:not(.tlicon)', function(e) { - $('.tlicon').each(function(a){ - $( this ).removeClass('tiselected') - }); +$('body').on('click', '.ldr:not(.tlicon)', function (e) { + $('.tlicon').each(function (a) { + $(this).removeClass('tiselected') + }); }); -$('body').on('click', '.ldr', function(e) { +$('body').on('click', '.ldr', function (e) { e.preventDefault(); location.hash = "#top"; $('#loader').html(''); @@ -193,7 +193,7 @@ $('body').on('click', '.ldr', function(e) { var id = $(this).attr('id'); localStorage.setItem("content", $('#content .element').detach()); $('#content').html('
'); - $.get(url + "&ajax=1", function(data) { + $.get(url + "&ajax=1", function (data) { $('#content').html(data); history.pushState({}, "Dashboard FE", url); var thread = getUrlParameter('thread'); @@ -201,7 +201,7 @@ $('body').on('click', '.ldr', function(e) { }); -$('body').on('click', '.gotop a', function(e) { +$('body').on('click', '.gotop a', function (e) { e.preventDefault(); $('html, body').animate({ scrollTop: 0 @@ -209,8 +209,8 @@ $('body').on('click', '.gotop a', function(e) { return false; }); -$('body').on('click', '.topbar:not(a)', function(e) { - if(e.target !== e.currentTarget) return; +$('body').on('click', '.topbar:not(a)', function (e) { + if (e.target !== e.currentTarget) return; e.preventDefault(); $('html, body').animate({ scrollTop: 0 @@ -218,7 +218,7 @@ $('body').on('click', '.topbar:not(a)', function(e) { return false; }); -$('body').on('click', '#loader', function() { +$('body').on('click', '#loader', function () { var cnt = $("#loaded").contents(); // $("#content").prepend(cnt); $('#content').find('.element').first().after(cnt); @@ -226,9 +226,9 @@ $('body').on('click', '#loader', function() { $("#loader").html(''); }); -$('body').on('click', '.nsfw', function() { +$('body').on('click', '.nsfw', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&nsfw=" + id, function(data) { + $.get("action.php?a=true&nsfw=" + id, function (data) { if (data == '1') { $('#' + id + '.nsfw').toggleClass('nsfw unnsfw'); $('#' + id + '.unnsfw').html('NSFW '); @@ -236,9 +236,9 @@ $('body').on('click', '.nsfw', function() { }); }); -$('body').on('click', '.unnsfw', function() { +$('body').on('click', '.unnsfw', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&nsfw=" + id, function(data) { + $.get("action.php?a=true&nsfw=" + id, function (data) { if (data == '1') { $('#' + id + '.unnsfw').toggleClass('unnsfw nsfw'); $('#' + id + '.nsfw').html('NSFW '); @@ -246,41 +246,41 @@ $('body').on('click', '.unnsfw', function() { }); }); -$('body').on('click', '.block', function() { +$('body').on('click', '.block', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&mode=true&block=" + id, function(data) { - - $('#' + id + '.block').removeClass('block').addClass('unblock'); - $('#' + id + '.unblock').html('Unblock'); - + $.get("action.php?a=true&mode=true&block=" + id, function (data) { + + $('#' + id + '.block').removeClass('block').addClass('unblock'); + $('#' + id + '.unblock').html('Unblock'); + }); }); -$('body').on('click', '.unblock', function() { +$('body').on('click', '.unblock', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&mode=off&block=" + id, function(data) { - - $('#' + id + '.unblock').removeClass('unblock').addClass('block'); - $('#' + id + '.block').html('Block'); - + $.get("action.php?a=true&mode=off&block=" + id, function (data) { + + $('#' + id + '.unblock').removeClass('unblock').addClass('block'); + $('#' + id + '.block').html('Block'); + }); }); -$('body').on('click', '.autl', function() { +$('body').on('click', '.autl', function () { var id = $(this).attr('id'); var list = $(this).attr('list'); - $.get("action.php?a=true&mode=true&user=" + id + "&list=" + list, function(data) { - + $.get("action.php?a=true&mode=true&user=" + id + "&list=" + list, function (data) { + $('#' + id + '.autl').removeClass('autl').addClass('rutl'); /* $('#' + id + '.rutl li').html('Added'); */ }); }); -$('body').on('click', '.rutl', function() { +$('body').on('click', '.rutl', function () { var elem = $(this); var id = $(this).attr('id'); var list = $(this).attr('list'); - $.get("action.php?a=true&mode=off&user=" + id + "&list=" + list, function(data) { + $.get("action.php?a=true&mode=off&user=" + id + "&list=" + list, function (data) { $('#' + id + '.rutl').removeClass('rutl').addClass('autl'); /* $(elem).find('li').html('Removed');*/ }); @@ -288,45 +288,45 @@ $('body').on('click', '.rutl', function() { -$('body').on('click', '.hide', function() { +$('body').on('click', '.hide', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&mode=true&hide=" + id, function(data) { + $.get("action.php?a=true&mode=true&hide=" + id, function (data) { $('#' + id + '.hide').removeClass('hide').addClass('unhide'); $('#' + id + '.unhide').html('Unhide Thread'); console.log(data); }); }); -$('body').on('click', '.unhide', function() { +$('body').on('click', '.unhide', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&mode=off&hide=" + id, function(data) { + $.get("action.php?a=true&mode=off&hide=" + id, function (data) { $('#' + id + '.unhide').removeClass('unhide').addClass('hide'); $('#' + id + '.hide').html('Hide Thread'); console.log(data); }); }); -$('body').on('click', '.bookmark', function() { +$('body').on('click', '.bookmark', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&mode=true&bookmark=" + id, function(data) { + $.get("action.php?a=true&mode=true&bookmark=" + id, function (data) { $('#' + id + '.bookmark').removeClass('bookmark').addClass('unbookmark'); $('#' + id + '.unbookmark').html('Unbookmark'); console.log(data); }); }); -$('body').on('click', '.unbookmark', function() { +$('body').on('click', '.unbookmark', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&mode=off&bookmark=" + id, function(data) { + $.get("action.php?a=true&mode=off&bookmark=" + id, function (data) { $('#' + id + '.unbookmark').removeClass('unbookmark').addClass('bookmark'); $('#' + id + '.bookmark').html('Bookmark'); console.log(data); }); }); -$('body').on('click', '.follow', function() { +$('body').on('click', '.follow', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&follow=" + id, function(data) { + $.get("action.php?a=true&follow=" + id, function (data) { console.log(data); if (data == '1') { $('#' + id + '.follow').removeClass('follow').addClass('unfollow'); @@ -335,10 +335,10 @@ $('body').on('click', '.follow', function() { }); }); -$('body').on('click', '.unfollow', function() { +$('body').on('click', '.unfollow', function () { var id = $(this).attr('id'); - $.get("action.php?a=true&unfollow=" + id, function(data) { - + $.get("action.php?a=true&unfollow=" + id, function (data) { + if (data == '1') { $('#' + id + '.unfollow').removeClass('unfollow').addClass('follow'); $('#' + id + '.follow').html('Follow'); @@ -346,43 +346,43 @@ $('body').on('click', '.unfollow', function() { }); }); -$('.container').on('mouseenter', '.user', function(event) { +$('.container').on('mouseenter', '.user', function (event) { event.stopPropagation(); - event.stopImmediatePropagation(); + event.stopImmediatePropagation(); var id = $(this).attr('id'); console.log(id); $(this).append("
"); - $.when($.get("action.php?a=true&userinfo=" + id, function(data) { + $.when($.get("action.php?a=true&userinfo=" + id, function (data) { $('#' + id + '.userinfo').html(data); - })).then(function(){ + })).then(function () { $('#' + id + '.userinfo').fadeIn(); }); }); -$('.container').on('mouseleave', '.user', function(event) { +$('.container').on('mouseleave', '.user', function (event) { event.stopPropagation(); - event.stopImmediatePropagation(); - $(this).find('.userinfo').fadeOut(300, function() { $(this).remove(); }); + event.stopImmediatePropagation(); + $(this).find('.userinfo').fadeOut(300, function () { $(this).remove(); }); }); -$('.container').on('mouseenter', '.preview', function(event) { +$('.container').on('mouseenter', '.preview', function (event) { event.stopPropagation(); - event.stopImmediatePropagation(); + event.stopImmediatePropagation(); var id = $(this).attr('id'); console.log(id); $(this).before("
"); - $.when($.get("action.php?a=true&previewpost=" + id, function(data) { + $.when($.get("action.php?a=true&previewpost=" + id, function (data) { $('#' + id + '.previewpost').html(data); - })).then(function(){ + })).then(function () { $('#' + id + '.previewpost').fadeIn(); }); }); -$('.container').on('mouseleave', '.preview', function(event) { +$('.container').on('mouseleave', '.preview', function (event) { event.stopPropagation(); - event.stopImmediatePropagation(); - $('.container').find('.previewpost').fadeOut(300, function() { $(this).remove(); }); + event.stopImmediatePropagation(); + $('.container').find('.previewpost').fadeOut(300, function () { $(this).remove(); }); }); var getUrlParameter = function getUrlParameter(sParam) { @@ -424,7 +424,7 @@ function getMode() { return "&mode=federated"; }; -function loadmore(){ +function loadmore() { var thread = getUrlParameter('thread'); if (typeof thread !== 'undefined') { return false; @@ -439,7 +439,7 @@ function loadmore(){ pageMode = getMode(); var id = $('.post').last().attr('pid'); $('.loadmore').html("") - $.get("index.php?ajax=1&next=" + id + "" + pageMode, function(data) { + $.get("index.php?ajax=1&next=" + id + "" + pageMode, function (data) { $('.loadmore').parent().before(data); $('.loadmore').html("Load More Posts") /*$('.loadmore').parent().detach(); @@ -451,20 +451,20 @@ function loadmore(){ } } -$(window).scroll(function() { +$(window).scroll(function () { if ($(window).scrollTop() == $(document).height() - $(window).height()) { loadmore(); } }); -$('body').on('click', '.loadmore', function() { +$('body').on('click', '.loadmore', function () { loadmore(); }); function newPosts() { - + var url = window.location.href; - + var thread = getUrlParameter('thread'); if (typeof thread !== 'undefined') { return false; @@ -486,17 +486,18 @@ function newPosts() { if (typeof page !== 'undefined') { return false; } - - $.get("index.php?ajax=1&since=" + id + "" + pageMode, function(data) { - - if (window.location.href !== url){ + + $.get("index.php?ajax=1&since=" + id + "" + pageMode, function (data) { + + if (window.location.href !== url) { return false; } - + if (data) { var scroll = $(window).scrollTop(); if (scroll > 1000) { - $('#loader').html("
Load Newer Posts
"); + $('#loader').html("
Load Newer Posts
"); + if ($('#loaded').length) { $('#loaded').prepend(data); } else { @@ -514,59 +515,58 @@ function newPosts() { }); }; -window.setInterval(function() { +window.setInterval(function () { var timestamp; - $('.postAge').each(function(a){ - timestamp = $(this).attr('id'); - $(this).html(timeSince(timestamp)+' ago'); - }); + $('.postAge').each(function (a) { + timestamp = $(this).attr('id'); + $(this).html(timeSince(timestamp) + ' ago'); + }); newPosts(); }, 25000); -function themecheck(name){ - if(name.value == "custom"){ - $('#customtheme').css("display","block"); - } - else{ - $('#customtheme').css("display","none"); - } +function themecheck(name) { + if (name.value == "custom") { + $('#customtheme').css("display", "block"); + } else { + $('#customtheme').css("display", "none"); + } }; function timeSince(date) { - /* https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site */ - - var seconds = Math.floor((new Date() - (date*1000)) / 1000); + /* https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site */ - var interval = Math.floor(seconds / 31536000); + var seconds = Math.floor((new Date() - (date * 1000)) / 1000); - if (interval >= 1) { - return interval + " year"+(interval > 1 ? "s" : ""); - } - interval = Math.floor(seconds / 2592000); - if (interval >= 1) { - return interval + " month"+(interval > 1 ? "s" : ""); - } - interval = Math.floor(seconds / 604800); - if (interval >= 1) { - return interval + " week"+(interval > 1 ? "s" : ""); - } - interval = Math.floor(seconds / 86400); - if (interval >= 1) { - return interval + " day"+(interval > 1 ? "s" : ""); - } - interval = Math.floor(seconds / 3600); - if (interval >= 1) { - return interval + " hour"+(interval > 1 ? "s" : ""); - } - interval = Math.floor(seconds / 60); - if (interval >= 1) { - return interval + " minute"+(interval > 1 ? "s" : ""); - } - - if (interval < 0) { - return " just now"; - } - return Math.floor(seconds) + " seconds"; + var interval = Math.floor(seconds / 31536000); + + if (interval >= 1) { + return interval + " year" + (interval > 1 ? "s" : ""); + } + interval = Math.floor(seconds / 2592000); + if (interval >= 1) { + return interval + " month" + (interval > 1 ? "s" : ""); + } + interval = Math.floor(seconds / 604800); + if (interval >= 1) { + return interval + " week" + (interval > 1 ? "s" : ""); + } + interval = Math.floor(seconds / 86400); + if (interval >= 1) { + return interval + " day" + (interval > 1 ? "s" : ""); + } + interval = Math.floor(seconds / 3600); + if (interval >= 1) { + return interval + " hour" + (interval > 1 ? "s" : ""); + } + interval = Math.floor(seconds / 60); + if (interval >= 1) { + return interval + " minute" + (interval > 1 ? "s" : ""); + } + + if (interval < 0) { + return " just now"; + } + return Math.floor(seconds) + " seconds"; }