{"version":3,"file":"StickyBar.js","names":["StickyBar","a","setters","Component","default","on","off","deepMerge","Event","execute","constructor","element","options","arguments","length","classNames","active","top","bottom","hidden","eventNamePrefix","stickTo","_resizable","_scrollable","initCache","selectors","bar","querySelector","initState","state","isSticky","updateSticky","unstick","classList","remove","stick","add","relativeScroll","getBoundingClientRect","stickPoint","toggleStickyClass","setHeight","resetHeight","getStickyPoint","window","innerHeight","style","height","offsetHeight","onResize","onScroll","onShow","onHide","bindEvents","bind","destroy","removeListener"],"sources":["components/global/StickyBar.js"],"sourcesContent":["import Component from 'core/Component';\nimport { on, off } from 'toolbox/event';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport { Event } from 'services/EventEmitter';\n\n/**\n * This is a description of the StickyBar constructor function.\n * @class\n * @classdesc This component represents bar that could be sticked to the edge of the viewport.\n * This component work as extensible or as fallback variant for native CSS position: sticky.\n * @extends Component\n */\nexport default class StickyBar extends Component {\n /**\n * @typedef {Object} optionsObject\n * @property {object} classNames - CSS classes applied to the component\n * @property {string} classNames.active - CSS classes applied active state\n * @property {string} classNames.top - CSS classes applied to positioned top\n * @property {string} classNames.bottom - CSS classes applied to positioned bottom\n * @property {string} stickTo - what side of viewport will host panel. [top|bottom]\n * @property {bool} resizable - source file of resource\n */\n /**\n * @constructor\n * @param {object} element - DOM node of component\n * @param {optionsObject} options - Options\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n classNames: {\n active: 'm-sticked',\n top: 'm-top',\n bottom: 'm-bottom',\n hidden: 'h-hidden',\n },\n eventNamePrefix: null, // sticky bar identificator\n stickTo: 'bottom',\n _resizable: true,\n _scrollable: true,\n }, options));\n }\n\n /**\n * All selectors must be cached. Never cache elements that are out of the component scope\n */\n initCache() {\n this.selectors.bar = this.element.querySelector('[data-js-stickybar]');\n }\n\n /**\n * Init the different state of the component\n * It helps to avoid heavy DOM manipulation\n */\n initState() {\n this.state.isSticky = false;\n this.updateSticky();\n }\n\n /**\n * Move panel to stale state\n *\n * @returns {Boolean} - true or false\n */\n unstick() {\n if (!this.state.isSticky) {\n return false;\n }\n this.selectors.bar.classList.remove(this.options.classNames.active);\n this.state.isSticky = false;\n\n return true;\n }\n\n /**\n * Move panel to stick state\n *\n * @returns {Boolean} - true or false\n */\n stick() {\n if (this.state.isSticky) {\n return false;\n }\n this.selectors.bar.classList.add(this.options.classNames.active);\n this.state.isSticky = true;\n\n return true;\n }\n\n /**\n * Check if panel should be in sticky state\n * @return {Boolean} isSticky\n */\n isSticky() {\n const relativeScroll = this.element.getBoundingClientRect()[this.options.stickTo] - this.stickPoint;\n return this.options.stickTo === 'bottom' ? relativeScroll > 0 : relativeScroll < 0;\n }\n\n /**\n * Toggle sticky state between stale, sticky and vica versa\n */\n toggleStickyClass() {\n if (this.isSticky()) {\n this.setHeight();\n this.stick();\n } else {\n this.unstick();\n this.resetHeight();\n }\n }\n\n /**\n * Get point on viewport on what panel should be sticky\n */\n getStickyPoint() {\n this.stickPoint = this.options.stickTo === 'bottom' ? window.innerHeight : 0;\n }\n\n /**\n * Set height and initial CSS-classes to the holder that reserve space for stale state\n */\n setHeight() {\n this.selectors.bar.classList.add(this.options.classNames[this.options.stickTo]);\n this.element.style.height = `${this.selectors.bar.offsetHeight}px`;\n }\n\n /**\n * Destroy height and initial CSS-classes in case when component deinited\n */\n resetHeight() {\n this.selectors.bar.classList.remove(this.options.classNames[this.options.stickTo], this.options.classNames.active);\n this.element.style.height = 'initial';\n }\n\n /**\n * Initialize component DOM structure sizes and classes\n */\n updateSticky() {\n this.setHeight();\n this.getStickyPoint();\n this.toggleStickyClass();\n }\n\n /**\n * Handlers to onresize event\n */\n onResize() {\n this.updateSticky();\n }\n\n /**\n * Handlers to onscroll event\n */\n onScroll() {\n this.toggleStickyClass();\n }\n\n /**\n * Handler to 'stickybar.show' event\n */\n onShow() {\n this.element.classList.remove(this.options.classNames.hidden);\n this.toggleStickyClass();\n }\n\n /**\n * Handler to 'stickybar.hide' event\n */\n onHide() {\n this.element.classList.add(this.options.classNames.hidden);\n this.toggleStickyClass();\n }\n\n /**\n * Should contain only event listeners and nothing else\n * All the event handlers should be into a separated function. No usage of anonyous function\n */\n bindEvents() {\n on('stickybar.show', this.element, this.onShow.bind(this));\n on('stickybar.hide', this.element, this.onHide.bind(this));\n\n if (this.options.eventNamePrefix) {\n Event.on(`${this.options.eventNamePrefix}.stickybar.show`, this.onShow, this);\n Event.on(`${this.options.eventNamePrefix}.stickybar.hide`, this.onHide, this);\n }\n }\n\n /**\n * Destroy is called automatically after the component is being removed from the DOM\n * You must always destroy the listeners attached to an element to avoid any memory leaks\n */\n destroy() {\n this.resetHeight();\n off(this.element);\n\n if (this.options.eventNamePrefix) {\n Event.removeListener(`${this.options.eventNamePrefix}.stickybar.show`, this.onShow, this);\n Event.removeListener(`${this.options.eventNamePrefix}.stickybar.hide`, this.onHide, this);\n }\n }\n}\n"],"mappings":"mJAYqBA,CAAS,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAZvBE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAE,CAAAJ,CAAA,CAAFI,EAAE,CAAEC,CAAG,CAAAL,CAAA,CAAHK,GAAG,WAAAL,CAAA,EACPM,CAAS,CAAAN,CAAA,CAATM,SAAS,WAAAN,CAAA,EACTO,CAAK,CAAAP,CAAA,CAALO,KAAK,GAAAC,OAAA,SAAAA,CAAA,EAAAR,CAAA,WASOD,CAAS,CAAf,aAAwB,CAAAG,CAAU,CAe7CO,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAEJ,CAAS,CAAC,CACrBQ,UAAU,CAAE,CACRC,MAAM,CAAE,WAAW,CACnBC,GAAG,CAAE,OAAO,CACZC,MAAM,CAAE,UAAU,CAClBC,MAAM,CAAE,UACZ,CAAC,CACDC,eAAe,CAAE,IAAI,C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