Skip to content

Commit

Permalink
Collapse Code as Default Display Option
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.brusch authored and naoyak committed May 28, 2020
1 parent 9996fbd commit 7d910d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions knowledge_repo/app/config_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,9 @@ def prepare_repo(repo):
# Posts with certain tags can be excluded from showing up
# in the app. This can be useful for security purposes
EXCLUDED_TAGS = ['private']


# -------------
# Collapse Code as Default Display Option
# -------------
COLLAPSE_CODE_DEFAULT = False
3 changes: 2 additions & 1 deletion knowledge_repo/app/routes/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def render(path):
is_private=(post.private == 1),
is_author=is_author,
can_download=permissions.post_download.can(),
downloads=post.kp.src_paths)
downloads=post.kp.src_paths,
collapse_code=current_app.config['COLLAPSE_CODE_DEFAULT'])
return rendered


Expand Down
10 changes: 8 additions & 2 deletions knowledge_repo/app/templates/markdown-rendered.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ <h2> {{ comments | length }} Comments </h2>
$maindiv = $('.renderedMarkdown');
$maindiv.prepend("<div class=\"codetoggleall\">Collapse All Code</div>");

$('.codetoggleall').click(function() {
var toggleCode = function() {
var label = $(this).html();
if (label.indexOf("Expand All Code") >= 0) {
$(this).html(label.replace("Expand All Code", "Collapse All Code"));
Expand All @@ -198,7 +198,13 @@ <h2> {{ comments | length }} Comments </h2>
$(this).html(label.replace("Collapse", "Expand"));
});
}
});
};

$('.codetoggleall').click(toggleCode);

{% if collapse_code %}
$('.codetoggleall').trigger( "click" )
{% endif %}
})

//Turn all the headers to be links
Expand Down

0 comments on commit 7d910d0

Please sign in to comment.