From 49c9bcc586abb7c78f569526a05fea97da86993d Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Tue, 4 Aug 2020 19:01:30 +0200 Subject: Highlight anchor --- .../main/resources/dokka/scripts/platformContentHandler.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'plugins/base/src/main/resources/dokka/scripts') diff --git a/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js b/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js index f0e08f48..78d65333 100644 --- a/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js +++ b/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js @@ -3,6 +3,8 @@ filteringContext = { restrictedDependencies: [], activeFilters: [] } +let highlightedAnchor; + window.addEventListener('load', () => { document.querySelectorAll("div[data-platform-hinted]") .forEach(elem => elem.addEventListener('click', (event) => togglePlatformDependent(event,elem))) @@ -22,6 +24,11 @@ window.addEventListener('load', () => { window.onhashchange = handleAnchor function handleAnchor() { + if(highlightedAnchor){ + highlightedAnchor.classList.remove('anchor-highlight') + highlightedAnchor = null; + } + let searchForTab = function(element) { if(element && element.hasAttribute) { if(element.hasAttribute("data-togglable")) return element; @@ -37,6 +44,11 @@ function handleAnchor() { if (tab) { let found = document.querySelector('.tabs-section > .section-tab[data-togglable="' + tab.getAttribute("data-togglable") + '"]') toggleSections(tab) + const content = element.nextElementSibling + if(content){ + content.classList.add('anchor-highlight') + highlightedAnchor = content + } element.scrollIntoView({behavior: "smooth"}) } } -- cgit