list-menu.html 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <div class="menu">
  2. <h6 class="menu__label">
  3. {{ if .IsHome }}
  4. {{ .Site.Title }}
  5. {{ else }}
  6. {{ $.Param "Title" }}
  7. {{ end }}
  8. </h6>
  9. <ul>
  10. {{ $root := . }}
  11. {{ range (.Site.GetPage "section" .Type).Pages }}
  12. {{ template "render-menu" (dict "ctx" . "root" $root "depth" 0)}}
  13. {{ end }}
  14. </ul>
  15. </div>
  16. {{ define "render-menu" }}
  17. {{ $root := .root }}
  18. {{ $ctx := .ctx }}
  19. {{ $depth := .depth }}
  20. {{ $currentURL := $root.Permalink }}
  21. {{ $sectionName1 := index (last 1 (split (delimit (split $ctx.Permalink "/") "," "") ",")) 0 }}
  22. {{ $sectionName2 := index (last 2 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  23. {{ $active := in $currentURL $ctx.Permalink }}
  24. {{ $active = or $active (eq $sectionName1 $sectionName2) }}
  25. {{ $active = or $active (in $currentURL $sectionName1) }}
  26. {{ if $ctx.Params.Collapsible }}
  27. <li class="menu__title--collapse {{ if $active }}active{{ end }}" data-depth="{{ $depth }}">
  28. <span class="menu__title--collapse-text">
  29. {{ $ctx.Title }}
  30. </span>
  31. <span
  32. class="menu__title--icon {{ if $active }}{{ if eq ($root.Param "languagedir") "rtl" }}downrtl{{ else }}down{{ end }}{{ else }}right{{ end }}">
  33. {{ if eq ($root.Param "languagedir") "rtl" }}
  34. {{ partial "svgs/arrow-left.svg" (dict "width" 22 "height" 22) }}
  35. {{ else }}
  36. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  37. {{ end }}
  38. </span>
  39. </li>
  40. <ul class="menu__list {{ if $active }}active{{ else if (in $ctx.Permalink (print "/" $sectionName1 "/")) }}{{ end }}"
  41. data-data={{ print "/" $sectionName1 "/"}} data-link={{ .root.Permalink }}>
  42. {{ range $ctx.Pages.ByWeight }}
  43. {{ if .Params.Collapsible }}
  44. {{ template "render-menu" (dict "ctx" . "root" $root "depth" (add $depth 1)) }}
  45. {{ else }}
  46. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  47. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  48. <li>
  49. <a href="{{ .Permalink }}"
  50. class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}"
  51. data-depth="{{ $depth }}">{{ .Title }}</a>
  52. </li>
  53. {{ end }}
  54. {{ end }}
  55. </ul>
  56. {{ else }}
  57. {{ $lastUrlElement1 := index (last 1 (split (delimit (split $ctx.Permalink "/") "," "") ",")) 0 }}
  58. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  59. <li class="{{ if $active }}active{{ end }}">
  60. <a href="{{ $ctx.Permalink }}" class="menu__title {{ if $active }}active{{ end }}">{{ $ctx.Title }}</a>
  61. </li>
  62. {{ end }}
  63. {{ end }}
  64. <script>
  65. var menuTitle = document.querySelectorAll('.menu__title');
  66. var modal = document.getElementById("myModal");
  67. var drawer = document.getElementById('myDrawer');
  68. var closeDrawer = function () {
  69. setTimeout(function () {
  70. modal.style.opacity = 0;
  71. drawer.style.left = '-100%';
  72. modal.style.left = '-100%';
  73. }, 250);
  74. }
  75. menuTitle ?
  76. menuTitle.forEach(function(elem) {
  77. elem.onclick = function() {
  78. closeDrawer();
  79. localStorage.setItem('isDrawerOpen', 'false');
  80. }
  81. }) : null;
  82. </script>