diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2023-02-24 17:44:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 17:44:24 +0200 |
commit | 1040288ca76e070445f1400df2fcc5a56310be28 (patch) | |
tree | 52bed40e8a320f0835540b0cd38ea1899800e395 /plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js | |
parent | 8d23340d1c377b8f490cdee3c2c874453d321dd8 (diff) | |
download | dokka-1040288ca76e070445f1400df2fcc5a56310be28.tar.gz dokka-1040288ca76e070445f1400df2fcc5a56310be28.tar.bz2 dokka-1040288ca76e070445f1400df2fcc5a56310be28.zip |
Reorganize tabs for Classlike (#2764)
Diffstat (limited to 'plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js')
-rw-r--r-- | plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js index def9dae8..1f99ba1f 100644 --- a/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js +++ b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js @@ -129,22 +129,39 @@ function handleAnchor() { highlightedAnchor = null; } - let searchForTab = function (element) { + let searchForContentTarget = function (element) { if (element && element.hasAttribute) { - if (element.hasAttribute("data-togglable")) return element; - else return searchForTab(element.parentNode) + if (element.hasAttribute("data-togglable")) return element.getAttribute("data-togglable"); + else return searchForContentTarget(element.parentNode) } else return null } + + let findAnyTab = function (target) { + let result = null + document.querySelectorAll('div[tabs-section] > button[data-togglable]') + .forEach(node => { + if(node.getAttribute("data-togglable").split(",").includes(target)) { + result = node + } + }) + return result + } + let anchor = window.location.hash if (anchor != "") { anchor = anchor.substring(1) let element = document.querySelector('a[data-name="' + anchor + '"]') + if (element) { - let tab = searchForTab(element) - if (tab) { - toggleSections(tab) - } const content = element.nextElementSibling + const contentStyle = window.getComputedStyle(content) + if(contentStyle.display == 'none') { + let tab = findAnyTab(searchForContentTarget(content)) + if (tab) { + toggleSections(tab) + } + } + if (content) { content.classList.add('anchor-highlight') highlightedAnchor = content @@ -174,10 +191,7 @@ function initTabs() { function showCorrespondingTabBody(element) { const buttonWithKey = element.querySelector("button[data-active]") if (buttonWithKey) { - const key = buttonWithKey.getAttribute("data-togglable") - document.querySelector(".tabs-section-body") - .querySelector("div[data-togglable='" + key + "']") - .setAttribute("data-active", "") + toggleSections(buttonWithKey) } } @@ -249,7 +263,6 @@ function removeSourcesetFilterFromCache(sourceset) { } function toggleSections(target) { - localStorage.setItem('active-tab', JSON.stringify(target.getAttribute("data-togglable"))) const activateTabs = (containerClass) => { for (const element of document.getElementsByClassName(containerClass)) { for (const child of element.children) { @@ -261,13 +274,24 @@ function toggleSections(target) { } } } - + const toggleTargets = target.getAttribute("data-togglable").split(",") + const activateTabsBody = (containerClass) => { + document.querySelectorAll("." + containerClass + " *[data-togglable]") + .forEach(child => { + if (toggleTargets.includes(child.getAttribute("data-togglable"))) { + child.setAttribute("data-active", "") + } else if(!child.classList.contains("sourceset-dependent-content")) { // data-togglable is used to switch source set as well, ignore it + child.removeAttribute("data-active") + } + }) + } activateTabs("tabs-section") - activateTabs("tabs-section-body") + activateTabsBody("tabs-section-body") } function toggleSectionsEventHandler(evt) { if (!evt.target.getAttribute("data-togglable")) return + localStorage.setItem('active-tab', JSON.stringify(evt.target.getAttribute("data-togglable"))) toggleSections(evt.target) } |