Files

33 lines
832 B
JavaScript
Raw Permalink Normal View History

2025-07-02 09:33:52 -07:00
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
};