1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-29 01:34:31 +01:00

post-hider.js: fixed multiple board issues; eg. you could hide a thread on one board, and threads from other boards with the same id would have been hidden too

This commit is contained in:
czaks 2013-06-24 09:02:12 -04:00
parent c65fe97a99
commit 7915be5d26

View File

@ -1,33 +1,37 @@
function phGetCookieName(id) {
return "ph_hide_" + id;
function phGetCookieName(board, id) {
return "ph_hide_" + board + "_" + id;
}
function phPostHidden(id) {
return (localStorage.getItem(phGetCookieName(id)) != null);
function phPostHidden(board, id) {
return (localStorage.getItem(phGetCookieName(board, id)) != null);
}
function phPostToggle(id) {
if(phPostHidden(id)) { localStorage.removeItem(phGetCookieName(id)); }
else { localStorage.setItem(phGetCookieName(id),"yes"); }
function phPostToggle(board, id) {
if(phPostHidden(board, id)) { localStorage.removeItem(phGetCookieName(board, id)); }
else { localStorage.setItem(phGetCookieName(board, id),"yes"); }
}
function phGetInnerText(id) {
if(phPostHidden(id)) { return "[+]"; }
else { return "[-]"; }
function phGetInnerText(board, id) {
if(phPostHidden(board, 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 phGetOpBoard(element) {
return element.data("board");
}
function phPostHandle(element) {
var id = phGetOpID(element);
var board = phGetOpBoard(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("[-]"); }
if(phPostHidden(board, 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){
$('form[name="postcontrols"] > div[id^="thread"]').each(function(index, element){
// Get thread ID.
var pin = $(this).children("div.post.op").children("p.intro");
var tid = phGetOpID($(this));
@ -35,7 +39,7 @@ $(document).ready(function(){
$("<a href='javascript:;' class='posthider'>[?]</a>").insertAfter(pin.children('a:last')).click(function(e) {
var eO = $(e.target);
var par = eO.parent().parent().parent();
phPostToggle(phGetOpID(par));
phPostToggle(phGetOpBoard(par), phGetOpID(par));
phPostHandle(par);
return false;
});