diff --git a/inc/config.php b/inc/config.php index 2137c91d..79ac48cb 100644 --- a/inc/config.php +++ b/inc/config.php @@ -603,6 +603,9 @@ // Some scripts require jQuery. Check the comments in script files to see what's needed. // $config['additional_javascript'][] = 'js/jquery.min.js'; // $config['additional_javascript'][] = 'js/auto-reload.js'; + + // Enable hiding posts. Remember to put this AFTER jQuery. + // $config['additional_javascript'][] = 'js/post-hider.js'; // Where these script files are located on the web (defaults to $config['root']). // $config['additional_javascript_url'] = '/js/'; diff --git a/js/post-hider.js b/js/post-hider.js new file mode 100644 index 00000000..2ae7e3b6 --- /dev/null +++ b/js/post-hider.js @@ -0,0 +1,44 @@ +function phGetCookieName(id) { + return "ph_hide_" + id; +} +function phPostHidden(id) { + return (localStorage.getItem(phGetCookieName(id)) != null); +} +function phPostToggle(id) { + if(phPostHidden(id)) { localStorage.removeItem(phGetCookieName(id)); } + else { localStorage.setItem(phGetCookieName(id),"yes"); } +} +function phGetInnerText(id) { + if(phPostHidden(id)) { return "[+]"; } + else { return "[-]"; } +} +function phGetOpID(element) { + return Number(element.children("div.post.op").children("p.intro").children("a.post_no:eq(1)").text()); +} +function phPostHandle(element) { + var id = phGetOpID(element); + var preplies = element.children("div.post.reply"); + var pbody = element.children("div.post.op").children("div.body"); + var pimage = element.children("a:first").children("img"); + var pbutton = element.children("div.post.op").children("p.intro").children("a.posthider"); + var pomitted = element.children("div.post.op").children("span.omitted"); + if(phPostHidden(id)) { element.addClass("thread-hidden"); pomitted.hide(); preplies.hide(); pbody.hide(); pimage.hide(); pbutton.text("[+]"); } + else { element.removeClass("thread-hidden"); pomitted.show(); preplies.show(); pbody.show(); pimage.show(); pbutton.text("[-]"); } +} + +$(document).ready(function(){ + $('div[id^="thread"]').each(function(index, element){ + // Get thread ID. + var pin = $(this).children("div.post.op").children("p.intro"); + var tid = phGetOpID($(this)); + if(tid != NaN) { + $("[?]").insertAfter(pin.children('a:last')).click(function(e) { + var eO = $(e.target); + var par = eO.parent().parent().parent(); + phPostToggle(phGetOpID(par)); + phPostHandle(par); + }); + phPostHandle($(this)); + } + }); +}); diff --git a/stylesheets/style.css b/stylesheets/style.css index 14463dc6..3d401184 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -453,3 +453,6 @@ table.mod.config-editor input[type="text"] { background-color: #fff; opacity: 0.8; } +.thread-hidden { + opacity: 0.5; +}