- md5
- 9082254a8d8124cabee72395c8cd1df4
- sha1
- 9a525892c2ff9a9e664d5dfdf0be5b530145bf7d
- sha256
- ca005f991c4cdd6d48cfea2e1f43123dc95c5d194cbf010eb784f099a30c2ed9
!function(){"use strict";function t(){t=function(){return e};var e={},n=Object.prototype,r=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function l(t,e,n,r){var i=e&&e.prototype instanceof d?e:d,o=Object.create(i.prototype),a=new L(r||[]);return o._invoke=function(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return O()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var u=E(a,n);if(u){if(u===h)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var s=c(t,e,n);if("normal"===s.type){if(r=n.done?"completed":"suspendedYield",s.arg===h)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r="completed",n.method="throw",n.arg=s.arg)}}}(t,n,a),o}function c(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var h={};function d(){}function p(){}function f(){}var v={};s(v,o,(function(){return this}));var m=Object.getPrototypeOf,y=m&&m(m(x([])));y&&y!==n&&r.call(y,o)&&(v=y);var b=f.prototype=d.prototype=Object.create(v);function g(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function n(i,o,a,u){var s=c(t[i],t,o);if("throw"!==s.type){var l=s.arg,h=l.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(h).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,u)}))}u(s.arg)}var i;this._invoke=function(t,r){function o(){return new e((function(e,i){n(t,r,e,i)}))}return i=i?i.then(o,o):o()}}function E(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var r=c(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,h;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function A(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function x(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:O}}function O(){return{value:void 0,done:!0}}return p.prototype=f,s(b,"constructor",f),s(f,"constructor",p),p.displayName=s(f,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,s(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},e.awrap=function(t){return{__await:t}},g(w.prototype),s(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new w(l(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(b),s(b,u,"Generator"),s(b,o,(function(){return this})),s(b,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=x,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(A),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,r){return a.type="throw",a.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var u=r.call(o,"catchLoc"),s=r.call(o,"finallyLoc");if(u&&s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),A(n),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:x(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}function e(t,e,n,r,i,o,a){try{var u=t[o](a),s=u.value}catch(t){return void n(t)}u.done?e(s):Promise.resolve(s).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(i,o){var a=t.apply(n,r);function u(t){e(a,i,o,u,s,"next",t)}function s(t){e(a,i,o,u,s,"throw",t)}u(void 0)}))}}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(){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 u(t,e,n){return u=a()?Reflect.construct.bind():function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&o(i,n.prototype),i},u.apply(null,arguments)}function s(t){var e="function"==typeof Map?new Map:void 0;return s=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;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,r)}function r(){return u(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},s(t)}function l(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 c=function(e){var i,a;function u(){var t;return(t=e.call(this)||this).onSelected=t.onSelected.bind(l(t)),t.show=t.show.bind(l(t)),t.clearValue=t.clearValue.bind(l(t)),t.modalClose=t.modalClose.bind(l(t)),t.setValue=t.setValue.bind(l(t)),t.updatePreview=t.updatePreview.bind(l(t)),t.validateValue=t.validateValue.bind(l(t)),t.markValid=t.markValid.bind(l(t)),t.markInvalid=t.markInvalid.bind(l(t)),t.mimeType="",t}a=e,(i=u).prototype=Object.create(a.prototype),i.prototype.constructor=i,o(i,a);var s,c,h,d=u.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.inputElement.removeAttribute("readonly"),this.inputElement.addEventListener("change",this.validateValue),this.updatePreview()},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=n(t().mark((function e(){return t().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()}}),e,this,[[0,5]])})));return function(){return e.apply(this,arguments)}}(),d.setValue=function(t){this.inputElement.value=t,this.validatedUrl=t,this.mimeType=Joomla.selectedMediaFile.fileType,this.updatePreview(),this.inputElement.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("change",{detail:{value:t},bubbles:!0}))},d.validateValue=function(){var e=n(t().mark((function e(n){var r,i,o,a,u=this;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.target.value,this.validatedUrl!==r&&""!==r){t.next=3;break}return t.abrupt("return");case 3:if(/^(http(s)?:\/\/).+$/.test(r))try{fetch(r).then((function(t){200===t.status?(u.validatedUrl=r,u.markValid()):(u.validatedUrl=r,u.markInvalid())}))}catch(t){this.validatedUrl=r,this.markInvalid()}else/^\//.test(r)&&(r=r.substring(1)),i=r.split("#"),o=i[0].split("/"),a=o.slice(1),fetch(Joomla.getOptions("system.paths").rootFull+"/"+r).then((function(t){return t.blob()})).then((function(t){if(t.type.includes("image")){var e=new Image;e.src=URL.createObjectURL(t),e.onload=function(){u.inputElement.value=o[0]+"/"+a.join("/")+"#joomlaImage://local-"+o[0]+"/"+a.join("/")+"?width="+e.width+"&height="+e.height,u.validatedUrl=o[0]+"/"+a.join("/")+"#joomlaImage://local-"+o[0]+"/"+a.join("/")+"?width="+e.width+"&height="+e.height,u.markValid()}}else t.type.includes("audio")||t.type.includes("video")||t.type.includes("application/pdf")?(u.mimeType=t.type,u.inputElement.value=r,u.validatedUrl=r,u.markValid()):(u.validatedUrl=r,u.markInvalid())})).catch((function(){u.setValue(r),u.validatedUrl=r,u.markInvalid()}));case 4:case"end":return t.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),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,n=this;if(-1!==["true","static"].indexOf(this.preview)&&"false"!==this.preview&&this.previewElement&&this.preview){var r=this.inputElement.value,i=this.supportedExtensions;if(r){var o;this.buttonClearEl.style.display="",this.previewElement.innerHTML="";var a,u=(e=(t=r).split(/[#]/)).length>1?e[1].split(/[?]/)[0].split(".").pop().trim():t.split(/[#?]/)[0].split(".").pop().trim();i.images.includes(u)&&(o="images"),i.audios.includes(u)&&(o="audios"),i.videos.includes(u)&&(o="videos"),i.documents.includes(u)&&(o="documents");var s={images:function(){i.images.includes(u)&&((a=new Image).src=/http/.test(r)?r:Joomla.getOptions("system.paths").rootFull+r,a.setAttribute("alt",""))},audios:function(){i.audios.includes(u)&&((a=document.createElement("audio")).src=/http/.test(r)?r:Joomla.getOptions("system.paths").rootFull+r,a.setAttribute("controls",""))},videos:function(){if(i.videos.includes(u)){a=document.createElement("video");var t=document.createElement("source");t.src=/http/.test(r)?r:Joomla.getOptions("system.paths").rootFull+r,t.type=n.mimeType,a.setAttribute("controls",""),a.setAttribute("width",n.previewWidth),a.setAttribute("height",n.previewHeight),a.appendChild(t)}},documents:function(){i.documents.includes(u)&&((a=document.createElement("object")).data=/http/.test(r)?r:Joomla.getOptions("system.paths").rootFull+r,a.type=n.mimeType,a.setAttribute("width",n.previewWidth),a.setAttribute("height",n.previewHeight))}};if(this.givenType&&["images","audios","videos","documents"].includes(this.givenType))s[this.givenType]();else{if(!o||!["images","audios","videos","documents"].includes(o))return;s[o]()}this.previewElement.style.width=this.previewWidth,this.previewElement.appendChild(a)}else this.buttonClearEl.style.display="none",this.previewElement.innerHTML=Joomla.sanitizeHtml('<span class="field-media-preview-icon"></span>')}},s=u,h=[{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"]}}],(c=[{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")}}])&&r(s.prototype,c),h&&r(s,h),Object.defineProperty(s,"prototype",{writable:!1}),u}(s(HTMLElement));customElements.define("joomla-field-media",c)}();
The same content is in 2 releases, Joomla 4.3.0-alpha1 to 4.3.0-alpha2. See them all, or every version of this file.