33 lines
832 B
JavaScript
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
|
||
|
|
};
|