summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authortopkek <topkek@users.noreply.github.com>2014-11-26 21:10:27 +0000
committerczaks <marcin@6irc.net>2015-03-31 07:51:20 +0200
commit2256604dad36caca4bd3f90898f1d1040066773b (patch)
treeca9ccfe7c24ad0bbcbab2f69a59f6cae57ad9304 /js
parent960053af750a9e8ce196a3855c9fbee69f9ec0ba (diff)
add global option for tree view
Diffstat (limited to 'js')
-rw-r--r--js/treeview.js71
1 files changed, 45 insertions, 26 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", "<label id='treeview-global'><input type='checkbox' /> "+_('Use tree view by default')+"</label>");
+ }
+ $(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('^&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);
+ });
+ }
+ if (localStorage.treeview === 'true') {
+ treeview();
+ }
+
$('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);
-
- });
- });
+ .click(function(e) { treeview(); e.preventDefault(); });
});