diff options
| author | topkek <topkek@users.noreply.github.com> | 2014-11-26 22:48:54 +0000 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2015-03-31 07:51:31 +0200 |
| commit | d67351534a4d54af65b0b9d6515587c49c772934 (patch) | |
| tree | 628a66331b36cf571263d7e385d26a0ac5d54a18 /js | |
| parent | 2256604dad36caca4bd3f90898f1d1040066773b (diff) | |
toggle tree view
Diffstat (limited to 'js')
| -rw-r--r-- | js/treeview.js | 52 |
1 files 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); + + 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(); |
