Files

2 lines
896 B
JavaScript
Raw Permalink Normal View History

2025-07-02 09:33:52 -07:00
(function(t,e){typeof exports=="object"&&typeof module<"u"?module.exports=e(require("@hotwired/stimulus")):typeof define=="function"&&define.amd?define(["@hotwired/stimulus"],e):(t=typeof globalThis<"u"?globalThis:t||self,t.StimulusPopover=e(t.Stimulus))})(this,function(t){"use strict";class e extends t.Controller{async show(r){const s=r.currentTarget;let n=null;if(this.hasContentTarget?n=this.contentTarget.innerHTML:n=await this.fetch(),!n)return;const o=document.createRange().createContextualFragment(n);s.appendChild(o)}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 r=await fetch(this.urlValue);this.remoteContent=await r.text()}return this.remoteContent}}return e.targets=["card","content"],e.values={url:String},e});