workflow/publish: update to php-8.1
[mdref/mdref] / public / index.js
1 "use strict";
2
3 document.addEventListener("DOMContentLoaded", function() {
4 const doTransition = function(e, trans, state, speed) {
5 e.classList.remove(trans + "-in", trans + "-out", "trans-slow", "trans-fast");
6 e.classList.add(trans + "-" + state, "trans-" + speed);
7 return (cb) => setTimeout(cb, speed === "slow" ? 600 : 200);
8 };
9 const letElementBlink = function(e, last) {
10 setTimeout(() => doTransition(e, "fade", "out", "fast")(function() {
11 e.classList.add("blink");
12 doTransition(e, "fade", "in", "fast")(function() {
13 e.classList.remove("blink");
14 doTransition(e, "fade", "out", "slow")(function () {
15 doTransition(e, "fade", "in", "slow");
16 });
17 });
18 }), 200);
19 };
20 const onHashChange = function() {
21 if (location.hash.length > 1) {
22 let hash = decodeURIComponent(location.hash.substring(1));
23 let e = document.getElementById(hash) || document.getElementById(location.hash.substring(1));
24 if (e) {
25 letElementBlink(e);
26 } else {
27 if (hash.substring(hash.length-1) === "*") {
28 hash = hash.substring(0, hash.length-1);
29 }
30 let klass = (hash.substring(0,1) === "$") ? "var" : "constant";
31 let scrolled = false;
32 Array.prototype.forEach.call(document.getElementsByClassName(klass), function(e) {
33 if (e.textContent.substring(0, hash.length) !== hash) {
34 return;
35 }
36 if (!scrolled) {
37 scrolled = true;
38 window.scrollTo(0, e.offsetTop > 64 ? e.offsetTop - 64 : 0);
39 }
40 letElementBlink(e);
41 });
42 }
43 }
44 };
45
46 onHashChange();
47 window.addEventListener("hashchange", onHashChange);
48 setTimeout(()=>document.getElementsByTagName("footer")[0].classList.add("hidden"), 1000);
49 })