Skip to content

Commit

Permalink
fix link-click toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
cjsheets committed Mar 11, 2018
1 parent bba53bf commit 69630fa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ site_author: 'Chad Sheets'

theme:
name: rtd-dropdown
# Default settings
collapse_by_default: false

repo_url: https://github.com/cjsheets/readthedocs-dropdown

Expand Down
5 changes: 3 additions & 2 deletions rtd_dropdown/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ $( document ).ready(function() {
$('table').addClass('docutils');

toggleCurrent = function (elem) {
console.log('toggle');
var parent_li = elem.closest('li');
parent_li.siblings('li.current').removeClass('current');
parent_li.siblings().find('li.current').removeClass('current');
Expand All @@ -53,11 +52,13 @@ $( document ).ready(function() {
var link = $(this);
expand = $('<span class="toctree-expand"></span>');
expand.on('click', function (ev) {
console.log('click');
toggleCurrent(link);
ev.stopPropagation();
return false;
});
link.on('click', function (ev) {
toggleCurrent(link);
});
link.prepend(expand);
});
});
Expand Down
21 changes: 12 additions & 9 deletions rtd_dropdown/nav-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
{{ nav_item.title }}
</a>

{% if nav_item.children %}
<ul class="{% if nav_item.active%}current{%endif%} subnav">
{% for nav_item in nav_item.children %}
{% include "nav-item.html" %}
{% endfor %}
</ul>
{% endif %}
{% if not nav_item.children %}
{% include "toc.html" %}
{#| Children are only added to the currently selected root item |#}
{% if nav_item.active %}
{% if nav_item.children %}
<ul class="{% if nav_item.active%}current{%endif%} subnav">
{% for nav_item in nav_item.children %}
{% include "nav-item.html" %}
{% endfor %}
</ul>
{% endif %}
{% if not nav_item.children %}
{% include "toc.html" %}
{% endif %}
{% endif %}
</li>
10 changes: 10 additions & 0 deletions rtd_dropdown/nav.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{#| Loop over the major, root-level groups |#}
{% for nav_item in nav %}

{#| Determine the full path of the root-level link |#}
{%- set nav_item_children = nav_item.children %}
{%- set nav_ns = namespace(url_list=false) %}

{%- if nav_item.children is defined %}
{% for _ in range(1, 6) %}
{%- if nav_item_children is defined %}
Expand Down Expand Up @@ -50,4 +52,12 @@
{%- endif %}
</ul>

<!--
| This is a hacky way to pass setting from the template generator to the
| javascript that drives the dropdown functionality
-->
<div style="width: 1px; height: 1px; visibility: none;">

</div>

{% endfor %}
21 changes: 11 additions & 10 deletions rtd_dropdown/toc-item.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@




{{(nav_item.title + toc_ns.top_level_headings | string) | debug}}
{%- set toclevel = toclevel + 1 %}

{#| Support collapse-by-default setting |#}
{% if toc_item.active and (toc_ns.top_level_headings == 1 or not
(config.theme is defined and config.theme.collapse_by_default)) %}
{%- set class_is_active = 'current' %}
{% endif %}

{% if toc_item.children is defined and toc_item.children | length > 0 and toclevel < 2 %}
<li class="{% if nav_item.active%}current{%endif%} toctree-l{{navlevel + 1}} toc-item">
<li class="{{class_is_active}} toctree-l{{navlevel + 1}}">
{% if toc_ns.top_level_headings is defined and toc_ns.top_level_headings > 1 %}
<a href="{{ nav_item.url }}" title="{{ nav_item.title }}"
class="{% if nav_item.active%}current{%endif%}">
<a href="{{ toc_item.url }}" title="{{ nav_item.title }}"
class="{{class_is_active}}">
{{ toc_item.title }}
</a>
{% endif %}
<ul class="{% if nav_item.active%}current{%endif%} subnav">
<ul class="{% if toc_item.active%}current{%endif%} subnav">
{% for toc_item in toc_item.children %}
{% include "toc-item.html" %}
{% endfor %}
</ul>
</li>
{% else %}
<li class="toctree-l{{navlevel + 1}} toc-item">
<a href="{{ nav_item.url }}" title="{{ nav_item.title }}">{{ toc_item.title }}</a>
<a href="{{ toc_item.url }}" title="{{ nav_item.title }}">{{ toc_item.title }}</a>
</li>
{% endif %}

0 comments on commit 69630fa

Please sign in to comment.