(e)
| 278 | |
| 279 | // Disable autoplay for videos when the prefers-reduced-motion media query is enabled. |
| 280 | function reducedMotionCheck(e) { |
| 281 | let videos = document.querySelectorAll('video[autoplay]'); |
| 282 | if (e.matches) { |
| 283 | for (let v of videos) { |
| 284 | v.pause(); |
| 285 | v.controls = true; |
| 286 | v.removeAttribute('tabindex'); |
| 287 | v.onclick = undefined; |
| 288 | v.onkeydown = undefined; |
| 289 | } |
| 290 | } else { |
| 291 | for (let v of videos) { |
| 292 | let toggle = () => { |
| 293 | if (v.paused) { |
| 294 | v.play(); |
| 295 | } else { |
| 296 | v.pause(); |
| 297 | } |
| 298 | }; |
| 299 | if (v.paused) { |
| 300 | v.play(); |
| 301 | } |
| 302 | v.tabIndex = 0; |
| 303 | v.controls = false; |
| 304 | v.onclick = toggle; |
| 305 | v.onkeydown = e => { |
| 306 | if (e.key === ' ' || e.key === 'Enter') { |
| 307 | e.preventDefault(); |
| 308 | toggle(); |
| 309 | } |
| 310 | }; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | let prefersReducedMotion = matchMedia('(prefers-reduced-motion)'); |
| 316 | reducedMotionCheck(prefersReducedMotion); |
no test coverage detected