joomla-ui-custom-elements
Version:
Joomla UI components as custom elements
2 lines (1 loc) • 4.76 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 r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function n(e){var n=function(e,n){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.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,r){return n=c(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,o()?Reflect.construct(n,r||[],c(e).constructor):n.apply(e,r))}function i(t){var e="function"==typeof Map?new Map:void 0;return i=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(o())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,e);var i=new(t.bind.apply(t,r));return n&&u(i,n.prototype),i}(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,t)},i(t)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=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 s=function(){function t(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),r(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,i(HTMLElement)),n=t,o=[{key:"type",get:function(){return this.getAttribute("type")},set:function(t){this.setAttribute("type",t)}},{key:"label",get:function(){return this.getAttribute("label")},set:function(t){this.setAttribute("label",t)}},{key:"tip",get:function(){return this.getAttribute("tip")},set:function(t){this.setAttribute("tip",t)}},{key:"position",get:function(){return this.getAttribute("position")},set:function(t){this.setAttribute("position",t)}},{key:"text",get:function(){return this.getAttribute("text")},set:function(t){this.getAttribute("text",t)}},{key:"connectedCallback",value:function(){(!this.position||this.position&&-1===["top","bottom","left","right"].indexOf(this.position))&&(this.position="top"),this.btnElement=document.createElement("button"),this.spanElement=document.createElement("span"),this.btnElement.setAttribute("aria-label",this.label?this.label:"more info"),this.btnElement.innerHTML=this.text?this.text:"",this.spanElement.setAttribute("role","status"),this.btnElement.addEventListener("click",this.showTip.bind(this)),this.append(this.btnElement),this.append(this.spanElement)}},{key:"disconnectedCallback",value:function(){this.querySelector("button").removeEventListener("click",this.showTip,!0)}},{key:"showTip",value:function(){var t=this,e=this;document.addEventListener("click",(function(n){t.btnElement!==n.target&&(t.spanElement.innerHTML="",e.removeEventListener("keydown",t))})),document.addEventListener("keydown",(function(n){9===(n.keyCode||n.which)&&(t.spanElement.innerHTML="",e.removeEventListener("keydown",t))})),this.spanElement.innerHTML='<span class="toggletip-bubble '.concat(this.position,'">').concat(this.tip,"</span>")}},{key:"dispatchCustomEvent",value:function(t){var e=new CustomEvent(t,{bubbles:!0,cancelable:!0});e.relatedTarget=this,this.dispatchEvent(e),this.removeEventListener(t,this)}}],c=[{key:"observedAttributes",get:function(){return["type","label","tip","text","position"]}}],o&&e(n.prototype,o),c&&e(n,c),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,c}();customElements.define("joomla-tip",s);