diff --git a/knowledge_repo/app/config_defaults.py b/knowledge_repo/app/config_defaults.py index 4daf8e67a..63eea7b9e 100644 --- a/knowledge_repo/app/config_defaults.py +++ b/knowledge_repo/app/config_defaults.py @@ -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 diff --git a/knowledge_repo/app/routes/posts.py b/knowledge_repo/app/routes/posts.py index 0b6f43b55..d61a384c9 100755 --- a/knowledge_repo/app/routes/posts.py +++ b/knowledge_repo/app/routes/posts.py @@ -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 diff --git a/knowledge_repo/app/templates/markdown-rendered.html b/knowledge_repo/app/templates/markdown-rendered.html index f6737ac2a..4ed4b6b14 100644 --- a/knowledge_repo/app/templates/markdown-rendered.html +++ b/knowledge_repo/app/templates/markdown-rendered.html @@ -177,7 +177,7 @@

{{ comments | length }} Comments

$maindiv = $('.renderedMarkdown'); $maindiv.prepend("
Collapse All Code
"); - $('.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")); @@ -198,7 +198,13 @@

{{ comments | length }} Comments

$(this).html(label.replace("Collapse", "Expand")); }); } - }); + }; + + $('.codetoggleall').click(toggleCode); + + {% if collapse_code %} + $('.codetoggleall').trigger( "click" ) + {% endif %} }) //Turn all the headers to be links