Browse Source

[docs] provide means to have collapsible code blocks without adding a new theme

pull/746/head
srmo 7 years ago
parent
commit
f361092ed9
3 changed files with 47 additions and 0 deletions
  1. +17
    -0
      docs/_static/custom_collapsible_code.css
  2. +10
    -0
      docs/_static/custom_collapsible_code.js
  3. +20
    -0
      docs/_templates/layout.html

+ 17
- 0
docs/_static/custom_collapsible_code.css View File

@ -0,0 +1,17 @@
.toggle {
padding-bottom: 1em ;
}
.toggle .header {
display: block;
clear: both;
cursor: pointer;
}
.toggle .header:after {
content: " ▼";
}
.toggle .header.open:after {
content: " ▲";
}

+ 10
- 0
docs/_static/custom_collapsible_code.js View File

@ -0,0 +1,10 @@
let makeCodeBlocksCollapsible = function() {
$(".toggle > *").hide();
$(".toggle .header").show();
$(".toggle .header").click(function() {
$(this).parent().children().not(".header").toggle({"duration": 400});
$(this).parent().children(".header").toggleClass("open");
});
};
// we could use the }(); way if we would have access to jQuery in HEAD, i.e. we would need to force the theme
// to load jQuery before our custom scripts

+ 20
- 0
docs/_templates/layout.html View File

@ -0,0 +1,20 @@
{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/custom_collapsible_code.css"] %}
# sadly, I didn't find a css style way to add custom JS to a list that is automagically added to head like CSS (above) #}
{% block extrahead %}
<script type="text/javascript" src="_static/custom_collapsible_code.js"></script>
{% endblock %}
{% block footer %}
<script type="text/javascript">
$(document).ready(function() {
// using this approach as we don't have access to the jQuery selectors
// when executing the function on load in HEAD
makeCodeBlocksCollapsible();
});
</script>
{% endblock %}

Loading…
Cancel
Save