aboutsummaryrefslogtreecommitdiff
path: root/static/js/hoverfix.ts
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/hoverfix.ts')
-rw-r--r--static/js/hoverfix.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/static/js/hoverfix.ts b/static/js/hoverfix.ts
new file mode 100644
index 0000000..b6d1a5b
--- /dev/null
+++ b/static/js/hoverfix.ts
@@ -0,0 +1,64 @@
+(function () {
+ /*/
+ * Element.closest() polyfill
+ * https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
+ * https://github.com/idmadj/element-closest-polyfill#readme
+ * Copyright (C) Abdelmadjid Hammou
+ * Licence: ISC | https://www.isc.org/licenses/
+ /*/
+
+ if (typeof Element !== "undefined") {
+ if (!Element.prototype.matches) {
+ Element.prototype.matches = Element.prototype.msMatchesSelector ||
+ Element.prototype.webkitMatchesSelector;
+ }
+ if (!Element.prototype.closest) {
+ Element.prototype.closest = function (s) {
+ var el = this;
+ do {
+ if (el.matches(s)) return el;
+ el = el.parentElement || el.parentNode;
+ } while (el !== null && el.nodeType === 1);
+ return null;
+ };
+ }
+ }
+
+ /*/
+ * -----------------------------------------------------------------
+ /*/
+
+ const disabled = "0s";
+
+ function walk(children, callback) {
+ for (let i = 0; i < children.length; i++) {
+ callback(children[i]);
+ walk(children[i].children, callback);
+ }
+ }
+
+ self.addEventListener("mousemove", function (event) {
+ if (typeof event.target.closest !== "function") return;
+ tree = event.target.closest("figure") || event.target.closest("article");
+
+ if (tree !== null) {
+ walk(tree.children, function (element) {
+ const delay = self.getComputedStyle(element).getPropertyValue(
+ "transition-delay",
+ );
+ if (delay !== disabled) {
+ element.style.setProperty("visibility", "hidden");
+ }
+ });
+
+ walk(tree.children, function (element) {
+ const delay = self.getComputedStyle(element).getPropertyValue(
+ "transition-delay",
+ );
+ if (delay !== disabled) {
+ element.style.removeProperty("visibility");
+ }
+ });
+ }
+ });
+})();