joomla-ui-custom-elements
Version:
Joomla UI components as custom elements
2 lines (1 loc) • 7.96 kB
JavaScript
function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){var o="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!o){if(Array.isArray(t)||(o=function(t,e){if(t){if("string"==typeof t)return n(t,e);var o={}.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?n(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){o&&(t=o);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,u=!0,a=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return u=t.done,t},e:function(t){a=!0,s=t},f:function(){try{u||null==o.return||o.return()}finally{if(a)throw s}}}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,i(o.key),o)}}function i(e){var n=function(e,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,n||"default");if("object"!=t(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==t(n)?n:n+""}function r(e,n,o){return n=l(n),function(e,n){if(n&&("object"==t(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(e)}(e,u()?Reflect.construct(n,o||[],l(e).constructor):n.apply(e,o))}function s(t){var e="function"==typeof Map?new Map:void 0;return s=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;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,n)}function n(){return function(t,e,n){if(u())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var i=new(t.bind.apply(t,o));return n&&a(i,n.prototype),i}(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,t)},s(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}var c=function(){function t(){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),(e=r(this,t)).close=e.close.bind(e),e.destroyCloseButton=e.destroyCloseButton.bind(e),e.createCloseButton=e.createCloseButton.bind(e),e.onMutation=e.onMutation.bind(e),e.observer=new MutationObserver(e.onMutation),e.observer.observe(e,{attributes:!1,childList:!0,subtree:!0}),e.addEventListener("animationend",(function(t){"joomla-alert-fade-in"===t.animationName&&t.target===e&&(e.dispatchEvent(new CustomEvent("joomla.alert.shown")),e.style.removeProperty("animationName"))})),e.addEventListener("animationend",(function(t){"joomla-alert-fade-out"===t.animationName&&t.target===e&&(e.dispatchEvent(new CustomEvent("joomla.alert.closed")),e.remove())})),e}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}(t,s(HTMLElement)),n=t,u=[{key:"observedAttributes",get:function(){return["type","role","dismiss","auto-dismiss","close-text"]}}],(i=[{key:"type",get:function(){return this.getAttribute("type")},set:function(t){this.setAttribute("type",t)}},{key:"role",get:function(){return this.getAttribute("role")},set:function(t){this.setAttribute("role",t)}},{key:"closeText",get:function(){return this.getAttribute("close-text")},set:function(t){this.setAttribute("close-text",t)}},{key:"dismiss",get:function(){return this.getAttribute("dismiss")},set:function(t){this.setAttribute("dismiss",t)}},{key:"autodismiss",get:function(){return this.getAttribute("auto-dismiss")},set:function(t){this.setAttribute("auto-dismiss",t)}},{key:"connectedCallback",value:function(){this.dispatchEvent(new CustomEvent("joomla.alert.show")),this.style.animationName="joomla-alert-fade-in",this.type&&["info","warning","danger","success"].includes(this.type)||this.setAttribute("type","info"),this.role&&["alert","alertdialog"].includes(this.role)||this.setAttribute("role","alert"),this.firstElementChild&&"BUTTON"===this.firstElementChild.tagName&&(this.button=this.firstElementChild,this.button.classList.contains("joomla-alert--close")&&this.button.classList.add("joomla-alert--close"),""===this.button.innerHTML&&(this.button.innerHTML='<span aria-hidden="true">×</span>'),this.button.hasAttribute("aria-label")||this.button.setAttribute("aria-label",this.closeText)),this.hasAttribute("dismiss")&&!this.button&&this.createCloseButton(),this.hasAttribute("auto-dismiss")&&this.autoDismiss()}},{key:"disconnectedCallback",value:function(){this.button&&this.button.removeEventListener("click",this.close),this.observer.disconnect()}},{key:"attributeChangedCallback",value:function(t,e,n){switch(t){case"type":(!n||n&&-1===["info","warning","danger","success"].indexOf(n))&&(this.type="info");break;case"role":(!n||n&&-1===["alert","alertdialog"].indexOf(n))&&(this.role="alert");break;case"dismiss":n&&""!==n||e&&""!==e?this.button&&"false"===n?this.destroyCloseButton():this.button||"false"===n||this.createCloseButton():this.button&&!this.hasAttribute("dismiss")?this.destroyCloseButton():!this.button&&this.hasAttribute("dismiss")&&this.createCloseButton();break;case"close-text":n&&n===e||this.button&&this.button.setAttribute("aria-label",n);break;case"auto-dismiss":this.autoDismiss()}}},{key:"onMutation",value:function(t){var n,o=e(t);try{for(o.s();!(n=o.n()).done;){var i=n.value;"childList"===i.type&&i.addedNodes.length&&this.button&&this.firstElementChild!==this.button&&this.prepend(this.button)}}catch(t){o.e(t)}finally{o.f()}}},{key:"close",value:function(){this.dispatchEvent(new CustomEvent("joomla.alert.close")),this.style.animationName="joomla-alert-fade-out"}},{key:"createCloseButton",value:function(){this.button=document.createElement("button"),this.button.setAttribute("type","button"),this.button.classList.add("joomla-alert--close"),this.button.innerHTML='<span aria-hidden="true">×</span>',this.button.setAttribute("aria-label",this.closeText),this.insertAdjacentElement("afterbegin",this.button),this.button.addEventListener("click",this.close)}},{key:"destroyCloseButton",value:function(){this.button&&(this.button.removeEventListener("click",this.close),this.button.parentNode.removeChild(this.button),this.button=null)}},{key:"autoDismiss",value:function(){var t=parseInt(this.getAttribute("auto-dismiss"),10);setTimeout(this.close,t>=10?t:3e3)}}])&&o(n.prototype,i),u&&o(n,u),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i,u}();customElements.get("joomla-alert")||customElements.define("joomla-alert",c);