Files
yearly-plan/node_modules/stimulus-popover/dist/stimulus-popover.mjs
0x8664b2 e28f2e0c51 updates
2025-07-02 09:33:52 -07:00

33 lines
832 B
JavaScript

import { Controller as o } from "@hotwired/stimulus";
class r extends o {
async show(e) {
const n = e.currentTarget;
let t = null;
if (this.hasContentTarget ? t = this.contentTarget.innerHTML : t = await this.fetch(), !t)
return;
const a = document.createRange().createContextualFragment(t);
n.appendChild(a);
}
hide() {
this.hasCardTarget && this.cardTarget.remove();
}
async fetch() {
if (!this.remoteContent) {
if (!this.hasUrlValue) {
console.error("[stimulus-popover] You need to pass an url to fetch the popover content.");
return;
}
const e = await fetch(this.urlValue);
this.remoteContent = await e.text();
}
return this.remoteContent;
}
}
r.targets = ["card", "content"];
r.values = {
url: String
};
export {
r as default
};