updates
This commit is contained in:
1 parent
028dea3cb8
commit
e28f2e0c51
17 files changed
+372
-6
No files matched your search
+32
@@ -0,0 +1,32 @@
|
||||
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
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
(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});
|
||||
Reference in new issue
Block a user