{"version":3,"file":"Hero.js","names":["Hero","a","setters","PromotionTile","default","deepMerge","execute","constructor","element","options","arguments","length","overlapOnScroll","_resizable","initCache","classes","stick","selectors","heroOverlay","querySelector","heroMedia","videoControl","heroCaption","afterInit","updateObserverThreshold","moveVideoControl","onResize","observer","unobserve","disconnect","heroHeight","getBoundingClientRect","height","th","window","innerHeight","heightRatio","threshold","Math","floor","IntersectionObserver","onIntersection","bind","observe","entries","forEach","entry","boundingClientRect","top","unstick","state","isSticky","elementWidth","offsetWidth","elementHeight","offsetHeight","style","width","classList","add","remove","insertBefore","destroy"],"sources":["components/global/Hero.js"],"sourcesContent":["import PromotionTile from 'components/global/PromotionTile';\nimport { deepMerge } from 'toolbox/deepMerge';\n\n/**\n * This is a description of the Hero constructor function.\n * @class\n * @classdesc Represents Hero component with different media (images, video) and content text\n * @extends Component\n */\nexport default class Hero extends PromotionTile {\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 overlapOnScroll: false,\n _resizable: 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 super.initCache();\n\n this.classes = {\n stick: 'm-sticky-image',\n };\n if (this.options.overlapOnScroll) {\n this.selectors.heroOverlay = this.element.querySelector('[data-js-hero-placeholder]');\n this.selectors.heroMedia = this.element.querySelector('[data-js-hero-media]');\n this.selectors.videoControl = this.element.querySelector('[data-js-video-control]');\n this.selectors.heroCaption = this.element.querySelector('[data-js-hero-caption]');\n }\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n super.afterInit();\n\n if (this.options.overlapOnScroll) {\n this.updateObserverThreshold();\n\n if (this.selectors.videoControl && this.selectors.heroCaption) {\n this.moveVideoControl();\n }\n }\n }\n\n /**\n * Update popper position when window is resized\n */\n onResize() {\n if (this.options.overlapOnScroll) {\n this.updateObserverThreshold();\n }\n }\n\n /**\n * Update Observer Threshold value\n */\n updateObserverThreshold() {\n if (this.observer) {\n this.observer.unobserve(this.element);\n this.observer.disconnect();\n }\n\n const heroHeight = this.element.getBoundingClientRect().height;\n let th = 1;\n\n // When the component height is close to or bigger than the screen height,\n // observer, due to its async nature, requires more points to catch the intersection\n // during the fast scrolling and work smooth during the slow scrolling\n if (heroHeight / window.innerHeight > 0.7) {\n const heightRatio = window.innerHeight / heroHeight;\n const threshold = heightRatio > 1 ? 1 : Math.floor(heightRatio * 100) / 100;\n th = [threshold - 0.1, threshold - 0.05, threshold - 0.01, threshold];\n }\n\n this.observer = new window.IntersectionObserver(this.onIntersection.bind(this), {\n threshold: th,\n });\n this.observer.observe(this.element);\n }\n\n /**\n * Intersection event handler\n * @param {Object} entries - Entries object\n */\n onIntersection(entries) {\n entries.forEach((entry) => {\n if (entry.boundingClientRect.top >= 0) {\n this.unstick();\n } else {\n this.stick();\n }\n });\n }\n\n /**\n * Move the tile media to the sticky state\n */\n stick() {\n if (this.state.isSticky) {\n return;\n }\n\n const elementWidth = this.selectors.heroMedia.offsetWidth;\n const elementHeight = this.selectors.heroMedia.offsetHeight;\n\n this.selectors.heroMedia.style.width = `${elementWidth}px`;\n\n this.element.classList.add(this.classes.stick);\n this.selectors.heroOverlay.style.width = `${elementWidth}px`;\n this.selectors.heroOverlay.style.height = `${elementHeight}px`;\n\n this.state.isSticky = true;\n }\n\n /**\n * Move the tile media to the static state\n */\n unstick() {\n if (!this.state.isSticky) {\n return;\n }\n\n this.selectors.heroOverlay.style.width = null;\n this.selectors.heroOverlay.style.height = null;\n this.element.classList.remove(this.classes.stick);\n\n this.selectors.heroMedia.style.width = null;\n\n this.state.isSticky = false;\n }\n\n /**\n * Change the video control placement if overlapOnScroll enabled since it should be always visible for a user\n */\n moveVideoControl() {\n this.element.insertBefore(this.selectors.videoControl, this.selectors.heroCaption);\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 super.destroy();\n\n if (this.options.overlapOnScroll) {\n this.unstick();\n this.observer.unobserve(this.element);\n this.observer.disconnect();\n }\n }\n}\n"],"mappings":"sHASqBA,CAAI,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EATlBE,CAAa,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACXI,CAAS,CAAAJ,CAAA,CAATI,SAAS,GAAAC,OAAA,SAAAA,CAAA,EAAAL,CAAA,WAQGD,CAAI,CAAV,aAAmB,CAAAG,CAAc,CAM5CI,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAEH,CAAS,CAAC,CACrBO,eAAe,GAAO,CACtBC,UAAU,GACd,CAAC,CAAEJ,CAAO,CAAC,CACf,CAKAK,SAASA,CAAA,CAAG,CACR,KAAK,CAACA,SAAS,CAAC,CAAC,CAEjB,IAAI,CAACC,OAAO,CAAG,CACXC,KAAK,CAAE,gBACX,CAAC,CACG,IAAI,CAACP,OAAO,CAACG,eAAe,GAC5B,IAAI,CAACK,SAAS,CAACC,WAAW,CAAG,IAAI,CAACV,OAAO,CAACW,aAAa,CAAC,4BAA4B,CAAC,CACrF,IAAI,CAACF,SAAS,CAACG,SAAS,CAAG,IAAI,CAACZ,OAAO,CAACW,aAAa,CAAC,sBAAsB,CAAC,CAC7E,IAAI,CAACF,SAAS,CAACI,YAAY,CAAG,IAAI,CAACb,OAAO,CAACW,aAAa,CAAC,yBAAyB,CAAC,CACnF,IAAI,CAACF,SAAS,CAACK,WAAW,CAAG,IAAI,CAACd,OAAO,CAACW,aAAa,CAAC,wBAAwB,CAAC,CAEzF,CAMAI,SAASA,CAAA,CAAG,CACR,KAAK,CAACA,SAAS,CAAC,CAAC,CAEb,IAAI,CAACd,OAAO,CAACG,eAAe,GAC5B,IAAI,CAACY,uBAA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