From 008883b9087621b9e0d8c166b89fc4035b6b82e5 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sat, 14 Sep 2019 19:24:03 -0400 Subject: [PATCH] Move script to file --- src/assets/js/script.js | 22 ++++++++++++++++++++++ src/index.html | 25 +------------------------ 2 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 src/assets/js/script.js diff --git a/src/assets/js/script.js b/src/assets/js/script.js new file mode 100644 index 00000000..791f9802 --- /dev/null +++ b/src/assets/js/script.js @@ -0,0 +1,22 @@ +addEventListener("hashchange", () => { + var q = document.querySelector(location.hash) + if (q instanceof HTMLHeadingElement && q.parentElement.parentElement instanceof HTMLDetailsElement) + q.parentElement.parentElement.open = true; +}) +if (location.hash) requestAnimationFrame(() => dispatchEvent(new HashChangeEvent("hashchange"))); +if ('IntersectionObserver' in self) { + const mo = new IntersectionObserver(i => { + for (const s of i) { + /** @type {HTMLVideoElement} */ + const v = s.target; + if (s.isIntersecting && v.paused) { + v.load() + v.play() + } else if (!v.paused) v.pause() + } + }) + for (let v of document.querySelectorAll('video')) { + mo.observe(v) + v.controls = false + } +} diff --git a/src/index.html b/src/index.html index ba7c2d12..e21f8ab1 100644 --- a/src/index.html +++ b/src/index.html @@ -135,29 +135,6 @@ - +