|
39 | 39 | <div |
40 | 40 | id="{{ $id }}" |
41 | 41 | class="relative" |
| 42 | + style="container-type: inline-size;" |
42 | 43 | data-twe-carousel-init |
43 | 44 | data-twe-ride="carousel" |
44 | 45 | data-twe-interval="{{ $interval }}"> |
45 | 46 | <div |
46 | | - class="absolute right-0 bottom-0 left-0 z-2 mx-[15%] mb-10 flex list-none justify-center p-0" |
| 47 | + class="absolute right-0 left-0 z-2 mx-[15%] mb-10 flex list-none justify-center p-0" |
| 48 | + style="top: calc(100cqi * {{ $aspecty }} / {{ $aspectx }} - 2.5rem);" |
47 | 49 | data-twe-carousel-indicators> |
48 | 50 | {{ $num := 0 }} |
49 | 51 | {{ range $images }} |
|
89 | 91 | class="block absolute top-0 object-cover w-full h-full not-prose nozoom" |
90 | 92 | alt="carousel image {{ add $index 1 }}"> |
91 | 93 | </div> |
92 | | - {{ if $caption }} |
| 94 | + {{ if or $caption $captionsParam }} |
93 | 95 | <figcaption |
94 | | - class="absolute left-0 right-0" |
95 | | - style="top: calc(100%);" |
96 | | - >{{ $caption | markdownify }}</figcaption> |
| 96 | + class="mt-1 {{ if not $caption }}invisible{{ end }}" |
| 97 | + {{ if not $caption }}aria-hidden="true"{{ end }} |
| 98 | + >{{ if $caption }}{{ $caption | markdownify }}{{ else }} {{ end }}</figcaption> |
97 | 99 | {{ end }} |
98 | 100 | </div> |
99 | 101 | {{ end }} |
100 | 102 | </div> |
101 | 103 |
|
102 | 104 | <button |
103 | | - class="absolute top-0 bottom-0 left-0 z-2 flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:no-underline hover:opacity-90 hover:outline-none focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none" |
| 105 | + class="absolute top-0 left-0 z-2 flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:no-underline hover:opacity-90 hover:outline-none focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none" |
| 106 | + style="height: calc(100cqi * {{ $aspecty }} / {{ $aspectx }});" |
104 | 107 | type="button" |
105 | 108 | data-twe-target="#{{ $id }}" |
106 | 109 | data-twe-slide="prev"> |
|
122 | 125 | </button> |
123 | 126 |
|
124 | 127 | <button |
125 | | - class="absolute top-0 bottom-0 right-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:no-underline hover:opacity-90 hover:outline-none focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none" |
| 128 | + class="absolute top-0 right-0 z-[1] flex w-[15%] items-center justify-center border-0 bg-none p-0 text-center opacity-50 transition-opacity duration-150 ease-[cubic-bezier(0.25,0.1,0.25,1.0)] hover:no-underline hover:opacity-90 hover:outline-none focus:no-underline focus:opacity-90 focus:outline-none motion-reduce:transition-none" |
| 129 | + style="height: calc(100cqi * {{ $aspecty }} / {{ $aspectx }});" |
126 | 130 | type="button" |
127 | 131 | data-twe-target="#{{ $id }}" |
128 | 132 | data-twe-slide="next"> |
|
143 | 147 | > |
144 | 148 | </button> |
145 | 149 | </div> |
| 150 | + |
| 151 | + {{ if $captionsParam }} |
| 152 | + <script> |
| 153 | + (() => { |
| 154 | + const root = document.getElementById("{{ $id }}"); |
| 155 | + if (!root) return; |
| 156 | + |
| 157 | + const items = Array.from(root.querySelectorAll("[data-twe-carousel-item]")); |
| 158 | + const captions = items |
| 159 | + .map((item) => item.querySelector("figcaption")) |
| 160 | + .filter((caption) => caption); |
| 161 | + if (captions.length < 2) return; |
| 162 | + |
| 163 | + const measureAndFixCaptionHeight = () => { |
| 164 | + const hiddenItems = items.filter((item) => item.classList.contains("hidden")); |
| 165 | + hiddenItems.forEach((item) => item.classList.remove("hidden")); |
| 166 | + |
| 167 | + const maxHeight = Math.max( |
| 168 | + ...captions.map((caption) => Math.ceil(caption.getBoundingClientRect().height)), |
| 169 | + ); |
| 170 | + |
| 171 | + hiddenItems.forEach((item) => item.classList.add("hidden")); |
| 172 | + captions.forEach((caption) => { |
| 173 | + caption.style.minHeight = `${maxHeight}px`; |
| 174 | + }); |
| 175 | + }; |
| 176 | + |
| 177 | + window.requestAnimationFrame(measureAndFixCaptionHeight); |
| 178 | + window.addEventListener("load", measureAndFixCaptionHeight, { once: true }); |
| 179 | + window.addEventListener("resize", measureAndFixCaptionHeight); |
| 180 | + })(); |
| 181 | + </script> |
| 182 | + {{ end }} |
0 commit comments