Browse Source

toggle tree view

pull/40/head
topkek 10 years ago
committed by czaks
parent
commit
d67351534a
  1. 46
      js/treeview.js

46
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);
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 parent_post = $("#reply_"+maxref);
if (parent_post.length == 0) return;
var margin = parseInt(parent_post.css("margin-left"))+32;
var margin = parseInt(parent_post.css("margin-left"))+32;
var post = $(this);
var br = post.next();
var post = $(this);
var br = post.next();
post.detach().css("margin-left", margin).insertAfter(parent_post.next());
br.detach().insertAfter(post);
});
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();

Loading…
Cancel
Save