Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

sidebar.js 1.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  1. export default function () {
  2. // TODO override active classes set on server side if sidebar elements are clicked
  3. const activeMenuItem = document.querySelector('.sidebar .active')
  4. if (!activeMenuItem) return
  5. const verticalBufferAboveActiveItem = 40
  6. const activeMenuItemPosition = activeMenuItem.offsetTop - verticalBufferAboveActiveItem
  7. const menu = document.querySelector('.sidebar')
  8. if (activeMenuItemPosition > (window.innerHeight * 0.5)) {
  9. menu.scrollTo(0, activeMenuItemPosition)
  10. }
  11. // if the active category is a standalone category, do not close the other open dropdowns
  12. const activeStandaloneCategory = document.querySelectorAll('.sidebar-category.active.standalone-category')
  13. if (activeStandaloneCategory.length) return
  14. const allOpenDetails = document.querySelectorAll('.sidebar-category:not(.active) details[open]')
  15. if (allOpenDetails) {
  16. for (const openDetail of allOpenDetails) {
  17. openDetail.removeAttribute('open')
  18. const svgArrowElem = openDetail.querySelector('summary > div > svg')
  19. svgArrowElem.remove()
  20. }
  21. }
  22. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...