<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-GB">
<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
    <style type="text/css">
        body {
          margin: 30px;
          font-family: sans-serif;
        }

        #fontSizeWrapper { font-size: 16px; }

        #fontSize {
        width: 100px;
        font-size: 1em;
        }

        /* ---------------------
        Tree core styles
        */
        .tree { margin: 1em; }

        .tree input {
        position: absolute;
        clip: rect(0, 0, 0, 0);
        }

        .tree input ~ ul { display: none; }

        .tree input:checked ~ ul { display: block; }

        /* ---------------------
        Tree rows
        */
        .tree li {
        line-height: 1;
        position: relative;
        padding: 0 0 1em 1em;
        }

        .tree ul li { padding: 1em 0 0 1em; }

        .tree > li:last-child { padding-bottom: 0; }

        /* ---------------------
        Tree labels
        */
        .tree_icon {
        position: relative;
        display: inline-block;
        background: #fff;
        }

        label.tree_icon { cursor: pointer; }

        label.tree_icon:hover { color: #666; }

        /* ---------------------
        Tree expanded icon
        */
        label.tree_icon:before {
        background: #000;
        color: #fff;
        position: relative;
        z-index: 1;
        float: left;
        margin: 0 1em 0 -2em;
        width: 1em;
        height: 1em;
        border-radius: 1em;
        content: '+';
        text-align: center;
        line-height: .9em;
        }

        :checked ~ label.tree_icon:before { content: '-'; }

        /* ---------------------
        Tree branches
        */
        .tree li:before {
        position: absolute;
        top: 0;
        bottom: 0;
        left: -.5em;
        display: block;
        width: 0;
        border-left: 1px solid #777;
        content: "";
        }

        .tree_icon:after {
        position: absolute;
        top: 0;
        left: -1.5em;
        display: block;
        height: 0.5em;
        width: 1em;
        border-bottom: 1px solid #777;
        border-left: 1px solid #777;
        border-radius: 0 0 0 .3em;
        content: '';
        }

        label.tree_icon:after { border-bottom: 0; }

        :checked ~ label.tree_icon:after {
        border-radius: 0 .3em 0 0;
        border-top: 1px solid #777;
        border-right: 1px solid #777;
        border-bottom: 0;
        border-left: 0;
        bottom: -.3em;
        top: 0.5em;
        height: auto;
        }

        .tree li:last-child:before {
        height: 1em;
        bottom: auto;
        }

        .tree > li:last-child:before { display: none; }

        .tree_label {
        position: relative;
        display: inline-block;
        background: #fff;
        line-height: 1.2em;
        height: 0.5em;
        }
  </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script type="text/javascript">
        function isNumber(n) {
            return !isNaN(parseFloat(n)) && isFinite(n);
        }

        function setFontSize(el) {
            var fontSize = el.val();

            if ( isNumber(fontSize) && fontSize >= 0.5 ) {
              $('body').css({ fontSize: fontSize + 'em' });
            } else if ( fontSize ) {
              el.val('1');
              $('body').css({ fontSize: '1em' });
            }
        }

        $(function() {

          $('#fontSize')
            .bind('change', function(){ setFontSize($(this)); })
            .bind('keyup', function(e){
              if (e.keyCode == 27) {
                $(this).val('1');
                $('body').css({ fontSize: '1em' });
              } else {
                setFontSize($(this));
              }
            });

          $(window)
            .bind('keyup', function(e){
              if (e.keyCode == 27) {
                $('#fontSize').val('1');
                $('body').css({ fontSize: '1em' });
              }
            });

        });
    </script>
</head>
<body>
<div id="fontSizeWrapper">
  <label for="fontSize">Font size</label>
  <input type="range" value="1" id="fontSize" step="0.5" min="0.5" max="5" />
</div>
{% macro input(sitemap, context) -%}
{%- for item, next_sitemap in sitemap.items() %}
<li>
    {% if next_sitemap and next_sitemap.nodes %}
    <input type="checkbox" id="{{ item.id }}" />
    <label class="tree_icon" for="{{ item.id }}"></label>
    <a class="tree_label" href="{{ context[(item, None)] }}">
        {{ item.title|e }}
    </a>
    <ul>
        {{ input(next_sitemap, context) }}
    </ul>
    {% else %}
    <span class="tree_icon">
        <a class="tree_label" href="{{ context[(item, None)] }}">
            {{ item.title|e }}
        </a>
    </span>
    {% endif %}
</li>
{%- endfor %}
{%- for item in sitemap.nodes %}
<li>
    <span class="tree_icon">
        <a class="tree_label" href="{{ context[(item, None)] }}">
            {{ item.title|e }}
        </a>
    </span>
</li>
{%- endfor %}
{%- endmacro %}

<ul class="tree">
    {{ input(sitemap, context) }}
</ul>
</body>
</html>