From bed1e4214ee704fb4b1472e6c2bad181a5ea209a Mon Sep 17 00:00:00 2001 From: Jesse Tan Date: Wed, 20 Dec 2017 11:39:39 +0100 Subject: [PATCH] Always call nav.enable() to make nav collapsable This used to depend on the sticky nav being enabled. Fixes #481 --- js/theme.js | 46 ++++++++++++++++++++++-------------- sphinx_rtd_theme/layout.html | 9 +++---- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/js/theme.js b/js/theme.js index 9fb328297..c9158d19a 100644 --- a/js/theme.js +++ b/js/theme.js @@ -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) { @@ -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 ($) { @@ -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 }; } diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index 965cc45c8..e647bddda 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -209,14 +209,15 @@ {% endif %} - {# STICKY NAVIGATION #} - {% if theme_sticky_navigation|tobool %} - {% endif %} {%- block footer %} {% endblock %}