CoreFiles by mySites.guru
joomla-field-media.min.js1 lines, 5,336 bytes, from Joomla_4.0.0-beta2-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta
md5
040138bce1ef4f6b50569aac1a5a84f8
sha1
73d9dc7fe1073309ba54f0255110cf6905f5a326
sha256
afe73772b92a59cf3682520c3807f8b48c9c189ede038d8524e7614a6356c136
"use strict";((a,b)=>{if(!b)throw new Error("Joomla API is not properly initiated");b.selectedFile={},window.document.addEventListener("onMediaFileSelected",a=>{b.selectedFile=a.detail});const c=(a,c,d)=>{if(!0===a.success){if(!a.data[0].url)b.selectedFile.url=!1;else if(/local-/.test(a.data[0].adapter)){const{rootFull:c}=b.getOptions("system.paths");b.selectedFile.url=a.data[0].url.split(c)[1],b.selectedFile.thumb=!!a.data[0].thumb_path&&a.data[0].thumb_path}else a.data[0].thumb_path&&(b.selectedFile.thumb=a.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;b.selectedFile.url&&(e(c)||"object"==typeof c?!e(c)&&"object"==typeof c&&c.id?window.parent.Joomla.editors.instances[c.id].replaceSelection(`<img loading="lazy" src="${b.selectedFile.url}" alt=""/>`):(c.value=b.selectedFile.url,d.updatePreview()):b.editors.instances[c].replaceSelection(`<img loading="lazy" src="${b.selectedFile.url}" alt=""/>`))}};b.getImage=(a,d,e)=>new Promise((f,g)=>{if(!a||"object"==typeof a&&(!a.path||""===a.path))return b.selectedFile={},void g(new Error("Nothing selected"));const h=`${b.getOptions("system.paths").rootFull}administrator/index.php?option=com_media&format=json`;b.request({url:`${h}&task=api.files&url=true&path=${a.path}&${b.getOptions("csrf.token")}=1&format=json`,method:"GET",perform:!0,headers:{"Content-Type":"application/json"},onSuccess:a=>{const b=JSON.parse(a);f(c(b,d,e))},onError:a=>{g(a)}})});class d 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).then(()=>{b.Modal.getCurrent().close()}).catch(()=>{b.Modal.getCurrent().close(),b.renderMessages({error:[b.Text._("JLIB_APPLICATION_ERROR_SERVER")]})})}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",d)})(customElements,Joomla);

No other release has this exact content. See every version of this file.