CoreFiles by mySites.guru
joomla-field-media.min.js1 lines, 5,088 bytes, from Joomla_4.0.0-alpha10-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha9
md5
8e4ccbaebbffcbc434f97814e79c363d
sha1
acd700eb146b0e22763b3afedba1546cb1b5741a
sha256
e1e278f8b859d34aa13b37b5fbf2212490815cad41a0d2f5a5b6099c02382603
"use strict";(a=>{if(!a)throw new Error("Joomla API is not properly initiated");a.selectedFile={},window.document.addEventListener("onMediaFileSelected",b=>{a.selectedFile=b.detail}),a.doIt=(b,c,d)=>{if(!0===b.success){if(!b.data[0].url)a.selectedFile.url=!1;else if(/local-/.test(b.data[0].adapter)){const{rootFull:c}=a.getOptions("system.paths");a.selectedFile.url=b.data[0].url.split(c)[1],a.selectedFile.thumb=!!b.data[0].thumb_path&&b.data[0].thumb_path}else b.data[0].thumb_path&&(a.selectedFile.thumb=b.data[0].thumb_path);const e=a=>"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName;a.selectedFile.url&&(e(c)||"object"==typeof c?!e(c)&&"object"==typeof c&&c.id?window.parent.Joomla.editors.instances[c.id].replaceSelection(`<img src="${a.selectedFile.url}" alt=""/>`):(c.value=a.selectedFile.url,d.updatePreview()):a.editors.instances[c].replaceSelection(`<img src="${a.selectedFile.url}" alt=""/>`))}},a.getImage=(b,c,d)=>new Promise((e,f)=>{const g=`${a.getOptions("system.paths").rootFull}administrator/index.php?option=com_media&format=json`;a.request({url:`${g}&task=api.files&url=true&path=${b.path}&${a.getOptions("csrf.token")}=1&format=json`,method:"GET",perform:!0,headers:{"Content-Type":"application/json"},onSuccess:b=>{const f=JSON.parse(b);e(a.doIt(f,c,d))},onError:()=>{f()}})})})(Joomla),((a,b)=>{class c extends HTMLElement{constructor(){super(),this.onSelected=this.onSelected.bind(this),this.show=this.show.bind(this),this.clearValue=this.clearValue.bind(this)}static get observedAttributes(){return["type","base-path","root-folder","url","modal-container","modal-width","modal-height","input","button-select","button-clear","button-save-selected","preview","preview-width","preview-height"]}get type(){return this.getAttribute("type")}set type(a){this.setAttribute("type",a)}get basePath(){return this.getAttribute("base-path")}set basePath(a){this.setAttribute("base-path",a)}get rootFolder(){return this.getAttribute("root-folder")}set rootFolder(a){this.setAttribute("root-folder",a)}get url(){return this.getAttribute("url")}set url(a){this.setAttribute("url",a)}get modalContainer(){return this.getAttribute("modal-container")}set modalContainer(a){this.setAttribute("modal-container",a)}get input(){return this.getAttribute("input")}set input(a){this.setAttribute("input",a)}get buttonSelect(){return this.getAttribute("button-select")}set buttonSelect(a){this.setAttribute("button-select",a)}get buttonClear(){return this.getAttribute("button-clear")}set buttonClear(a){this.setAttribute("button-clear",a)}get buttonSaveSelected(){return this.getAttribute("button-save-selected")}set buttonSaveSelected(a){this.setAttribute("button-save-selected",a)}get modalWidth(){return this.getAttribute(parseInt("modal-width",10))}set modalWidth(a){this.setAttribute("modal-width",a)}get modalHeight(){return this.getAttribute(parseInt("modal-height",10))}set modalHeight(a){this.setAttribute("modal-height",a)}get previewWidth(){return this.getAttribute(parseInt("preview-width",10))}set previewWidth(a){this.setAttribute("preview-width",a)}get previewHeight(){return this.getAttribute(parseInt("preview-height",10))}set previewHeight(a){this.setAttribute("preview-height",a)}get preview(){return this.getAttribute("preview")}set preview(a){this.setAttribute("preview",a)}get previewContainer(){return this.getAttribute("preview-container")}connectedCallback(){this.button=this.querySelector(this.buttonSelect),this.buttonClearEl=this.querySelector(this.buttonClear),this.show=this.show.bind(this),this.modalClose=this.modalClose.bind(this),this.clearValue=this.clearValue.bind(this),this.setValue=this.setValue.bind(this),this.updatePreview=this.updatePreview.bind(this),this.button.addEventListener("click",this.show),this.buttonClearEl&&this.buttonClearEl.addEventListener("click",this.clearValue),this.updatePreview()}disconnectedCallback(){this.button&&this.button.removeEventListener("click",this.show),this.buttonClearEl&&this.buttonClearEl.removeEventListener("click",this.clearValue)}onSelected(a){return a.preventDefault(),a.stopPropagation(),this.modalClose(),!1}show(){this.querySelector("[role=\"dialog\"]").open(),this.querySelector(this.buttonSaveSelected).addEventListener("click",this.onSelected)}modalClose(){const a=this.querySelector(this.input);b.getImage(b.selectedFile,a,this),b.Modal.getCurrent().close()}setValue(a){this.querySelector(this.input).value=a,this.updatePreview()}clearValue(){this.setValue("")}updatePreview(){if(-1!==["true","static"].indexOf(this.preview)&&"false"!==this.preview&&this.preview){const a=this.querySelector(this.input),{value:c}=a,d=this.querySelector(".field-media-preview");if(!c)d.innerHTML="<span class=\"field-media-preview-icon\"></span>";else{d.innerHTML="";const a=new Image;switch(this.type){case"image":a.src=/http/.test(c)?c:b.getOptions("system.paths").rootFull+c,a.setAttribute("alt","");break;default:}d.style.width=this.previewWidth,d.appendChild(a)}}}}a.define("joomla-field-media",c)})(customElements,Joomla);

The same content is in 4 releases, Joomla 4.0.0-alpha9 to 4.0.0-alpha12. See them all, or every version of this file.