summaryrefslogtreecommitdiff
path: root/js/treeview.js
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2014-04-19 23:33:54 +0200
committerczaks <marcin@6irc.net>2014-04-19 23:33:54 +0200
commitedcaee1f78935c5e166201ad4c663b4ace5d7f5b (patch)
treea837b984bf8671f770c30a6502fd3f8f74302684 /js/treeview.js
parentb33e8cb10d343e5e4792ba3357a534920c4f909d (diff)
treeview.js: initial commit
Diffstat (limited to 'js/treeview.js')
-rw-r--r--js/treeview.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/js/treeview.js b/js/treeview.js
new file mode 100644
index 00000000..78ad620b
--- /dev/null
+++ b/js/treeview.js
@@ -0,0 +1,45 @@
+/*
+ * treeview.js
+ * https://github.com/vichan-devel/vichan/blob/master/js/treeview.js
+ *
+ * Released under the MIT license
+ * Copyright (c) 2014 Marcin Ɓabanowski <marcin@6irc.net>
+ *
+ * Usage:
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/treeview.js';
+ *
+ */
+
+if (active_page == 'thread')
+$(function() {
+ $('hr:first').before('<div id="treeview" style="text-align:right"><a class="unimportant" href="javascript:void(0)"></a></div>');
+ $('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('^&gt;&gt;[0-9]+$')) {
+ references.push(parseInt($(this).html().replace('&gt;&gt;', '')));
+ }
+ });
+
+ 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);
+
+ });
+ });
+});