From d9a29082d810f2954c29aea215ba5cbbaa361ac6 Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 6 Aug 2022 02:09:42 -0400 Subject: themes/default/layouts/partials: Hack in card context menu --- static/icons/feather/arrow-down-circle.svg | 15 +++++++++++++++ static/icons/feather/external-link.svg | 15 +++++++++++++++ static/js/contextmenu.ts | 28 ++++++++++++++++++++++++++++ static/js/index.ts | 1 + 4 files changed, 59 insertions(+) create mode 100644 static/icons/feather/arrow-down-circle.svg create mode 100644 static/icons/feather/external-link.svg create mode 100644 static/js/contextmenu.ts (limited to 'static') diff --git a/static/icons/feather/arrow-down-circle.svg b/static/icons/feather/arrow-down-circle.svg new file mode 100644 index 0000000..eb9f1a0 --- /dev/null +++ b/static/icons/feather/arrow-down-circle.svg @@ -0,0 +1,15 @@ + + + + + diff --git a/static/icons/feather/external-link.svg b/static/icons/feather/external-link.svg new file mode 100644 index 0000000..537b731 --- /dev/null +++ b/static/icons/feather/external-link.svg @@ -0,0 +1,15 @@ + + + + + diff --git a/static/js/contextmenu.ts b/static/js/contextmenu.ts new file mode 100644 index 0000000..dea9bec --- /dev/null +++ b/static/js/contextmenu.ts @@ -0,0 +1,28 @@ +(function () { + const hide = (triggers) => { + for (let i = 0; i < triggers.length; i++) { + triggers[i].checked = false; + } + }; + + const hideIfClickedOutside = (menus, triggers, event) => { + for (let i = 0; i < menus.length; i++) { + const active = triggers[i].checked === true; + const outside = !menus[i].contains(event.target); + if (outside && active) hide(triggers); + } + }; + + self.addEventListener("scroll", function () { + const triggers = document.querySelectorAll("micro-metadata-menu input"); + hide(triggers); + }); + + ["click", "touchstart"].forEach(function (event) { + self.addEventListener(event, function (event) { + const menus = document.querySelectorAll("micro-metadata-menu"); + const triggers = document.querySelectorAll("micro-metadata-menu input"); + hideIfClickedOutside(menus, triggers, event); + }); + }); +})(); diff --git a/static/js/index.ts b/static/js/index.ts index 52cc678..e00907b 100644 --- a/static/js/index.ts +++ b/static/js/index.ts @@ -1,6 +1,7 @@ import "./pager.ts"; import "./plumber.ts"; import "./instantpage.ts"; +import "./contextmenu.ts"; import "./fixedsearch.ts"; import "./timeago.ts"; -- cgit v1.2.3