From 73b5cf5a08c395e706e8bc3ac8032bfbc810376f Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 2 Aug 2013 04:20:57 -0400 Subject: [PATCH] ukko: implement ukko hide --- templates/themes/ukko/ukko.js | 65 +++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/templates/themes/ukko/ukko.js b/templates/themes/ukko/ukko.js index 99c737d6..9011c754 100644 --- a/templates/themes/ukko/ukko.js +++ b/templates/themes/ukko/ukko.js @@ -3,7 +3,54 @@ var cache = new Array(), thread = false, loading = false; + +if (localStorage.hiddenboards !== null) { + localStorage.hiddenboards = "{}"; +} + +// Load data from HTML5 localStorage +var hiddenboards = JSON.parse(localStorage.hiddenboards); + +var storeboards = function() { + localStorage.hiddenboards = JSON.stringify(hiddenboards); +}; + $(document).ready(function() { + var addukkohide = function() { + var ukkohide = $(''); + var board = $(this).next().data("board"); + var hr = $("
"); + + $(this).append(ukkohide); + $(this).append(hr); + + if (hiddenboards[board] !== true) { + ukkohide.html(_("(hide threads from this board)")); + hr.hide(); + } + else { + ukkohide.html(_("(show threads from this board)")); + $(this).next().hide(); + } + ukkohide.click(function() { + hiddenboards[board] = (hiddenboards[board] !== true); + if (hiddenboards[board] !== true) { + $('[data-board="'+board+'"][data-cached!="yes"]').show().prev(). + find('.ukkohide').html(_("(hide threads from this board)")). + parent().find('hr').hide(); + } + else { + $('[data-board="'+board+'"][data-cached!="yes"]').hide().prev(). + find('.ukkohide').html(_("(show threads from this board)")) + .parent().find('hr').show(); + } + storeboards(); + return false; + }); + + }; + $("h2").each(addukkohide); + $('.pages').hide(); $(window).on('scroll', function() { if (overflow.length == 0) { @@ -12,14 +59,17 @@ $(document).ready(function() { while($(window).scrollTop() + $(window).height() + 500 > $(document).height() && !loading && overflow.length > 0) { var page = '../' + overflow[0].board + '/' + overflow[0].page; thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]'); - if (thread.length > 0 && thread.css('display') != 'none') { // already present + if (thread.length > 0 && thread.data("cached") !== 'yes') { // already present overflow.shift(); continue; } + var boardheader = $('

/' + overflow[0].board + '/

'); + if($.inArray(page, cache) != -1 && thread.length > 0) { - thread.prepend('

/' + overflow[0].board + '/

'); - $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).css('display', 'block')); + $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).data("cached", "no").css('display', 'block')); + boardheader.insertBefore(thread); + addukkohide.call(boardheader); $(document).trigger('new_post', thread); overflow.shift(); } else { @@ -29,13 +79,14 @@ $(document).ready(function() { cache.push(page); $(data).find('div[id*="thread_"]').each(function() { - $('form[name="postcontrols"]').prepend($(this).css('display', 'none').attr('data-board', overflow[0].board)); + $('form[name="postcontrols"]').prepend($(this).css('display', 'none').data("cached", "yes").attr('data-board', overflow[0].board)); }); thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]'); - if(thread.length > 0 && thread.css('display') != 'none') { - thread.prepend('

/' + overflow[0].board + '/

'); - $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).css('display', 'block')); + if(thread.length > 0 && thread.data('cached') !== 'no') { + $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).data("cached", "no").css('display', 'block')); + boardheader.insertBefore(thread); + addukkohide.call(boardheader); $(document).trigger('new_post', thread); overflow.shift(); }