From 53aee80928993d84032c99b09fd4121de127f42f Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Wed, 4 May 2016 20:28:54 +0100 Subject: [PATCH] Manually set the correct highlighted TOC item when the user clicks it see #406 --- mkdocs/themes/mkdocs/js/base.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mkdocs/themes/mkdocs/js/base.js b/mkdocs/themes/mkdocs/js/base.js index d98859c7..c8888d53 100644 --- a/mkdocs/themes/mkdocs/js/base.js +++ b/mkdocs/themes/mkdocs/js/base.js @@ -29,6 +29,20 @@ $(document).ready(function() { // Highlight.js hljs.initHighlightingOnLoad(); $('table').addClass('table table-striped table-hover'); + + // Improve the scrollspy behaviour when users click on a TOC item. + $(".nav a").on("click", function() { + var clicked = this; + setTimeout(function() { + var active = $('.nav li.active a'); + active = active[active.length - 1]; + if (clicked !== active) { + $(active).parent().removeClass("active"); + $(clicked).parent().addClass("active"); + } + }, 50); + }); + });