{"version":3,"file":"BazaarvoiceRatingsSummary.js","names":["BazaarvoiceRatingsSummary","a","setters","Component","default","on","off","Event","execute","bindEvents","element","onClick","bind","once","afterInit","onProductUrlUpdated","emit","event","target","id","category","action","label","analytics","extraData","event_name","product_info","querySelectorAll","forEach","path","fillURL","style","fill","linearGradientID","split","setAttribute","concat","window","location","href","destroy","removeListener"],"sources":["components/product/BazaarvoiceRatingsSummary.js"],"sourcesContent":["import Component from 'core/Component';\nimport { on, off } from 'toolbox/event';\nimport { Event } from 'services/EventEmitter';\n\n/**\n * This is a description of the BazaarvoiceRatingsSummary constructor function.\n * @class\n * @classdesc Component used to emit BazaarVoice events on specific actions.\n * @extends Component\n */\nexport default class BazaarvoiceRatingsSummary extends Component {\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 Event.once('BV.dependency.check', this.afterInit, this);\n Event.on('product.url.updated', this.onProductUrlUpdated, this);\n }\n\n /**\n * After init\n * Run any script after the component is fully initialized\n */\n afterInit() {\n Event.emit('BV.dependency.loaded');\n }\n\n /**\n * Emits an event when clicking on review button.\n * @param {Object} event - event data\n */\n onClick(event) {\n if (event.target.id === 'WAR') {\n Event.emit('analytics.event', {\n category: 'product detail page',\n action: 'write review',\n label: this.analytics.label,\n extraData: {\n event_name: 'write_review',\n product_info: this.analytics.label,\n },\n });\n\n Event.emit('BV.review.write', {\n category: 'product detail page',\n label: this.analytics.label,\n });\n }\n }\n\n /**\n * Update product review SVG fill URL when product URL is updated\n */\n onProductUrlUpdated() {\n this.element.querySelectorAll('#ratings-summary path').forEach((path) => {\n // Expected fill URL format example:\n // url(\"https:///s/NGLora/en_GB/NG337040-LAC.html?dwvar_NG337040-LAC_color=334_Insta-Rose#bv_rating_summary_star_filled_1_0_99.99_NG337040-LAC\") !important\n const fillURL = path.style.fill;\n\n // Store the Gradient ID after the hash\n const linearGradientID = fillURL.split('#')[1].split('\"')[0];\n\n // Build the new fill URL\n path.setAttribute('style', `fill: url(\"${window.location.href}#${linearGradientID}\") !important`);\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 off('click', this.element);\n Event.removeListener('BV.dependency.check', this.afterInit, this);\n Event.removeListener('product.url.updated', this.onProductUrlUpdated, this);\n }\n}\n"],"mappings":"6HAUqBA,CAAyB,QAAAC,CAAA,oBAAAC,OAAA,WAAAD,CAAA,EAVvCE,CAAS,CAAAF,CAAA,CAAAG,OAAA,WAAAH,CAAA,EACPI,CAAE,CAAAJ,CAAA,CAAFI,EAAE,CAAEC,CAAG,CAAAL,CAAA,CAAHK,GAAG,WAAAL,CAAA,EACPM,CAAK,CAAAN,CAAA,CAALM,KAAK,GAAAC,OAAA,SAAAA,CAAA,EAAAP,CAAA,WAQOD,CAAyB,CAA/B,aAAwC,CAAAG,CAAU,CAK7DM,UAAUA,CAAA,CAAG,CACTJ,CAAE,CAAC,OAAO,CAAE,IAAI,CAACK,OAAO,CAAE,IAAI,CAACC,OAAO,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC,CAClDL,CAAK,CAACM,IAAI,CAAC,qBAAqB,CAAE,IAAI,CAACC,SAAS,CAAE,IAAI,CAAC,CACvDP,CAAK,CAACF,EAAE,CAAC,qBAAqB,CAAE,IAAI,CAACU,mBAAmB,CAAE,IAAI,CAClE,CAMAD,SAASA,CAAA,CAAG,CACRP,CAAK,CAACS,IAAI,CAAC,sBAAsB,CACrC,CAMAL,OAAOA,CAACM,CAAK,CAAE,CACa,KAAK,GAAzBA,CAAK,CAACC,MAAM,CAACC,EAAY,GACzBZ,CAAK,CAACS,IAAI,CAAC,iBAAiB,CAAE,CAC1BI,QAAQ,CAAE,qBAAqB,CAC/BC,MAAM,CAAE,cAAc,CACtBC,KAAK,CAAE,IAAI,CAACC,SAAS,CAACD,KAAK,CAC3BE,SAAS,CAAE,CACPC,UAAU,CAAE,cAAc,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