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.ts 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
29
30
  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') as HTMLElement
  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(
  13. '.sidebar-category.active.standalone-category'
  14. )
  15. if (activeStandaloneCategory.length) return
  16. const allOpenDetails = document.querySelectorAll('.sidebar-category:not(.active) details[open]')
  17. if (allOpenDetails) {
  18. for (const openDetail of Array.from(allOpenDetails)) {
  19. openDetail.removeAttribute('open')
  20. const svgArrowElem = openDetail.querySelector('summary > div > svg')
  21. svgArrowElem?.remove()
  22. }
  23. }
  24. }
Tip!

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

Comments

Loading...