{"version":3,"file":"BackTop.js","names":["BackTop","a","setters","Component","default","mix","on","off","deepMerge","AnalyticsMixin","execute","with","constructor","element","options","arguments","length","classNames","active","scrollTo","offset","_resizable","_scrollable","initState","state","isActive","setOffsetSize","window","innerHeight","bindEvents","onClick","bind","onKeyPress","onScroll","scrollY","show","hide","sendAnalytics","analytics","scroll","top","event","focusableElement","document","querySelector","indexOf","key","focus","classList","add","remove","destroy","onResize"],"sources":["components/global/BackTop.js"],"sourcesContent":["import Component from 'core/Component';\nimport { mix } from 'core/mixwith';\nimport { on, off } from 'toolbox/event';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport AnalyticsMixin from 'mixins/Analytics';\n\n/**\n * This is a description of the BackTop constructor function.\n * @class\n * @classdesc This is a description of the BackTop class.\n * @extends Component\n */\nexport default class BackTop extends mix(Component).with(AnalyticsMixin) {\n /**\n * Constructor of the class that mainly merge the options of the components\n * @param {HTMLElement} element HTMLElement of the component\n * @param {Object} options options that belongs to the component\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n classNames: {\n active: 'm-active',\n },\n scrollTo: 0, // Y position of the scroll target\n offset: 'auto', // page scroll top position to show the element (in pixels), set 'auto' to take 50% of screen height\n _resizable: true,\n _scrollable: true,\n }, options));\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.isActive = false;\n this.setOffsetSize();\n }\n\n /**\n * Update the offset value.\n */\n setOffsetSize() {\n // if auto, offset is set to half of the page\n // if manual, offset is taken from the default offset options\n this.state.offset = this.options.offset === 'auto' ? window.innerHeight * 0.5 : this.options.offset;\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('click', this.element, this.onClick.bind(this));\n on('keypress', this.element, this.onKeyPress.bind(this));\n }\n\n /**\n * Handlers to onscroll event\n */\n onScroll() {\n if (this.state.offset <= 0) {\n return;\n }\n if (window.scrollY >= this.state.offset) {\n if (!this.state.isActive) {\n this.show();\n }\n } else if (this.state.isActive) {\n this.hide();\n }\n }\n\n /**\n * Click event handler\n */\n onClick() {\n this.sendAnalytics(this.analytics);\n window.scroll({\n top: this.options.scrollTo,\n });\n }\n\n /**\n * KeyPress event handler\n *\n * @param {Object} event Event object\n */\n onKeyPress(event) {\n const focusableElement = document.querySelector('[data-js-skip-to-content]');\n\n if (['Enter', ' '].indexOf(event.key) !== -1) {\n window.scroll({\n top: this.options.scrollTo,\n });\n\n if (focusableElement) {\n focusableElement.focus();\n }\n }\n }\n\n /**\n * Show back to top element\n */\n show() {\n this.element.classList.add(this.options.classNames.active);\n this.state.isActive = true;\n }\n\n /**\n * Hide back to top element\n */\n hide() {\n this.element.classList.remove(this.options.classNames.active);\n this.state.isActive = false;\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 off('click', this.element);\n off('keypress', this.element);\n }\n\n /**\n * Handlers to onresize event\n */\n onResize() {\n if (this.options.offset === 'auto') {\n this.setOffsetSize();\n }\n }\n}\n"],"mappings":"+JAYqBA,CAAO,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAZrBE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAG,CAAAJ,CAAA,CAAHI,GAAG,WAAAJ,CAAA,EACHK,CAAE,CAAAL,CAAA,CAAFK,EAAE,CAAEC,CAAG,CAAAN,CAAA,CAAHM,GAAG,WAAAN,CAAA,EACPO,CAAS,CAAAP,CAAA,CAATO,SAAS,WAAAP,CAAA,EACXQ,CAAc,CAAAR,CAAA,CAAAG,OAAA,GAAAM,OAAA,SAAAA,CAAA,EAAAT,CAAA,WAQAD,CAAO,CAAb,aAAsB,CAAAK,CAAG,CAACF,CAAS,CAAC,CAACQ,IAAI,CAACF,CAAc,CAAE,CAMrEG,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAA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