list-menu.html 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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) }}{{ if eq ($.Param "languagedir") "rtl" }}downrtl{{ else }}down{{ end }}{{ else }}right{{ end }}">
  18. {{ if eq ($.Param "languagedir") "rtl" }}
  19. {{ partial "svgs/arrow-left.svg" (dict "width" 22 "height" 22) }}
  20. {{ else }}
  21. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  22. {{ end }}
  23. </span>
  24. </span>
  25. <ul class="menu__list {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}active{{ end }}">
  26. {{ range .Pages.ByWeight }}
  27. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  28. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  29. <li>
  30. <a href="{{ .Permalink }}" class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}">{{ .Title }}</a>
  31. </li>
  32. {{ end }}
  33. </ul>
  34. {{ else }}
  35. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  36. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  37. <li class="{{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}">
  38. <a href="{{ .Permalink }}" class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}">{{ .Title }}</a>
  39. </li>
  40. {{ end }}
  41. {{ end }}
  42. </ul>
  43. </div>
  44. <script>
  45. var menuTitle = document.querySelectorAll('.menu__title');
  46. var modal = document.getElementById("myModal");
  47. var drawer = document.getElementById('myDrawer');
  48. var closeDrawer = function () {
  49. setTimeout(function () {
  50. modal.style.opacity = 0;
  51. drawer.style.left = '-100%';
  52. modal.style.left = '-100%';
  53. }, 250);
  54. }
  55. menuTitle ?
  56. menuTitle.forEach(function(elem) {
  57. elem.onclick = function() {
  58. closeDrawer();
  59. localStorage.setItem('isDrawerOpen', 'false');
  60. }
  61. }) : null;
  62. </script>