- md5
- f3adcf17217d4adf6790f0e74a34c2c9
- sha1
- 55cb1b1dac65efe1140241c76480a3fb9a587ae3
- sha256
- 702f8e670ae7d18041ddd26334aff17fc6439dea243c2021fee86d76cdd6206d
"use strict";((a,b)=>{if(!b)throw new Error("Joomla API is not properly initiated");let c={};window.document.addEventListener("onMediaFileSelected",a=>{c=a.detail});const d=(a,d,e)=>{if(!0===a.success){if(!a.data[0].url)c.url=!1;else if(/local-/.test(a.data[0].adapter)){const{rootFull:d}=b.getOptions("system.paths");c.url=a.data[0].url.split(d)[1],c.thumb=!!a.data[0].thumb_path&&a.data[0].thumb_path}else a.data[0].thumb_path&&(c.thumb=a.data[0].thumb_path);const f=a=>"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName;c.url&&(f(d)||"object"==typeof d?!f(d)&&"object"==typeof d&&d.id?window.parent.Joomla.editors.instances[d.id].replaceSelection(`<img loading="lazy" src="${c.url}" alt=""/>`):(d.value=c.url,e.updatePreview()):b.editors.instances[d].replaceSelection(`<img loading="lazy" src="${c.url}" alt=""/>`))}},e=(a,e,f)=>new Promise((g,h)=>{if(!a||"object"==typeof a&&(!a.path||""===a.path))return c={},void h(new Error("Nothing selected"));const i=`${b.getOptions("system.paths").rootFull}administrator/index.php?option=com_media&format=json`;b.request({url:`${i}&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);g(d(b,e,f))},onError:a=>{h(a)}})});class f 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);e(c,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",f)})(customElements,Joomla);
No other release has this exact content. See every version of this file.