2024-12-07 10:41:52 -08:00
|
|
|
class SupportOutfitViewer extends HTMLElement {
|
|
|
|
#internals = this.attachInternals();
|
|
|
|
|
|
|
|
connectedCallback() {
|
|
|
|
this.addEventListener("mouseenter", this.#onMouseEnter, { capture: true });
|
|
|
|
this.addEventListener("mouseleave", this.#onMouseLeave, { capture: true });
|
|
|
|
this.addEventListener("click", this.#onClick);
|
|
|
|
this.#internals.states.add("ready");
|
|
|
|
}
|
|
|
|
|
|
|
|
// When a row is hovered, highlight its corresponding outfit viewer layer.
|
|
|
|
#onMouseEnter(e) {
|
|
|
|
if (!e.target.matches("tr")) return;
|
|
|
|
|
|
|
|
const id = e.target.querySelector("[data-field=id]").innerText;
|
2024-12-07 11:39:37 -08:00
|
|
|
const layers = this.querySelectorAll(
|
2024-12-07 10:41:52 -08:00
|
|
|
`outfit-viewer [data-asset-id="${CSS.escape(id)}"]`,
|
|
|
|
);
|
2024-12-07 11:39:37 -08:00
|
|
|
for (const layer of layers) {
|
|
|
|
layer.setAttribute("highlighted", "");
|
|
|
|
}
|
2024-12-07 10:41:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// When a row is unhovered, unhighlight its corresponding outfit viewer layer.
|
|
|
|
#onMouseLeave(e) {
|
|
|
|
if (!e.target.matches("tr")) return;
|
|
|
|
|
|
|
|
const id = e.target.querySelector("[data-field=id]").innerText;
|
2024-12-07 11:39:37 -08:00
|
|
|
const layers = this.querySelectorAll(
|
2024-12-07 10:41:52 -08:00
|
|
|
`outfit-viewer [data-asset-id="${CSS.escape(id)}"]`,
|
|
|
|
);
|
2024-12-07 11:39:37 -08:00
|
|
|
for (const layer of layers) {
|
|
|
|
layer.removeAttribute("highlighted");
|
|
|
|
}
|
2024-12-07 10:41:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// When clicking a row, redirect the click to the first link.
|
|
|
|
#onClick(e) {
|
|
|
|
const row = e.target.closest("tr");
|
|
|
|
if (row == null) return;
|
|
|
|
|
|
|
|
row.querySelector("[data-field=links] a").click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("support-outfit-viewer", SupportOutfitViewer);
|