From 666a7f760d48ea4ae017a425f101a11cb11d2cd4 Mon Sep 17 00:00:00 2001 From: topkek Date: Wed, 26 Nov 2014 21:10:27 +0000 Subject: [PATCH 1/6] add global option for tree view --- js/treeview.js | 71 +++++++++++++++++++++++++++---------------- stylesheets/style.css | 3 +- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/js/treeview.js b/js/treeview.js index 78ad620b..c9bd55f8 100644 --- a/js/treeview.js +++ b/js/treeview.js @@ -11,35 +11,54 @@ * */ +if (active_page == 'thread' || active_page == 'ukko' || active_page == 'index') +$(function() { + if (window.Options && Options.get_tab('general')) { + var selector = '#treeview-global>input'; + Options.extend_tab("general", ""); + } + $(selector).on('change', function () { + if (localStorage.treeview === 'true') { + localStorage.treeview = 'false'; + } else { + localStorage.treeview = 'true'; + } + }); + if (localStorage.treeview === 'true') { + $(selector).attr('checked', 'checked'); + } +}); + if (active_page == 'thread') $(function() { + var treeview = function() { + $('.post.reply').each(function(){ + var references = []; + $(this).find('.body a').each(function(){ + if ($(this).html().match('^>>[0-9]+$')) { + references.push(parseInt($(this).html().replace('>>', ''))); + } + }); + var maxref = references.reduce(function(a,b) { return a > b ? a : b; }, 0); + + var parent_post = $("#reply_"+maxref); + if (parent_post.length == 0) return; + + var margin = parseInt(parent_post.css("margin-left"))+32; + + var post = $(this); + var br = post.next(); + + post.detach().css("margin-left", margin).insertAfter(parent_post.next()); + br.detach().insertAfter(post); + }); + } + if (localStorage.treeview === 'true') { + treeview(); + } + $('hr:first').before('
'); $('div#treeview a') .text(_('Tree view')) - .click(function(e) { - e.preventDefault(); - - $('.post.reply').each(function(){ - var references = []; - $(this).find('.body a').each(function(){ - if ($(this).html().match('^>>[0-9]+$')) { - references.push(parseInt($(this).html().replace('>>', ''))); - } - }); - - var maxref = references.reduce(function(a,b) { return a > b ? a : b; }, 0); - - var parent_post = $("#reply_"+maxref); - if (parent_post.length == 0) return; - - var margin = parseInt(parent_post.css("margin-left"))+32; - - var post = $(this); - var br = post.next(); - - post.detach().css("margin-left", margin).insertAfter(parent_post.next()); - br.detach().insertAfter(post); - - }); - }); + .click(function(e) { treeview(); e.preventDefault(); }); }); diff --git a/stylesheets/style.css b/stylesheets/style.css index bebd4813..f86f0021 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -858,7 +858,7 @@ pre { #options_div { width: 600px; - height: 300px; + height: 320px; } #alert_div { @@ -925,6 +925,7 @@ pre { right: 0px; text-align: left; font-size: 12px; + overflow-y: auto; } .options_tab h2 { From 2da17bfebeabd2c85b5102d66bec8ea733f846f6 Mon Sep 17 00:00:00 2001 From: topkek Date: Wed, 26 Nov 2014 22:48:54 +0000 Subject: [PATCH 2/6] toggle tree view --- js/treeview.js | 52 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/js/treeview.js b/js/treeview.js index c9bd55f8..937ea6ff 100644 --- a/js/treeview.js +++ b/js/treeview.js @@ -31,27 +31,41 @@ $(function() { if (active_page == 'thread') $(function() { + var treeview_on = false; var treeview = function() { - $('.post.reply').each(function(){ - var references = []; - $(this).find('.body a').each(function(){ - if ($(this).html().match('^>>[0-9]+$')) { - references.push(parseInt($(this).html().replace('>>', ''))); - } - }); - var maxref = references.reduce(function(a,b) { return a > b ? a : b; }, 0); - - var parent_post = $("#reply_"+maxref); - if (parent_post.length == 0) return; - - var margin = parseInt(parent_post.css("margin-left"))+32; - - var post = $(this); - var br = post.next(); + if (!treeview_on) { + treeview_on = true; + $('.post.reply').each(function(){ + var references = []; + $(this).find('.body a').each(function(){ + if ($(this).html().match('^>>[0-9]+$')) { + references.push(parseInt($(this).html().replace('>>', ''))); + } + }); + var maxref = references.reduce(function(a,b) { return a > b ? a : b; }, 0); - post.detach().css("margin-left", margin).insertAfter(parent_post.next()); - br.detach().insertAfter(post); - }); + var parent_post = $("#reply_"+maxref); + if (parent_post.length == 0) return; + + var margin = parseInt(parent_post.css("margin-left"))+32; + + var post = $(this); + var br = post.next(); + + post.detach().css("margin-left", margin).insertAfter(parent_post.next()); + br.detach().insertAfter(post); + }); + } else { + treeview_on = false; + $('.post.reply').sort(function(a,b) { + return parseInt(a.id.replace('reply_', '')) > parseInt(b.id.replace('reply_', '')); + }).each(function () { + var post = $(this); + var br = post.next(); + post.detach().css('margin-left', '0').appendTo('.thread'); + br.detach().insertAfter(post); + }); + } } if (localStorage.treeview === 'true') { treeview(); From 191347b92e79b03457ff3c1d8581181bd8f912cc Mon Sep 17 00:00:00 2001 From: topkek Date: Thu, 27 Nov 2014 00:36:51 +0000 Subject: [PATCH 3/6] chrome fix --- js/treeview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/treeview.js b/js/treeview.js index 937ea6ff..046a9796 100644 --- a/js/treeview.js +++ b/js/treeview.js @@ -58,7 +58,7 @@ $(function() { } else { treeview_on = false; $('.post.reply').sort(function(a,b) { - return parseInt(a.id.replace('reply_', '')) > parseInt(b.id.replace('reply_', '')); + return parseInt(a.id.replace('reply_', '')) - parseInt(b.id.replace('reply_', '')); }).each(function () { var post = $(this); var br = post.next(); From 2a2f64c09805a4f6dfe8ba298fd8570b21518661 Mon Sep 17 00:00:00 2001 From: topkek Date: Thu, 27 Nov 2014 18:14:12 +0000 Subject: [PATCH 4/6] don't indent previews --- js/post-hover.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/post-hover.js b/js/post-hover.js index eefb3875..657c4f1d 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -73,6 +73,7 @@ onready(function(){ .css('font-style', 'normal') .css('z-index', '100') .css('left', '0') + .css('margin-left', '0') .addClass('reply').addClass('post') .appendTo(link.closest('div.post')) From 82fc6c241b6b1ba7c5c80a4771101dc12a633a90 Mon Sep 17 00:00:00 2001 From: topkek Date: Fri, 28 Nov 2014 01:15:10 +0000 Subject: [PATCH 5/6] checkbox for tree view --- js/favorites.js | 1 - js/post-hover.js | 2 +- js/treeview.js | 21 +++++++++------------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/js/favorites.js b/js/favorites.js index 39bae783..acef9c7e 100644 --- a/js/favorites.js +++ b/js/favorites.js @@ -56,7 +56,6 @@ if (active_page == 'thread' || active_page == 'index' || active_page == 'catalog $(document).ready(function(){ var favorites = JSON.parse(localStorage.favorites); var is_board_favorite = ~$.inArray(board_name, favorites); - console.log(is_board_favorite); $('header>h1').append('\u2605'); add_favorites(); diff --git a/js/post-hover.js b/js/post-hover.js index 657c4f1d..94841cc5 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -73,7 +73,7 @@ onready(function(){ .css('font-style', 'normal') .css('z-index', '100') .css('left', '0') - .css('margin-left', '0') + .css('margin-left', '') .addClass('reply').addClass('post') .appendTo(link.closest('div.post')) diff --git a/js/treeview.js b/js/treeview.js index 046a9796..dcd87e1e 100644 --- a/js/treeview.js +++ b/js/treeview.js @@ -31,10 +31,8 @@ $(function() { if (active_page == 'thread') $(function() { - var treeview_on = false; - var treeview = function() { - if (!treeview_on) { - treeview_on = true; + var treeview = function(enable) { + if (enable === true) { $('.post.reply').each(function(){ var references = []; $(this).find('.body a').each(function(){ @@ -56,23 +54,22 @@ $(function() { br.detach().insertAfter(post); }); } else { - treeview_on = false; $('.post.reply').sort(function(a,b) { return parseInt(a.id.replace('reply_', '')) - parseInt(b.id.replace('reply_', '')); }).each(function () { var post = $(this); var br = post.next(); - post.detach().css('margin-left', '0').appendTo('.thread'); + post.detach().css('margin-left', '').appendTo('.thread'); br.detach().insertAfter(post); }); } } + + $('hr:first').before('
'); + $('input#treeview').on('change', function(e) { treeview($(this).is(':checked')); }); + if (localStorage.treeview === 'true') { - treeview(); + treeview(true); + $('input#treeview').attr('checked', true); } - - $('hr:first').before('
'); - $('div#treeview a') - .text(_('Tree view')) - .click(function(e) { treeview(); e.preventDefault(); }); }); From 74a6ad7e52d043227f7bae279c766100d4e7dca7 Mon Sep 17 00:00:00 2001 From: topkek Date: Fri, 28 Nov 2014 21:59:05 +0000 Subject: [PATCH 6/6] clean up options code --- js/treeview.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/js/treeview.js b/js/treeview.js index dcd87e1e..1709debb 100644 --- a/js/treeview.js +++ b/js/treeview.js @@ -16,16 +16,16 @@ $(function() { if (window.Options && Options.get_tab('general')) { var selector = '#treeview-global>input'; Options.extend_tab("general", ""); - } - $(selector).on('change', function () { + $(selector).on('change', function() { + if (localStorage.treeview === 'true') { + localStorage.treeview = 'false'; + } else { + localStorage.treeview = 'true'; + } + }); if (localStorage.treeview === 'true') { - localStorage.treeview = 'false'; - } else { - localStorage.treeview = 'true'; + $(selector).attr('checked', 'checked'); } - }); - if (localStorage.treeview === 'true') { - $(selector).attr('checked', 'checked'); } });