芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/beyondbrightenterprise.com/media/system/js/fields/joomla-field-media.min.js
if(!Joomla)throw new Error("Joomla API is not properly initiated");const getExtension=t=>{const e=t.split(/[#]/);return e.length>1?e[1].split(/[?]/)[0].split(".").pop().trim():t.split(/[#?]/)[0].split(".").pop().trim()};class JoomlaFieldMedia extends HTMLElement{constructor(){super(),this.onSelected=this.onSelected.bind(this),this.show=this.show.bind(this),this.clearValue=this.clearValue.bind(this),this.modalClose=this.modalClose.bind(this),this.setValue=this.setValue.bind(this),this.updatePreview=this.updatePreview.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(t){this.setAttribute("type",t)}get basePath(){return this.getAttribute("base-path")}set basePath(t){this.setAttribute("base-path",t)}get rootFolder(){return this.getAttribute("root-folder")}set rootFolder(t){this.setAttribute("root-folder",t)}get url(){return this.getAttribute("url")}set url(t){this.setAttribute("url",t)}get modalContainer(){return this.getAttribute("modal-container")}set modalContainer(t){this.setAttribute("modal-container",t)}get input(){return this.getAttribute("input")}set input(t){this.setAttribute("input",t)}get buttonSelect(){return this.getAttribute("button-select")}set buttonSelect(t){this.setAttribute("button-select",t)}get buttonClear(){return this.getAttribute("button-clear")}set buttonClear(t){this.setAttribute("button-clear",t)}get buttonSaveSelected(){return this.getAttribute("button-save-selected")}set buttonSaveSelected(t){this.setAttribute("button-save-selected",t)}get modalWidth(){return parseInt(this.getAttribute("modal-width"),10)}set modalWidth(t){this.setAttribute("modal-width",t)}get modalHeight(){return parseInt(this.getAttribute("modal-height"),10)}set modalHeight(t){this.setAttribute("modal-height",t)}get previewWidth(){return parseInt(this.getAttribute("preview-width"),10)}set previewWidth(t){this.setAttribute("preview-width",t)}get previewHeight(){return parseInt(this.getAttribute("preview-height"),10)}set previewHeight(t){this.setAttribute("preview-height",t)}get preview(){return this.getAttribute("preview")}set preview(t){this.setAttribute("preview",t)}get previewContainer(){return this.getAttribute("preview-container")}connectedCallback(){if(this.button=this.querySelector(this.buttonSelect),this.inputElement=this.querySelector(this.input),this.buttonClearEl=this.querySelector(this.buttonClear),this.modalElement=this.querySelector(".joomla-modal"),this.buttonSaveSelectedElement=this.querySelector(this.buttonSaveSelected),this.previewElement=this.querySelector(".field-media-preview"),!(this.button&&this.inputElement&&this.buttonClearEl&&this.modalElement&&this.buttonSaveSelectedElement))throw new Error("Misconfiguaration...");if(this.button.addEventListener("click",this.show),this.modalElement&&window.bootstrap&&window.bootstrap.Modal&&!window.bootstrap.Modal.getInstance(this.modalElement)&&Joomla.initialiseModal(this.modalElement,{isJoomla:!0}),this.buttonClearEl&&this.buttonClearEl.addEventListener("click",this.clearValue),this.supportedExtensions=Joomla.getOptions("media-picker",{}),!Object.keys(this.supportedExtensions).length)throw new Error("Joomla API is not properly initiated");this.updatePreview()}disconnectedCallback(){this.button&&this.button.removeEventListener("click",this.show),this.buttonClearEl&&this.buttonClearEl.removeEventListener("click",this.clearValue)}onSelected(t){return t.preventDefault(),t.stopPropagation(),this.modalClose(),!1}show(){this.modalElement.open(),Joomla.selectedMediaFile={},this.buttonSaveSelectedElement.addEventListener("click",this.onSelected)}async modalClose(){try{await Joomla.getMedia(Joomla.selectedMediaFile,this.inputElement,this)}catch(t){Joomla.renderMessages({error:[Joomla.Text._("JLIB_APPLICATION_ERROR_SERVER")]})}Joomla.selectedMediaFile={},Joomla.Modal.getCurrent().close()}setValue(t){this.inputElement.value=t,this.updatePreview(),this.inputElement.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("change",{detail:{value:t},bubbles:!0}))}clearValue(){this.setValue("")}updatePreview(){if(-1!==["true","static"].indexOf(this.preview)&&"false"!==this.preview&&this.previewElement&&this.preview){const{value:t}=this.inputElement,{supportedExtensions:e}=this;if(t){let i;this.buttonClearEl.style.display="",this.previewElement.innerHTML="";const s=getExtension(t);let o;e.images.includes(s)&&(i="images"),e.audios.includes(s)&&(i="audios"),e.videos.includes(s)&&(i="videos"),e.documents.includes(s)&&(i="documents");const r={images:()=>{e.images.includes(s)&&(o=new Image,o.src=/http/.test(t)?t:Joomla.getOptions("system.paths").rootFull+t,o.setAttribute("alt",""))},audios:()=>{e.audios.includes(s)&&(o=document.createElement("audio"),o.src=/http/.test(t)?t:Joomla.getOptions("system.paths").rootFull+t,o.setAttribute("controls",""))},videos:()=>{if(e.videos.includes(s)){o=document.createElement("video");const e=document.createElement("source");e.src=/http/.test(t)?t:Joomla.getOptions("system.paths").rootFull+t,e.type=`video/${s}`,o.setAttribute("controls",""),o.setAttribute("width",this.previewWidth),o.setAttribute("height",this.previewHeight),o.appendChild(e)}},documents:()=>{e.documents.includes(s)&&(o=document.createElement("object"),o.data=/http/.test(t)?t:Joomla.getOptions("system.paths").rootFull+t,o.type=`application/${s}`,o.setAttribute("width",this.previewWidth),o.setAttribute("height",this.previewHeight))}};if(this.givenType&&["images","audios","videos","documents"].includes(this.givenType))r[this.givenType]();else{if(!i||!["images","audios","videos","documents"].includes(i))return;r[i]()}this.previewElement.style.width=this.previewWidth,this.previewElement.appendChild(o)}else this.buttonClearEl.style.display="none",this.previewElement.innerHTML=Joomla.sanitizeHtml('
')}}}customElements.define("joomla-field-media",JoomlaFieldMedia);