From 2256604dad36caca4bd3f90898f1d1040066773b Mon Sep 17 00:00:00 2001 From: topkek Date: Wed, 26 Nov 2014 21:10:27 +0000 Subject: add global option for tree view --- js/treeview.js | 71 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 26 deletions(-) (limited to 'js/treeview.js') 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(); }); }); -- cgit v1.3 From d67351534a4d54af65b0b9d6515587c49c772934 Mon Sep 17 00:00:00 2001 From: topkek Date: Wed, 26 Nov 2014 22:48:54 +0000 Subject: toggle tree view --- js/treeview.js | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'js/treeview.js') 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); + + var parent_post = $("#reply_"+maxref); + if (parent_post.length == 0) return; + + var margin = parseInt(parent_post.css("margin-left"))+32; - post.detach().css("margin-left", margin).insertAfter(parent_post.next()); - br.detach().insertAfter(post); - }); + 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(); -- cgit v1.3 From 1888e174b3d6ea6a506c62cc1c75c9d6acf6ff72 Mon Sep 17 00:00:00 2001 From: topkek Date: Thu, 27 Nov 2014 00:36:51 +0000 Subject: chrome fix --- js/treeview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/treeview.js') 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(); -- cgit v1.3 From 8de9b68f5f5386265a624678bf95214e44f9bc21 Mon Sep 17 00:00:00 2001 From: topkek Date: Fri, 28 Nov 2014 01:15:10 +0000 Subject: checkbox for tree view Conflicts: js/post-hover.js --- js/favorites.js | 1 - js/treeview.js | 21 +++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'js/treeview.js') diff --git a/js/favorites.js b/js/favorites.js index e325e110..daf7b732 100644 --- a/js/favorites.js +++ b/js/favorites.js @@ -54,7 +54,6 @@ if (active_page == 'thread' || active_page == 'index') { $(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/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(); }); }); -- cgit v1.3 From e6da7b4682a80b63008b6f2bb550515d5c90d774 Mon Sep 17 00:00:00 2001 From: topkek Date: Fri, 28 Nov 2014 21:59:05 +0000 Subject: clean up options code --- js/treeview.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'js/treeview.js') 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'); } }); -- cgit v1.3