[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/fields/ -> joomla-field-media-es5.min.js (source)

   1  !function(){"use strict";function t(t,e,i,n,r,o,s){try{var a=t[o](s),l=a.value}catch(t){return void i(t)}a.done?e(l):Promise.resolve(l).then(n,r)}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function i(t){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function o(t,e,i){return(o=r()?Reflect.construct:function(t,e,i){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return i&&n(o,i.prototype),o}).apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,s)}function s(){return o(t,arguments,i(this).constructor)}return s.prototype=Object.create(t.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),n(s,t)})(t)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}if(!Joomla)throw new Error("Joomla API is not properly initiated");var l=function(i){var r,o;function s(){var t;return(t=i.call(this)||this).onSelected=t.onSelected.bind(a(t)),t.show=t.show.bind(a(t)),t.clearValue=t.clearValue.bind(a(t)),t.modalClose=t.modalClose.bind(a(t)),t.setValue=t.setValue.bind(a(t)),t.updatePreview=t.updatePreview.bind(a(t)),t.validateValue=t.validateValue.bind(a(t)),t.markValid=t.markValid.bind(a(t)),t.markInvalid=t.markInvalid.bind(a(t)),t}o=i,(r=s).prototype=Object.create(o.prototype),r.prototype.constructor=r,n(r,o);var l,u,c,d=s.prototype;return d.connectedCallback=function(){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(),this.inputElement.removeAttribute("readonly"),this.inputElement.addEventListener("change",this.validateValue)},d.disconnectedCallback=function(){this.button&&this.button.removeEventListener("click",this.show),this.buttonClearEl&&this.buttonClearEl.removeEventListener("click",this.clearValue),this.inputElement&&this.inputElement.removeEventListener("change",this.validateValue)},d.onSelected=function(t){return t.preventDefault(),t.stopPropagation(),this.modalClose(),!1},d.show=function(){this.modalElement.open(),Joomla.selectedMediaFile={},this.buttonSaveSelectedElement.addEventListener("click",this.onSelected)},d.modalClose=function(){var e,i=(e=regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Joomla.getMedia(Joomla.selectedMediaFile,this.inputElement,this);case 3:t.next=8;break;case 5:t.prev=5,t.t0=t.catch(0),Joomla.renderMessages({error:[Joomla.Text._("JLIB_APPLICATION_ERROR_SERVER")]});case 8:Joomla.selectedMediaFile={},Joomla.Modal.getCurrent().close();case 10:case"end":return t.stop()}}),t,this,[[0,5]])})),function(){var i=this,n=arguments;return new Promise((function(r,o){var s=e.apply(i,n);function a(e){t(s,r,o,a,l,"next",e)}function l(e){t(s,r,o,a,l,"throw",e)}a(void 0)}))});return function(){return i.apply(this,arguments)}}(),d.setValue=function(t){this.inputElement.value=t,this.validatedUrl=t,this.updatePreview(),this.inputElement.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("change",{detail:{value:t},bubbles:!0}))},d.validateValue=function(t){var e=this,i=t.target.value;if(this.validatedUrl!==i&&""!==i)if(/^(http(s)?:\/\/).+$/.test(i))try{fetch(i).then((function(t){200===t.status?(e.validatedUrl=i,e.markValid()):(e.validatedUrl=i,e.markInvalid())}))}catch(t){this.validatedUrl=i,this.markInvalid()}else{/^\//.test(i)&&(i=i.substring(1));var n=i.split("#")[0].split("/"),r=n.slice(1);fetch(Joomla.getOptions("system.paths").rootFull+"/"+i).then((function(t){return t.blob()})).then((function(t){if(t.type.includes("image")){var o=new Image;o.src=URL.createObjectURL(t),o.onload=function(){e.inputElement.value=n[0]+"/"+r.join("/")+"#joomlaImage://local-"+n[0]+"/"+r.join("/")+"?width="+o.width+"&height="+o.height,e.validatedUrl=n[0]+"/"+r.join("/")+"#joomlaImage://local-"+n[0]+"/"+r.join("/")+"?width="+o.width+"&height="+o.height,e.markValid()}}else t.type.includes("audio")||t.type.includes("video")||t.type.includes("application/pdf")?(e.inputElement.value=i,e.validatedUrl=i,e.markValid()):(e.validatedUrl=i,e.markInvalid())})).catch((function(){e.setValue(i),e.validatedUrl=i,e.markInvalid()}))}},d.markValid=function(){this.inputElement.removeAttribute("required"),this.inputElement.removeAttribute("pattern"),document.formvalidator&&document.formvalidator.validate(this.inputElement)},d.markInvalid=function(){this.inputElement.setAttribute("required",""),this.inputElement.setAttribute("pattern","/^(http://INVALID/).+$/"),document.formvalidator&&document.formvalidator.validate(this.inputElement)},d.clearValue=function(){this.setValue(""),this.validatedUrl="",this.inputElement.removeAttribute("required"),this.inputElement.removeAttribute("pattern"),document.formvalidator&&document.formvalidator.validate(this.inputElement)},d.updatePreview=function(){var t,e,i=this;if(-1!==["true","static"].indexOf(this.preview)&&"false"!==this.preview&&this.previewElement&&this.preview){var n=this.inputElement.value,r=this.supportedExtensions;if(n){var o;this.buttonClearEl.style.display="",this.previewElement.innerHTML="";var s,a=(e=(t=n).split(/[#]/)).length>1?e[1].split(/[?]/)[0].split(".").pop().trim():t.split(/[#?]/)[0].split(".").pop().trim();r.images.includes(a)&&(o="images"),r.audios.includes(a)&&(o="audios"),r.videos.includes(a)&&(o="videos"),r.documents.includes(a)&&(o="documents");var l={images:function(){r.images.includes(a)&&((s=new Image).src=/http/.test(n)?n:Joomla.getOptions("system.paths").rootFull+n,s.setAttribute("alt",""))},audios:function(){r.audios.includes(a)&&((s=document.createElement("audio")).src=/http/.test(n)?n:Joomla.getOptions("system.paths").rootFull+n,s.setAttribute("controls",""))},videos:function(){if(r.videos.includes(a)){s=document.createElement("video");var t=document.createElement("source");t.src=/http/.test(n)?n:Joomla.getOptions("system.paths").rootFull+n,t.type="video/"+a,s.setAttribute("controls",""),s.setAttribute("width",i.previewWidth),s.setAttribute("height",i.previewHeight),s.appendChild(t)}},documents:function(){r.documents.includes(a)&&((s=document.createElement("object")).data=/http/.test(n)?n:Joomla.getOptions("system.paths").rootFull+n,s.type="application/"+a,s.setAttribute("width",i.previewWidth),s.setAttribute("height",i.previewHeight))}};if(this.givenType&&["images","audios","videos","documents"].includes(this.givenType))l[this.givenType]();else{if(!o||!["images","audios","videos","documents"].includes(o))return;l[o]()}this.previewElement.style.width=this.previewWidth,this.previewElement.appendChild(s)}else this.buttonClearEl.style.display="none",this.previewElement.innerHTML=Joomla.sanitizeHtml('<span class="field-media-preview-icon"></span>')}},l=s,c=[{key:"observedAttributes",get:function(){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"]}}],(u=[{key:"type",get:function(){return this.getAttribute("type")},set:function(t){this.setAttribute("type",t)}},{key:"basePath",get:function(){return this.getAttribute("base-path")},set:function(t){this.setAttribute("base-path",t)}},{key:"rootFolder",get:function(){return this.getAttribute("root-folder")},set:function(t){this.setAttribute("root-folder",t)}},{key:"url",get:function(){return this.getAttribute("url")},set:function(t){this.setAttribute("url",t)}},{key:"modalContainer",get:function(){return this.getAttribute("modal-container")},set:function(t){this.setAttribute("modal-container",t)}},{key:"input",get:function(){return this.getAttribute("input")},set:function(t){this.setAttribute("input",t)}},{key:"buttonSelect",get:function(){return this.getAttribute("button-select")},set:function(t){this.setAttribute("button-select",t)}},{key:"buttonClear",get:function(){return this.getAttribute("button-clear")},set:function(t){this.setAttribute("button-clear",t)}},{key:"buttonSaveSelected",get:function(){return this.getAttribute("button-save-selected")},set:function(t){this.setAttribute("button-save-selected",t)}},{key:"modalWidth",get:function(){return parseInt(this.getAttribute("modal-width"),10)},set:function(t){this.setAttribute("modal-width",t)}},{key:"modalHeight",get:function(){return parseInt(this.getAttribute("modal-height"),10)},set:function(t){this.setAttribute("modal-height",t)}},{key:"previewWidth",get:function(){return parseInt(this.getAttribute("preview-width"),10)},set:function(t){this.setAttribute("preview-width",t)}},{key:"previewHeight",get:function(){return parseInt(this.getAttribute("preview-height"),10)},set:function(t){this.setAttribute("preview-height",t)}},{key:"preview",get:function(){return this.getAttribute("preview")},set:function(t){this.setAttribute("preview",t)}},{key:"previewContainer",get:function(){return this.getAttribute("preview-container")}}])&&e(l.prototype,u),c&&e(l,c),Object.defineProperty(l,"prototype",{writable:!1}),s}(s(HTMLElement));customElements.define("joomla-field-media",l)}();


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer