list-menu.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. <span class="menu__title--collapse {{ if $active }}active{{ end }}" data-depth="{{ $depth }}">
  28. {{ $ctx.Title }}
  29. <span
  30. class="menu__title--icon {{ if $active }}{{ if eq ($root.Param "languagedir") "rtl" }}downrtl{{ else }}down{{ end }}{{ else }}right{{ end }}">
  31. {{ if eq ($root.Param "languagedir") "rtl" }}
  32. {{ partial "svgs/arrow-left.svg" (dict "width" 22 "height" 22) }}
  33. {{ else }}
  34. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  35. {{ end }}
  36. </span>
  37. </span>
  38. <ul class="menu__list {{ if $active }}active{{ else if (in $ctx.Permalink (print "/" $sectionName1 "/")) }}{{ end }}"
  39. data-data={{ print "/" $sectionName1 "/"}} data-link={{ .root.Permalink }}>
  40. {{ range $ctx.Pages.ByWeight }}
  41. {{ if .Params.Collapsible }}
  42. {{ template "render-menu" (dict "ctx" . "root" $root "depth" (add $depth 1)) }}
  43. {{ else }}
  44. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  45. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  46. <li>
  47. <a href="{{ .Permalink }}"
  48. class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}"
  49. data-depth="{{ $depth }}">{{ .Title }}</a>
  50. </li>
  51. {{ end }}
  52. {{ end }}
  53. </ul>
  54. {{ else }}
  55. {{ $lastUrlElement1 := index (last 1 (split (delimit (split $ctx.Permalink "/") "," "") ",")) 0 }}
  56. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  57. <li class="{{ if $active }}active{{ end }}">
  58. <a href="{{ $ctx.Permalink }}" class="menu__title {{ if $active }}active{{ end }}">{{ $ctx.Title }}</a>
  59. </li>
  60. {{ end }}
  61. {{ end }}
  62. <script>
  63. var menuTitle = document.querySelectorAll('.menu__title');
  64. var modal = document.getElementById("myModal");
  65. var drawer = document.getElementById('myDrawer');
  66. var closeDrawer = function () {
  67. setTimeout(function () {
  68. modal.style.opacity = 0;
  69. drawer.style.left = '-100%';
  70. modal.style.left = '-100%';
  71. }, 250);
  72. }
  73. menuTitle ?
  74. menuTitle.forEach(function(elem) {
  75. elem.onclick = function() {
  76. closeDrawer();
  77. localStorage.setItem('isDrawerOpen', 'false');
  78. }
  79. }) : null;
  80. </script>