list-menu.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <div class="menu">
  2. <h6 class="menu__label">
  3. {{ if .IsHome }}
  4. {{ .Site.Title }}
  5. {{ else }}
  6. {{ .Type }}
  7. {{ end }}
  8. </h6>
  9. <ul>
  10. {{ $currentURL := .Permalink }}
  11. {{ range (.Site.GetPage "section" .Type).Pages }}
  12. {{ $sectionName1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  13. {{ $sectionName2 := index (last 2 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  14. {{ if .Params.Collapsible }}
  15. <span class="menu__title--collapse {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}active{{ end }}">
  16. {{ .Title }}
  17. <span class="menu__title--icon {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}down{{ else }}right{{ end }}">
  18. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  19. </span>
  20. </span>
  21. <ul class="menu__list {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}active{{ end }}">
  22. {{ range .Pages.ByWeight }}
  23. {{ $lastUrlElement := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  24. <li>
  25. <a href="{{ .Permalink }}" class="menu__title {{ if and (in $currentURL $lastUrlElement) (eq $sectionName1 $sectionName2) }}active{{ end }}">{{ .Title }}</a>
  26. </li>
  27. {{ end }}
  28. </ul>
  29. {{ else }}
  30. {{ $lastUrlElement := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  31. <li class="{{ if in $currentURL $lastUrlElement }}active{{ end }}">
  32. <a href="{{ .Permalink }}" class="menu__title {{ if in $currentURL $lastUrlElement }}active{{ end }}">{{ .Title }}</a>
  33. </li>
  34. {{ end }}
  35. {{ end }}
  36. </ul>
  37. </div>
  38. <script>
  39. var menuTitle = document.querySelectorAll('.menu__title');
  40. var modal = document.getElementById("myModal");
  41. var drawer = document.getElementById('myDrawer');
  42. var closeDrawer = function () {
  43. setTimeout(function () {
  44. modal.style.opacity = 0;
  45. drawer.style.left = '-100%';
  46. modal.style.left = '-100%';
  47. }, 250);
  48. }
  49. menuTitle ?
  50. menuTitle.forEach(function(elem) {
  51. elem.onclick = function() {
  52. closeDrawer();
  53. localStorage.setItem('isDrawerOpen', 'false');
  54. }
  55. }) : null;
  56. </script>