{"version":3,"file":"Overlay.js","names":["Overlay","a","setters","Component","default","Event","on","animate","deepMerge","execute","constructor","element","options","arguments","length","preventClick","classNames","active","animationEnter","animationLeave","closeTimeout","initState","state","isClosed","isClosing","keepOpened","bindEvents","onClick","bind","open","close","once","onClose","closeCallback","classList","add","emit","contains","remove","then"],"sources":["components/global/Overlay.js"],"sourcesContent":["import Component from 'core/Component';\nimport { Event } from 'services/EventEmitter';\nimport { on } from 'toolbox/event';\nimport { animate } from 'toolbox/animate';\nimport { deepMerge } from 'toolbox/deepMerge';\n\n/**\n * This is a description of the Overlay constructor function.\n * @class\n * @classdesc This is a description of the Overlay class.\n * @extends Component\n */\nexport default class Overlay 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            preventClick: false,\n            classNames: {\n                active: 'm-active',\n                animationEnter: 'h-fade-in',\n                animationLeave: 'h-fade-out',\n            },\n        }, options));\n        this.closeTimeout = null;\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.isClosed = true;\n        this.state.isClosing = false;\n        this.state.keepOpened = false;\n        this.state.preventClick = this.options.preventClick;\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\n        Event.on('overlay.open', this.open, this);\n        Event.on('overlay.close', this.close, this);\n    }\n\n    /**\n     * Click on the overlay would close it.\n     */\n    onClick() {\n        if (this.state.isClosing || this.state.isClosed || this.state.preventClick) {\n            return;\n        }\n\n        this.close();\n    }\n\n    /**\n     * Open overlay\n     *\n     * @param {Object} options - Options that can be passed when opening\n     */\n    open(options = {}) {\n        // It happens that open and close methods are called at the same time.\n        // In this case, we wait the close to happen and open back the overlay.\n        if (this.state.isClosing) {\n            Event.once('overlay.close.after', this.open.bind(this, options), this);\n        }\n\n        // When one component with overlay is calling another component with overlay we don't need to close the overlay\n        // after the second component is closed to avoid the animation glitch.\n        // We still need to trigger the overlay.close.before event on close so that the overlay owner component\n        // can perform onClose actions if the close sequence is initiated by the click on the overlay.\n        this.state.keepOpened = !!options.keepOpened;\n\n        if (!this.state.isClosed) {\n            return;\n        }\n        this.state.preventClick = !!options.preventClick;\n\n        if (typeof options.onClose === 'function') {\n            this.closeCallback = options.onClose;\n        }\n\n        const {\n            active,\n            animationEnter,\n        } = this.options.classNames;\n\n        this.state.isClosed = false;\n        this.element.classList.add(active);\n\n        animate(animationEnter, this.element);\n    }\n\n    /**\n     * Close the modal\n     *\n     * @param {Object} options That belongs to the component\n     */\n    close(options) {\n        if (this.state.isClosed || this.state.isClosing) {\n            return;\n        }\n        if (this.state.keepOpened) {\n            Event.emit('overlay.close.before');\n            this.state.keepOpened = false;\n            return;\n        }\n        this.state.isClosing = true;\n        // reset initial prevenClick value coming from options\n        this.state.preventClick = this.options.preventClick;\n        // in case if open and close methods are called at the same time\n        // we need remove animationEnter class from overlay\n        if (this.element.classList.contains(this.options.classNames.animationEnter)) {\n            this.element.classList.remove(this.options.classNames.animationEnter);\n        }\n        Event.emit('overlay.close.before');\n        animate(this.options.classNames.animationLeave, this.element).then(this.onClose.bind(this, options));\n    }\n\n    /**\n     * onClose handler\n     *\n     * @param {Object} options That belongs to the component\n     */\n    onClose(options) {\n        this.element.classList.remove(this.options.classNames.active);\n\n        if (options && typeof options.onClose === 'function') {\n            options.onClose();\n        }\n\n        if (typeof this.closeCallback === 'function') {\n            this.closeCallback();\n            this.closeCallback = null;\n        }\n\n        this.state.isClosing = false;\n        this.state.isClosed = true;\n        Event.emit('overlay.close.after');\n    }\n}\n"],"mappings":"qKAYqBA,CAAO,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAZrBE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAK,CAAAJ,CAAA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