assets/js/just-the-docs.js in just-the-docs-0.3.3 vs assets/js/just-the-docs.js in just-the-docs-0.4.0.rc1
- old
+ new
@@ -67,11 +67,11 @@
{%- if site.search_enabled != false %}
// Site search
function initSearch() {
var request = new XMLHttpRequest();
- request.open('GET', '{{ "assets/js/search-data.json" | absolute_url }}', true);
+ request.open('GET', '{{ "assets/js/search-data.json" | relative_url }}', true);
request.onload = function(){
if (request.status >= 200 && request.status < 400) {
var docs = JSON.parse(request.responseText);
@@ -452,19 +452,32 @@
return cssFileHref.substring(cssFileHref.lastIndexOf('-') + 1, cssFileHref.length - 4);
}
jtd.setTheme = function(theme) {
var cssFile = document.querySelector('[rel="stylesheet"]');
- cssFile.setAttribute('href', '{{ "assets/css/just-the-docs-" | absolute_url }}' + theme + '.css');
+ cssFile.setAttribute('href', '{{ "assets/css/just-the-docs-" | relative_url }}' + theme + '.css');
}
+// Scroll site-nav to ensure the link to the current page is visible
+
+function scrollNav() {
+ const href = document.location.pathname;
+ const siteNav = document.getElementById('site-nav');
+ const targetLink = siteNav.querySelector('a[href="' + href + '"], a[href="' + href + '/"]');
+ if(targetLink){
+ const rect = targetLink.getBoundingClientRect();
+ siteNav.scrollBy(0, rect.top - 3*rect.height);
+ }
+}
+
// Document ready
jtd.onReady(function(){
initNav();
{%- if site.search_enabled != false %}
initSearch();
{%- endif %}
+ scrollNav();
});
})(window.jtd = window.jtd || {});
{% include js/custom.js %}