UNPKG

@odopod/odo-base-component

Version:

Base component for odo components. Includes media query listeners and exports base globals

3 lines (2 loc) 3.69 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("tiny-emitter")):"function"==typeof define&&define.amd?define(["tiny-emitter"],t):e.OdoBaseComponent=t(e.TinyEmitter)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},i=function(e){function i(n){var o=arguments.length>1&&void 0!==arguments[1]&&arguments[1];t(this,i);var u=r(this,e.call(this));if(!n)throw new TypeError(u.constructor.name+'\'s "element" in the constructor must be element. Got: "'+n+'".');return u.element=n,o&&i.hasMediaQueries&&u._registerMediaQueryListeners(),u}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(i,e),i.prototype._getContext=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.element},i.prototype.getElementByClass=function(e,t){return this._getContext(t).getElementsByClassName(e)[0]||null},i.prototype.getElementsByClass=function(e,t){return Array.from(this._getContext(t).getElementsByClassName(e))},i.prototype.getElementsBySelector=function(e,t){return Array.from(this._getContext(t).querySelectorAll(e))},i.prototype.onMediaQueryChange=function(){},i.prototype.dispose=function(){var e=this;this.element=null,this._onMediaChange&&(Object.keys(i.queries).forEach(function(t){i.queries[t].removeListener(e._onMediaChange)}),this._onMediaChange=null)},i.prototype._registerMediaQueryListeners=function(){var e=this;this._onMediaChange=function(e,t,n){var r,i,o,u,a;function s(){var c=Date.now()-u;c<t&&c>=0?r=setTimeout(s,t-c):(r=null,n||(a=e.apply(o,i),o=i=null))}null==t&&(t=100);var c=function(){o=this,i=arguments,u=Date.now();var c=n&&!r;return r||(r=setTimeout(s,t)),c&&(a=e.apply(o,i),o=i=null),a};return c.clear=function(){r&&(clearTimeout(r),r=null)},c.flush=function(){r&&(a=e.apply(o,i),o=i=null,clearTimeout(r),r=null)},c}(this.onMediaQueryChange.bind(this),50),Object.keys(i.queries).forEach(function(t){i.queries[t].addListener(e._onMediaChange)})},i.matches=function(e){if(i.queries[e])return i.queries[e].matches;throw new Error('Unrecognized breakpoint key: "'+e+'"')},i.getCurrentBreakpoint=function(){return Object.keys(i.queries).find(function(e){return i.queries[e].matches})||null},i._getQueries=function(e){return{xs:matchMedia("(max-width:"+(e[0]-1)+"px)"),sm:matchMedia("(min-width:"+e[0]+"px) and (max-width:"+(e[1]-1)+"px)"),md:matchMedia("(min-width:"+e[1]+"px) and (max-width:"+(e[2]-1)+"px)"),lg:matchMedia("(min-width:"+e[2]+"px)")}},i.defineBreakpoints=function(e){i.BREAKPOINTS=e,i.queries=i._getQueries(e)},n(i,[{key:"breakpoint",get:function(){return i.breakpoint}}],[{key:"breakpoint",get:function(){return{matches:i.matches,get current(){return i.getCurrentBreakpoint()}}}}]),i}(e);return i.defineBreakpoints([768,1024,1392]),i.BREAKPOINT_NAMES=Object.keys(i.queries),i.hasMediaQueries="function"==typeof i.queries.xs.addListener,i}); //# sourceMappingURL=odo-base-component.min.js.map