Move script to file

This commit is contained in:
Eugene 2019-09-14 19:24:03 -04:00
parent d9b1b92b08
commit 008883b908
No known key found for this signature in database
GPG Key ID: E1FD745328866B0A
2 changed files with 23 additions and 24 deletions

22
src/assets/js/script.js Normal file
View File

@ -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
}
}

View File

@ -135,29 +135,6 @@
<script src="assets/js/bootstrap-4.3.1.min.js"></script>
<script src="assets/js/bootstrap-toc-1.0.1.min.js"></script>
<!-- Convenience script -->
<script>
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
}
}
</script>
<script src="assets/js/script.js"></script>
</body>
</html>