{"version":3,"file":"ModalAutoTrigger.js","names":["ModalAutoTrigger","a","setters","Component","default","deepMerge","cookie","Event","execute","constructor","element","options","arguments","length","modalOptions","cssPath","classNames","container","disableModal","cookieID","cookieExpireInDays","disableParamsList","displayDelay","displayDelayBeforeScrollTreshold","setCookieOnModalOpen","disableModalIfCookieExists","_scrollable","reloadEvents","initState","state","lastScrollTop","isShown","bindEvents","forEach","event","on","onReloadModal","afterInit","getModalDisabled","window","scrollY","document","documentElement","scrollTop","setTimeout","showModal","onScroll","handleDisplay","getCookie","url","URL","location","some","param","search","indexOf","scrollHeight","isScrollDown","contentUrl","content","afterClose","bind","beforeOpen","setCookie","emit","reload","destroy","removeListener"],"sources":["components/global/ModalAutoTrigger.js"],"sourcesContent":["import Component from 'core/Component';\nimport { deepMerge } from 'toolbox/deepMerge';\nimport { cookie } from 'toolbox/cookie';\nimport { Event } from 'services/EventEmitter';\n\n/**\n * This is a description of the GeoRedirect constructor function.\n * @class\n * @classdesc This is a description of the GeoRedirect class\n * @extends Component\n */\nexport default class ModalAutoTrigger extends Component {\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 modalOptions: {\n cssPath: null,\n classNames: {\n container: [],\n },\n },\n disableModal: false,\n cookieID: null,\n cookieExpireInDays: 365,\n disableParamsList: null,\n displayDelay: 0, // display delay by {displayDelay} ms\n displayDelayBeforeScrollTreshold: 0, // scroll treshold to display the modal\n setCookieOnModalOpen: false, // the need to set cookie on opening the modal\n disableModalIfCookieExists: false, // the need to disable modal if cookie exists\n _scrollable: true,\n reloadEvents: [],\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.lastScrollTop = 0;\n this.state.isShown = false;\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 anonymous function\n */\n bindEvents() {\n (this.options.reloadEvents || []).forEach((event) => {\n Event.on(event, this.onReloadModal, this);\n });\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n const disableModal = this.getModalDisabled();\n\n this.state.lastScrollTop = window.scrollY || document.documentElement.scrollTop;\n\n if (!disableModal) {\n const { displayDelay, displayDelayBeforeScrollTreshold } = this.options;\n\n if (displayDelay) {\n setTimeout(() => this.showModal(), displayDelay);\n } else if (!displayDelayBeforeScrollTreshold) {\n this.showModal();\n }\n }\n }\n\n /**\n * Handlers to onscroll event\n */\n onScroll() {\n const { displayDelay, displayDelayBeforeScrollTreshold } = this.options;\n\n if (!this.state.isShown && !displayDelay && displayDelayBeforeScrollTreshold && !this.getModalDisabled()) {\n this.handleDisplay();\n }\n }\n\n /**\n * Get modal disabled\n * @returns {Boolean} the modal disabled\n */\n getModalDisabled() {\n if (this.options.disableModal\n || (this.options.disableModalIfCookieExists && this.options.cookieID && cookie.getCookie(this.options.cookieID))) {\n return true;\n }\n\n let disableModal = false;\n\n if (this.options.disableParamsList) {\n const url = (new URL(document.location));\n disableModal = this.options.disableParamsList.some(param => url.search.indexOf(param) > -1);\n }\n return disableModal;\n }\n\n /**\n * Show/Hide toaster based on scroll direction\n */\n handleDisplay() {\n const scrollTop = window.scrollY || document.documentElement.scrollTop;\n const scrollHeight = scrollTop - this.state.lastScrollTop;\n const isScrollDown = scrollTop > this.state.lastScrollTop;\n\n if (isScrollDown) {\n if (scrollHeight >= this.options.displayDelayBeforeScrollTreshold) {\n this.showModal();\n }\n } else {\n this.state.lastScrollTop = scrollTop <= 0 ? 0 : scrollTop; // For Mobile or negative scrolling\n }\n }\n\n /**\n * Show modal, if customer's locale is different from current one\n */\n showModal() {\n if (this.options.modalOptions && (this.options.modalOptions.contentUrl || this.options.modalOptions.content)) {\n const options = this.options.modalOptions;\n options.afterClose = this.afterClose.bind(this);\n this.state.isShown = true;\n\n if (this.options.setCookieOnModalOpen && this.options.cookieID && !cookie.getCookie(this.options.cookieID)) {\n options.beforeOpen = () => {\n cookie.setCookie(this.options.cookieID, true, this.options.cookieExpireInDays);\n };\n }\n\n Event.emit('modal.open', { options });\n }\n }\n\n /**\n * Reload component\n */\n onReloadModal() {\n this.reload();\n }\n\n /**\n * Modal afterClose() function\n */\n afterClose() {\n if (this.options.cookieID && !cookie.getCookie(this.options.cookieID)) {\n cookie.setCookie(this.options.cookieID, true, this.options.cookieExpireInDays);\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.options.reloadEvents || []).forEach((event) => {\n Event.removeListener(event, this.onReloadModal, this);\n });\n }\n}\n"],"mappings":"kJAWqBA,CAAgB,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAX9BE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAS,CAAAJ,CAAA,CAATI,SAAS,WAAAJ,CAAA,EACTK,CAAM,CAAAL,CAAA,CAANK,MAAM,WAAAL,CAAA,EACNM,CAAK,CAAAN,CAAA,CAALM,KAAK,GAAAC,OAAA,SAAAA,CAAA,EAAAP,CAAA,WAQOD,CAAgB,CAAtB,aAA+B,CAAAG,CAAU,CAMpDM,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,MAAA,WAAAD,SAAA,IAAAA,SAAA,IAAG,CAAC,CAAC,CAC7B,KAAK,CAACF,CAAO,CAAEL,CAAS,CAAC,CACrBS,YAAY,CAAE,CACVC,OAAO,CAAE,IAAI,CACbC,UAAU,CAAE,CACRC,SAAS,CAAE,EACf,CACJ,CAAC,CACDC,YAAY,GAAO,CACnBC,QAAQ,CAAE,IAAI,CACdC,kBAAkB,CAAE,GAAG,CACvBC,iBAAiB,CAAE,IAAI,CACvBC,YAAY,CAAE,CAAC,CACfC,gCAAgC,CAAE,CAAC,CACnCC,oBAAoB,GAAO,CAC3BC,0BAA0B,GAAO,CACjCC,WAAW,G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