joomla-ui-custom-elements
Version:
Joomla UI components as custom elements
2 lines (1 loc) • 4.2 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){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,r(o.key),o)}}function r(e){var r=function(e,r){if("object"!=t(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,r||"default");if("object"!=t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==t(r)?r:r+""}function n(e,r,n){return r=c(r),function(e,r){if(r&&("object"==t(r)||"function"==typeof r))return r;if(void 0!==r)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,i()?Reflect.construct(r,n||[],c(e).constructor):r.apply(e,n))}function o(t){var e="function"==typeof Map?new Map:void 0;return o=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,r)}function r(){return function(t,e,r){if(i())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&u(o,r.prototype),o}(t,arguments,c(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)},o(t)}function i(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(i=function(){return!!t})()}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}var a=function(){function t(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),n(this,t,arguments)}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&&u(t,e)}(t,o(HTMLElement)),r=t,c=[{key:"observedAttributes",get:function(){return["for"]}}],(i=[{key:"for",get:function(){return this.getAttribute("for")},set:function(t){this.setAttribute("for",t)}},{key:"connectedCallback",value:function(){var t=this;this.setAttribute("aria-labelledby",this.for.substring(1));var e=document.querySelector(this.for),r=this.querySelectorAll("a");e.id&&(e.setAttribute("aria-haspopup",!0),e.setAttribute("aria-expanded",!1),e.addEventListener("click",(function(n){t.hasAttribute("expanded")?(t.removeAttribute("expanded"),n.target.setAttribute("aria-expanded",!1)):(t.setAttribute("expanded",""),n.target.setAttribute("aria-expanded",!0)),document.addEventListener("click",(function(r){r.target!==e&&(t.findAncestor(r.target,"joomla-dropdown")||t.close())})),r.forEach((function(e){e.addEventListener("click",(function(){t.close()}))}))})))}},{key:"dispatchCustomEvent",value:function(t){var e=new CustomEvent(t);e.relatedTarget=this,this.dispatchEvent(e),this.removeEventListener(t,this)}},{key:"adoptedCallback",value:function(t,e){}},{key:"attributeChangedCallback",value:function(t,e,r){}},{key:"close",value:function(){var t=document.querySelector("#".concat(this.getAttribute("aria-labelledby")));this.removeAttribute("expanded"),t.setAttribute("aria-expanded",!1)}},{key:"findAncestor",value:function(t,e){for(;(t=t.parentElement)&&t.nodeName.toLowerCase()!==e;);return t}}])&&e(r.prototype,i),c&&e(r,c),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,i,c}();customElements.define("joomla-dropdown",a);