{"version":3,"file":"MiniCartIcon.js","names":["MiniCartIcon","a","setters","Component","default","Event","deepMerge","execute","constructor","element","options","arguments","length","reloadData","section","id","skipLazyload","enableAnimation","animationDuration","initCache","classNames","animation","animationTimeout","selectors","button","querySelector","minicart","closest","bindEvents","on","updateIcon","onAddToBagConfirmationClosed","afterInit","updateButtonParams","reload","animate","removeAnimationClass","classList","remove","clearTimeout","add","setTimeout","bind","dataset","jsButtonRole","setAttribute","removeAttribute","destroy","removeListener"],"sources":["components/cart/MiniCartIcon.js"],"sourcesContent":["import Component from 'core/Component';\nimport { Event } from 'services/EventEmitter';\nimport { deepMerge } from 'toolbox/deepMerge';\n\n/**\n * This is a description of the MiniCartIcon constructor function.\n * @class\n * @classdesc This is a description of the MiniCartIcon class.\n * @extends ToolTip\n */\nexport default class MiniCartIcon extends Component {\n /**\n * Constructor of the class that mainly merge the options of the components\n *\n * @param {HTMLElement} element HTMLElement of the component\n * @param {Object} options That belongs to the component\n */\n constructor(element, options = {}) {\n super(element, deepMerge({\n reloadData: {\n section: 'header',\n id: 'minicarticon',\n skipLazyload: true,\n },\n enableAnimation: false,\n animationDuration: 1000,\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.classNames = {\n animation: 'm-animated',\n };\n this.animationTimeout = null;\n this.selectors.button = this.element.querySelector('[data-js-minicart-button]');\n this.selectors.minicart = this.element.closest('[data-component=\"cart/MiniCart\"]');\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 Event.on('cart.product.added', this.updateIcon, this);\n Event.on('cart.updated', this.updateIcon, this);\n Event.on('carticon.update', this.updateIcon, this);\n Event.on('lineitem.updated', this.updateIcon, this);\n Event.on('addtobag.confirmation.closed', this.onAddToBagConfirmationClosed, this);\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n this.updateButtonParams();\n }\n\n /**\n * Cart icon update event handler\n */\n updateIcon() {\n this.reload();\n }\n\n /**\n * Add to Cart confirmation closed event handler\n */\n onAddToBagConfirmationClosed() {\n if (this.options.enableAnimation) {\n this.animate();\n }\n }\n\n /**\n * Remove animation class\n *\n * @param {HTMLElement} element - HTML element\n * @param {Object} classNames - classNames object\n */\n removeAnimationClass(element, classNames) {\n element.classList.remove(classNames.animation);\n }\n\n /**\n * Animates icon\n */\n animate() {\n if (this.animationTimeout) {\n clearTimeout(this.animationTimeout);\n }\n\n this.element.classList.add(this.classNames.animation);\n // eslint-disable-next-line max-len\n this.animationTimeout = setTimeout(this.removeAnimationClass.bind(this, this.element, this.classNames), this.options.animationDuration);\n }\n\n /**\n * Update button attributes based on the click action (redirect to cart or minicart open)\n */\n updateButtonParams() {\n if (this.selectors.minicart && this.selectors.minicart.dataset.jsButtonRole === 'link') {\n this.selectors.button.setAttribute('role', 'link');\n } else {\n this.selectors.button.removeAttribute('role');\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 super.destroy();\n Event.removeListener('cart.product.added', this.updateIcon, this);\n Event.removeListener('cart.updated', this.updateIcon, this);\n Event.removeListener('lineitem.updated', this.updateIcon, this);\n Event.removeListener('carticon.update', this.updateIcon, this);\n Event.removeListener('addtobag.confirmation.closed', this.onAddToBagConfirmationClosed, this);\n }\n}\n"],"mappings":"+HAUqBA,CAAY,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAV1BE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAK,CAAAJ,CAAA,CAALI,KAAK,WAAAJ,CAAA,EACLK,CAAS,CAAAL,CAAA,CAATK,SAAS,GAAAC,OAAA,SAAAA,CAAA,EAAAN,CAAA,WAQGD,CAAY,CAAlB,aAA2B,CAAAG,CAAU,CAOhDK,WAAWA,CAACC,CAAO,CAAgB,IAAd,CAAAC,CAAO,GAAAC,SAAA,CAAAC,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