mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Always call nav.enable() to make nav collapsable (#519)
Always call nav.enable() to make nav collapsing work
This commit is contained in:
parent
5de02b5a1a
commit
5db94ebf5f
46
js/theme.js
46
js/theme.js
@ -15,17 +15,22 @@ function ThemeNav () {
|
|||||||
isRunning: false
|
isRunning: false
|
||||||
};
|
};
|
||||||
|
|
||||||
nav.enable = function () {
|
nav.enable = function (withStickyNav) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!self.isRunning) {
|
if (self.isRunning) {
|
||||||
self.isRunning = true;
|
// Only allow enabling nav logic once
|
||||||
jQuery(function ($) {
|
return;
|
||||||
self.init($);
|
}
|
||||||
|
|
||||||
self.reset();
|
self.isRunning = true;
|
||||||
self.win.on('hashchange', self.reset);
|
jQuery(function ($) {
|
||||||
|
self.init($);
|
||||||
|
|
||||||
|
self.reset();
|
||||||
|
self.win.on('hashchange', self.reset);
|
||||||
|
|
||||||
|
if (withStickyNav) {
|
||||||
// Set scroll monitor
|
// Set scroll monitor
|
||||||
self.win.on('scroll', function () {
|
self.win.on('scroll', function () {
|
||||||
if (!self.linkScroll) {
|
if (!self.linkScroll) {
|
||||||
@ -35,18 +40,23 @@ function ThemeNav () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Set resize monitor
|
// Set resize monitor
|
||||||
self.win.on('resize', function () {
|
self.win.on('resize', function () {
|
||||||
if (!self.winResize) {
|
if (!self.winResize) {
|
||||||
self.winResize = true;
|
self.winResize = true;
|
||||||
requestAnimationFrame(function() { self.onResize(); });
|
requestAnimationFrame(function() { self.onResize(); });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
self.onResize();
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
self.onResize();
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
nav.enableSticky = function() {
|
||||||
|
this.enable(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
nav.init = function ($) {
|
nav.init = function ($) {
|
||||||
@ -176,7 +186,7 @@ function ThemeNav () {
|
|||||||
module.exports.ThemeNav = ThemeNav();
|
module.exports.ThemeNav = ThemeNav();
|
||||||
|
|
||||||
if (typeof(window) != 'undefined') {
|
if (typeof(window) != 'undefined') {
|
||||||
window.SphinxRtdTheme = { StickyNav: module.exports.ThemeNav };
|
window.SphinxRtdTheme = { Navigation: module.exports.ThemeNav };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,14 +209,15 @@
|
|||||||
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
|
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# STICKY NAVIGATION #}
|
|
||||||
{% if theme_sticky_navigation|tobool %}
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(function () {
|
jQuery(function () {
|
||||||
SphinxRtdTheme.StickyNav.enable();
|
{% if theme_sticky_navigation|tobool %}
|
||||||
|
SphinxRtdTheme.Navigation.enableSticky();
|
||||||
|
{% else %}
|
||||||
|
SphinxRtdTheme.Navigation.enable();
|
||||||
|
{% endif %}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{%- block footer %} {% endblock %}
|
{%- block footer %} {% endblock %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user