Skip to content

Commit

Permalink
Always call nav.enable() to make nav collapsable
Browse files Browse the repository at this point in the history
This used to depend on the sticky nav being enabled.
Fixes #481
  • Loading branch information
jessetan committed Dec 20, 2017
1 parent 5de02b5 commit bed1e42
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
46 changes: 28 additions & 18 deletions js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@ function ThemeNav () {
isRunning: false
};

nav.enable = function () {
nav.enable = function (withStickyNav) {
var self = this;

if (!self.isRunning) {
self.isRunning = true;
jQuery(function ($) {
self.init($);
if (self.isRunning) {
// Only allow enabling nav logic once
return;
}

self.reset();
self.win.on('hashchange', self.reset);
self.isRunning = true;
jQuery(function ($) {
self.init($);

self.reset();
self.win.on('hashchange', self.reset);

if (withStickyNav) {
// Set scroll monitor
self.win.on('scroll', function () {
if (!self.linkScroll) {
Expand All @@ -35,18 +40,23 @@ function ThemeNav () {
}
}
});
}

// Set resize monitor
self.win.on('resize', function () {
if (!self.winResize) {
self.winResize = true;
requestAnimationFrame(function() { self.onResize(); });
}
});

self.onResize();
// Set resize monitor
self.win.on('resize', function () {
if (!self.winResize) {
self.winResize = true;
requestAnimationFrame(function() { self.onResize(); });
}
});
};

self.onResize();
});

};

nav.enableSticky = function() {
this.enable(true);
};

nav.init = function ($) {
Expand Down Expand Up @@ -176,7 +186,7 @@ function ThemeNav () {
module.exports.ThemeNav = ThemeNav();

if (typeof(window) != 'undefined') {
window.SphinxRtdTheme = { StickyNav: module.exports.ThemeNav };
window.SphinxRtdTheme = { Navigation: module.exports.ThemeNav };
}


Expand Down
9 changes: 5 additions & 4 deletions sphinx_rtd_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,15 @@
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
{% endif %}

{# STICKY NAVIGATION #}
{% if theme_sticky_navigation|tobool %}
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
{% if theme_sticky_navigation|tobool %}
SphinxRtdTheme.Navigation.enableSticky();
{% else %}
SphinxRtdTheme.Navigation.enable();
{% endif %}
});
</script>
{% endif %}

{%- block footer %} {% endblock %}

Expand Down

0 comments on commit bed1e42

Please sign in to comment.