mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 17:25:32 +00:00
Scroll Button
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
var _ = (i) => {
|
var _ = (i) => {
|
||||||
throw TypeError(i);
|
throw TypeError(i);
|
||||||
};
|
};
|
||||||
var g = (i, r, t) => r.has(i) || _("Cannot " + t);
|
var L = (i, r, t) => r.has(i) || _("Cannot " + t);
|
||||||
var c = (i, r, t) => (g(i, r, "read from private field"), t ? t.call(i) : r.get(i)), l = (i, r, t) => r.has(i) ? _("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(i) : r.set(i, t), o = (i, r, t, e) => (g(i, r, "write to private field"), e ? e.call(i, t) : r.set(i, t), t), d = (i, r, t) => (g(i, r, "access private method"), t);
|
var d = (i, r, t) => (L(i, r, "read from private field"), t ? t.call(i) : r.get(i)), o = (i, r, t) => r.has(i) ? _("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(i) : r.set(i, t), a = (i, r, t, e) => (L(i, r, "write to private field"), e ? e.call(i, t) : r.set(i, t), t), u = (i, r, t) => (L(i, r, "access private method"), t);
|
||||||
const v = "script[xslt-onload]", m = "xslt-template", A = "xslt-transformed", F = "filter-list", f = "filter-list-list", w = "filter-list-item", I = "filter-list-input", E = "filter-list-searchable";
|
const v = "script[xslt-onload]", b = "xslt-template", w = "xslt-transformed", k = "filter-list", f = "filter-list-list", y = "filter-list-item", A = "filter-list-input", m = "filter-list-searchable", F = "scroll-button";
|
||||||
var a, p, b;
|
var l, p, E;
|
||||||
class $ {
|
class H {
|
||||||
constructor() {
|
constructor() {
|
||||||
l(this, p);
|
o(this, p);
|
||||||
l(this, a);
|
o(this, l);
|
||||||
o(this, a, /* @__PURE__ */ new Map());
|
a(this, l, /* @__PURE__ */ new Map());
|
||||||
}
|
}
|
||||||
setup() {
|
setup() {
|
||||||
let r = htmx.findAll(v);
|
let r = htmx.findAll(v);
|
||||||
for (let t of r)
|
for (let t of r)
|
||||||
d(this, p, b).call(this, t);
|
u(this, p, E).call(this, t);
|
||||||
}
|
}
|
||||||
hookupHTMX() {
|
hookupHTMX() {
|
||||||
htmx.on("htmx:load", (r) => {
|
htmx.on("htmx:load", (r) => {
|
||||||
@@ -22,27 +22,27 @@ class $ {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a = new WeakMap(), p = new WeakSet(), b = function(r) {
|
l = new WeakMap(), p = new WeakSet(), E = function(r) {
|
||||||
if (r.getAttribute(A) === "true" || !r.hasAttribute(m))
|
if (r.getAttribute(w) === "true" || !r.hasAttribute(b))
|
||||||
return;
|
return;
|
||||||
let t = "#" + r.getAttribute(m), e = c(this, a).get(t);
|
let t = "#" + r.getAttribute(b), e = d(this, l).get(t);
|
||||||
if (!e) {
|
if (!e) {
|
||||||
let u = htmx.find(t);
|
let c = htmx.find(t);
|
||||||
if (u) {
|
if (c) {
|
||||||
let S = u.innerHTML ? new DOMParser().parseFromString(u.innerHTML, "application/xml") : u.contentDocument;
|
let x = c.innerHTML ? new DOMParser().parseFromString(c.innerHTML, "application/xml") : c.contentDocument;
|
||||||
e = new XSLTProcessor(), e.importStylesheet(S), c(this, a).set(t, e);
|
e = new XSLTProcessor(), e.importStylesheet(x), d(this, l).set(t, e);
|
||||||
} else
|
} else
|
||||||
throw new Error("Unknown XSLT template: " + t);
|
throw new Error("Unknown XSLT template: " + t);
|
||||||
}
|
}
|
||||||
let s = new DOMParser().parseFromString(r.innerHTML, "application/xml"), L = e.transformToFragment(s, document), x = new XMLSerializer().serializeToString(L);
|
let s = new DOMParser().parseFromString(r.innerHTML, "application/xml"), T = e.transformToFragment(s, document), S = new XMLSerializer().serializeToString(T);
|
||||||
r.outerHTML = x;
|
r.outerHTML = S;
|
||||||
};
|
};
|
||||||
var n, h, T;
|
var n, h, g;
|
||||||
class k extends HTMLElement {
|
class I extends HTMLElement {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
l(this, h);
|
o(this, h);
|
||||||
l(this, n, !1);
|
o(this, n, !1);
|
||||||
this._items = [], this._url = "", this._filterstart = !1, this._placeholder = "Liste filtern...", this.render();
|
this._items = [], this._url = "", this._filterstart = !1, this._placeholder = "Liste filtern...", this.render();
|
||||||
}
|
}
|
||||||
static get observedAttributes() {
|
static get observedAttributes() {
|
||||||
@@ -55,7 +55,7 @@ class k extends HTMLElement {
|
|||||||
return this._items;
|
return this._items;
|
||||||
}
|
}
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
this._url = this.getAttribute("data-url") || "./", this._filterstart = this.getAttribute("data-filterstart") === "true", this._placeholder = this.getAttribute("data-placeholder") || "Liste filtern...", this._filterstart && o(this, n, !0), this.addEventListener("input", this.onInput.bind(this)), this.addEventListener("keydown", this.onEnter.bind(this)), this.addEventListener("focusin", this.onGainFocus.bind(this)), this.addEventListener("focusout", this.onLoseFocus.bind(this));
|
this._url = this.getAttribute("data-url") || "./", this._filterstart = this.getAttribute("data-filterstart") === "true", this._placeholder = this.getAttribute("data-placeholder") || "Liste filtern...", this._filterstart && a(this, n, !0), this.addEventListener("input", this.onInput.bind(this)), this.addEventListener("keydown", this.onEnter.bind(this)), this.addEventListener("focusin", this.onGainFocus.bind(this)), this.addEventListener("focusout", this.onLoseFocus.bind(this));
|
||||||
}
|
}
|
||||||
attributeChangedCallback(t, e, s) {
|
attributeChangedCallback(t, e, s) {
|
||||||
t === "data-url" && e !== s && (this._url = s, this.render()), t === "data-filterstart" && e !== s && (this._filterstart = s === "true", this.render()), t === "data-placeholder" && e !== s && (this._placeholder = s, this.render());
|
t === "data-url" && e !== s && (this._url = s, this.render()), t === "data-filterstart" && e !== s && (this._filterstart = s === "true", this.render()), t === "data-placeholder" && e !== s && (this._placeholder = s, this.render());
|
||||||
@@ -64,14 +64,14 @@ class k extends HTMLElement {
|
|||||||
t.target && t.target.tagName.toLowerCase() === "input" && (this._filter = t.target.value, this.renderList());
|
t.target && t.target.tagName.toLowerCase() === "input" && (this._filter = t.target.value, this.renderList());
|
||||||
}
|
}
|
||||||
onGainFocus(t) {
|
onGainFocus(t) {
|
||||||
t.target && t.target.tagName.toLowerCase() === "input" && (o(this, n, !1), this.renderList());
|
t.target && t.target.tagName.toLowerCase() === "input" && (a(this, n, !1), this.renderList());
|
||||||
}
|
}
|
||||||
onLoseFocus(t) {
|
onLoseFocus(t) {
|
||||||
let e = this.querySelector("input");
|
let e = this.querySelector("input");
|
||||||
if (t.target && t.target === e) {
|
if (t.target && t.target === e) {
|
||||||
if (relatedElement = t.relatedTarget, relatedElement && this.contains(relatedElement))
|
if (relatedElement = t.relatedTarget, relatedElement && this.contains(relatedElement))
|
||||||
return;
|
return;
|
||||||
e.value = "", this._filter = "", this._filterstart && o(this, n, !0), this.renderList();
|
e.value = "", this._filter = "", this._filterstart && a(this, n, !0), this.renderList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onEnter(t) {
|
onEnter(t) {
|
||||||
@@ -87,7 +87,7 @@ class k extends HTMLElement {
|
|||||||
let t = this.querySelector("#" + f);
|
let t = this.querySelector("#" + f);
|
||||||
if (!t)
|
if (!t)
|
||||||
return;
|
return;
|
||||||
let e = new Mark(t.querySelectorAll("." + E));
|
let e = new Mark(t.querySelectorAll("." + m));
|
||||||
this._filter && e.mark(this._filter, {
|
this._filter && e.mark(this._filter, {
|
||||||
separateWordSearch: !0
|
separateWordSearch: !0
|
||||||
});
|
});
|
||||||
@@ -124,7 +124,7 @@ class k extends HTMLElement {
|
|||||||
}
|
}
|
||||||
getLinkText(t) {
|
getLinkText(t) {
|
||||||
let e = this.getSearchText(t);
|
let e = this.getSearchText(t);
|
||||||
return e === "" ? "" : `<span class="${E}">${e}</span>`;
|
return e === "" ? "" : `<span class="${m}">${e}</span>`;
|
||||||
}
|
}
|
||||||
renderList() {
|
renderList() {
|
||||||
let t = this.querySelector("#" + f);
|
let t = this.querySelector("#" + f);
|
||||||
@@ -139,7 +139,7 @@ class k extends HTMLElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
ActiveDot(t) {
|
ActiveDot(t) {
|
||||||
return d(this, h, T).call(this, t), "";
|
return u(this, h, g).call(this, t), "";
|
||||||
}
|
}
|
||||||
NoItems(t) {
|
NoItems(t) {
|
||||||
return t.length === 0 ? '<div class="px-2 py-0.5 italic text-gray-500">Keine Einträge gefunden</div>' : "";
|
return t.length === 0 ? '<div class="px-2 py-0.5 italic text-gray-500">Keine Einträge gefunden</div>' : "";
|
||||||
@@ -152,7 +152,7 @@ class k extends HTMLElement {
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="${this._placeholder}"
|
placeholder="${this._placeholder}"
|
||||||
class="${I} w-full placeholder:italic px-2 py-0.5" />
|
class="${A} w-full placeholder:italic px-2 py-0.5" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -164,16 +164,16 @@ class k extends HTMLElement {
|
|||||||
t = this._items.filter((e) => this.getSearchText(e).toLowerCase().startsWith(this._filter.toLowerCase()));
|
t = this._items.filter((e) => this.getSearchText(e).toLowerCase().startsWith(this._filter.toLowerCase()));
|
||||||
else {
|
else {
|
||||||
let e = this._filter.split(" ");
|
let e = this._filter.split(" ");
|
||||||
t = this._items.filter((s) => e.every((L) => this.getSearchText(s).toLowerCase().includes(L.toLowerCase())));
|
t = this._items.filter((s) => e.every((T) => this.getSearchText(s).toLowerCase().includes(T.toLowerCase())));
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
<div id="${f}" class="${f} pt-1 min-h-[19rem] max-h-60 overflow-auto border-b border-zinc-300 bg-stone-50 ${c(this, n) ? "hidden" : ""}">
|
<div id="${f}" class="${f} pt-1 min-h-[19rem] max-h-60 overflow-auto border-b border-zinc-300 bg-stone-50 ${d(this, n) ? "hidden" : ""}">
|
||||||
${t.map(
|
${t.map(
|
||||||
(e, s) => `
|
(e, s) => `
|
||||||
<a
|
<a
|
||||||
href="${this._url}${this.getHREF(e)}"
|
href="${this._url}${this.getHREF(e)}"
|
||||||
class="${w} block px-2.5 py-0.5 hover:bg-slate-200 no-underline ${s % 2 === 0 ? "bg-stone-100" : "bg-stone-50"}"
|
class="${y} block px-2.5 py-0.5 hover:bg-slate-200 no-underline ${s % 2 === 0 ? "bg-stone-100" : "bg-stone-50"}"
|
||||||
${d(this, h, T).call(this, e) ? 'aria-current="page"' : ""}>
|
${u(this, h, g).call(this, e) ? 'aria-current="page"' : ""}>
|
||||||
${this.ActiveDot(e)}
|
${this.ActiveDot(e)}
|
||||||
${this.getLinkText(e)}
|
${this.getLinkText(e)}
|
||||||
</a>
|
</a>
|
||||||
@@ -184,14 +184,52 @@ class k extends HTMLElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = new WeakMap(), h = new WeakSet(), T = function(t) {
|
n = new WeakMap(), h = new WeakSet(), g = function(t) {
|
||||||
if (!t)
|
if (!t)
|
||||||
return !1;
|
return !1;
|
||||||
let e = this.getHREF(t);
|
let e = this.getHREF(t);
|
||||||
return !(e === "" || !window.location.href.endsWith(e));
|
return !(e === "" || !window.location.href.endsWith(e));
|
||||||
};
|
};
|
||||||
customElements.define(F, k);
|
class M extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super(), this.handleScroll = this.handleScroll.bind(this), this.scrollToTop = this.scrollToTop.bind(this);
|
||||||
|
}
|
||||||
|
connectedCallback() {
|
||||||
|
this.innerHTML = `
|
||||||
|
<button
|
||||||
|
class="
|
||||||
|
scroll-to-top
|
||||||
|
fixed bottom-5 right-5
|
||||||
|
hidden
|
||||||
|
bg-gray-800 text-white
|
||||||
|
p-2
|
||||||
|
rounded-md
|
||||||
|
cursor-pointer
|
||||||
|
text-2xl
|
||||||
|
hover:opacity-80
|
||||||
|
transition-opacity
|
||||||
|
border-0
|
||||||
|
"
|
||||||
|
aria-label="Scroll to top"
|
||||||
|
>
|
||||||
|
<i class="ri-arrow-up-double-line"></i>
|
||||||
|
</button>
|
||||||
|
`, this._button = this.querySelector(".scroll-to-top"), window.addEventListener("scroll", this.handleScroll), this._button.addEventListener("click", this.scrollToTop);
|
||||||
|
}
|
||||||
|
disconnectedCallback() {
|
||||||
|
window.removeEventListener("scroll", this.handleScroll), this._button.removeEventListener("click", this.scrollToTop);
|
||||||
|
}
|
||||||
|
handleScroll() {
|
||||||
|
(window.scrollY || document.documentElement.scrollTop) > 300 ? this._button.classList.remove("hidden") : this._button.classList.add("hidden");
|
||||||
|
}
|
||||||
|
scrollToTop() {
|
||||||
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
customElements.define(k, I);
|
||||||
|
customElements.define(F, M);
|
||||||
export {
|
export {
|
||||||
k as FilterList,
|
I as FilterList,
|
||||||
$ as XSLTParseProcess
|
M as ScrollButton,
|
||||||
|
H as XSLTParseProcess
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -45,6 +45,8 @@
|
|||||||
{{ block "_footer" . }}
|
{{ block "_footer" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<scroll-button></scroll-button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,12 +4,15 @@ import "./site.css";
|
|||||||
const ATTR_XSLT_ONLOAD = "script[xslt-onload]";
|
const ATTR_XSLT_ONLOAD = "script[xslt-onload]";
|
||||||
const ATTR_XSLT_TEMPLATE = "xslt-template";
|
const ATTR_XSLT_TEMPLATE = "xslt-template";
|
||||||
const ATTR_XSLT_STATE = "xslt-transformed";
|
const ATTR_XSLT_STATE = "xslt-transformed";
|
||||||
|
|
||||||
const FILTER_LIST_ELEMENT = "filter-list";
|
const FILTER_LIST_ELEMENT = "filter-list";
|
||||||
const FILTER_LIST_LIST = "filter-list-list";
|
const FILTER_LIST_LIST = "filter-list-list";
|
||||||
const FILTER_LIST_ITEM = "filter-list-item";
|
const FILTER_LIST_ITEM = "filter-list-item";
|
||||||
const FILTER_LIST_INPUT = "filter-list-input";
|
const FILTER_LIST_INPUT = "filter-list-input";
|
||||||
const FILTER_LIST_SEARCHABLE = "filter-list-searchable";
|
const FILTER_LIST_SEARCHABLE = "filter-list-searchable";
|
||||||
|
|
||||||
|
const SCROLL_BUTTON_ELEMENT = "scroll-button";
|
||||||
|
|
||||||
class XSLTParseProcess {
|
class XSLTParseProcess {
|
||||||
#processors;
|
#processors;
|
||||||
|
|
||||||
@@ -360,6 +363,69 @@ class FilterList extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define(FILTER_LIST_ELEMENT, FilterList);
|
class ScrollButton extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.handleScroll = this.handleScroll.bind(this);
|
||||||
|
this.scrollToTop = this.scrollToTop.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
export { XSLTParseProcess, FilterList };
|
connectedCallback() {
|
||||||
|
// Insert Tailwind-styled button in light DOM
|
||||||
|
this.innerHTML = `
|
||||||
|
<button
|
||||||
|
class="
|
||||||
|
scroll-to-top
|
||||||
|
fixed bottom-5 right-5
|
||||||
|
hidden
|
||||||
|
bg-gray-800 text-white
|
||||||
|
p-2
|
||||||
|
rounded-md
|
||||||
|
cursor-pointer
|
||||||
|
text-2xl
|
||||||
|
hover:opacity-80
|
||||||
|
transition-opacity
|
||||||
|
border-0
|
||||||
|
"
|
||||||
|
aria-label="Scroll to top"
|
||||||
|
>
|
||||||
|
<i class="ri-arrow-up-double-line"></i>
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
|
||||||
|
this._button = this.querySelector(".scroll-to-top");
|
||||||
|
|
||||||
|
// Listen for scroll events
|
||||||
|
window.addEventListener("scroll", this.handleScroll);
|
||||||
|
|
||||||
|
// Listen for clicks on the button
|
||||||
|
this._button.addEventListener("click", this.scrollToTop);
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectedCallback() {
|
||||||
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
|
this._button.removeEventListener("click", this.scrollToTop);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleScroll() {
|
||||||
|
// Show/hide button based on scroll position
|
||||||
|
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||||
|
if (scrollTop > 300) {
|
||||||
|
// Remove 'hidden' so it becomes visible
|
||||||
|
this._button.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
// Add 'hidden' so it's not displayed
|
||||||
|
this._button.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToTop() {
|
||||||
|
// Smoothly scroll back to top
|
||||||
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define(FILTER_LIST_ELEMENT, FilterList);
|
||||||
|
customElements.define(SCROLL_BUTTON_ELEMENT, ScrollButton);
|
||||||
|
|
||||||
|
export { XSLTParseProcess, FilterList, ScrollButton };
|
||||||
|
|||||||
Reference in New Issue
Block a user