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AmBkH,mBAAmB,IAEvF,CACJ,IACJ,G","sources":["webpack://sequra-wc/./assets/js/src/page/widget-facade.js"],"sourcesContent":["(function () {\n document.addEventListener('DOMContentLoaded', () => {\n if (!SequraConfigParams || !SequraWidgetFacade) {\n return;\n }\n\n SequraWidgetFacade = {\n ...{\n widgets: [],\n miniWidgets: [],\n },\n ...SequraConfigParams,\n ...SequraWidgetFacade,\n ...{\n mutationObserver: null,\n forcePriceSelector: true,\n presets: {\n L: '{\"alignment\":\"left\"}',\n R: '{\"alignment\":\"right\"}',\n legacy: '{\"type\":\"legacy\"}',\n legacyL: '{\"type\":\"legacy\",\"alignment\":\"left\"}',\n legacyR: '{\"type\":\"legacy\",\"alignment\":\"right\"}',\n minimal: '{\"type\":\"text\",\"branding\":\"none\",\"size\":\"S\",\"starting-text\":\"as-low-as\"}',\n minimalL: '{\"type\":\"text\",\"branding\":\"none\",\"size\":\"S\",\"starting-text\":\"as-low-as\",\"alignment\":\"left\"}',\n minimalR: '{\"type\":\"text\",\"branding\":\"none\",\"size\":\"S\",\"starting-text\":\"as-low-as\",\"alignment\":\"right\"}'\n },\n\n init: function () {\n // Remove duplicated objects from this.widgets.\n const uniqueWidgets = [];\n this.widgets.forEach(widget => {\n Object.keys(widget).forEach(key => {\n if (typeof widget[key] === 'string') {\n widget[key] = this.decodeEntities(widget[key]);\n }\n });\n\n if (!uniqueWidgets.some(w => w.price_src === widget.price_src && w.dest === widget.dest && w.product === widget.product && w.theme === widget.theme && w.reverse === widget.reverse && w.campaign === widget.campaign)) {\n uniqueWidgets.push(widget);\n }\n });\n this.widgets = uniqueWidgets;\n },\n\n getText: function (selector) {\n return selector && document.querySelector(selector) ? document.querySelector(selector).textContent : \"0\";\n },\n\n nodeToCents: function (node) {\n return this.textToCents(node ? node.textContent : \"0\");\n },\n\n selectorToCents: function (selector) {\n return this.textToCents(this.getText(selector));\n },\n\n decodeEntities: function (encodedString) {\n if (!encodedString.match(/&(nbsp|amp|quot|lt|gt|#\\d+|#x[0-9A-Fa-f]+);/g)) {\n return encodedString;\n }\n const elem = document.createElement('div');\n elem.innerHTML = encodedString;\n return elem.textContent;\n },\n\n textToCents: function (text) {\n const thousandSeparator = this.decodeEntities(this.thousandSeparator);\n const decimalSeparator = this.decodeEntities(this.decimalSeparator);\n\n text = text.replace(/^\\D*/, '').replace(/\\D*$/, '');\n if (text.indexOf(decimalSeparator) < 0) {\n text += decimalSeparator + '00';\n }\n return this.floatToCents(\n parseFloat(\n text\n .replace(thousandSeparator, '')\n .replace(decimalSeparator, '.')\n )\n );\n },\n\n floatToCents: function (value) {\n return parseInt(value.toFixed(2).replace('.', ''), 10);\n },\n\n refreshComponents: function () {\n Sequra.onLoad(\n function () {\n Sequra.refreshComponents();\n }\n );\n },\n\n isVariableProduct: function (selector) {\n return document.querySelector(selector) ? true : false;\n },\n\n getPriceSelector: function (widget) {\n return !this.forcePriceSelector && this.isVariableProduct(widget.isVariableSel) ? widget.variationPriceSel : widget.priceSel;\n },\n\n /**\n * Search for child elements in the parentElem that are targets of the widget\n * @param {object} parentElem DOM element that may contains the widget's targets\n * @param {object} widget Widget object\n * @param {string} observedAt Unique identifier to avoid fetch the same element multiple times\n * @returns {array} Array of objects containing the target elements and a reference to the widget\n */\n getWidgetTargets: function (parentElem, widget, observedAt) {\n const targets = [];\n if (widget.dest) {\n const children = parentElem.querySelectorAll(widget.dest);\n const productObservedAttr = 'data-sequra-observed-' + widget.product;\n for (const child of children) {\n if (child.getAttribute(productObservedAttr) == observedAt) {\n continue;// skip elements that are already observed in this mutation.\n }\n child.setAttribute(productObservedAttr, observedAt);\n targets.push({ elem: child, widget });\n }\n }\n return targets;\n },\n\n /**\n * Search for child elements in the parentElem that are targets of the widget\n * @param {object} widget Widget object\n * @returns {array} Array of objects containing the target elements and a reference to the widget\n */\n getMiniWidgetTargets: function (widget) {\n const targets = [];\n if (widget.dest) {\n const children = document.querySelectorAll(widget.dest);\n const prices = document.querySelectorAll(widget.priceSel);\n const priceObservedAttr = 'data-sequra-observed-price-' + widget.product;\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n\n const priceElem = 'undefined' !== typeof prices[i] ? prices[i] : null;\n const priceValue = priceElem ? this.nodeToCents(priceElem) : null;\n\n if (null === priceValue || child.getAttribute(priceObservedAttr) == priceValue) {\n continue;\n }\n child.setAttribute(priceObservedAttr, priceValue);\n targets.push({ elem: child, priceElem, widget });\n }\n }\n return targets;\n },\n\n /**\n * Get an unique identifier to avoid fetch the same element multiple times\n * @returns {number} The current timestamp\n */\n getObservedAt: () => Date.now(),\n\n removeWidgetsOnPage: function () {\n if (this.mutationObserver) {\n this.mutationObserver.disconnect();\n }\n document.querySelectorAll('.sequra-promotion-widget').forEach(widget => widget.remove());\n if (this.mutationObserver) {\n this.mutationObserver.observe(document, { childList: true, subtree: true });\n }\n },\n\n /**\n * Draw the missing or outdated widgets in the page.\n */\n refreshWidgets: function () {\n\n const targets = [];\n for (const widget of this.widgets) {\n const widgetTargets = this.getWidgetTargets(document, widget, this.getObservedAt());\n targets.push(...widgetTargets);\n }\n for (const miniWidget of this.miniWidgets) {\n const widgetTargets = this.getMiniWidgetTargets(miniWidget);\n targets.push(...widgetTargets);\n }\n\n targets.forEach(target => {\n const { elem, widget } = target;\n this.isMiniWidget(widget) ? this.drawMiniWidgetOnElement(widget, elem, target.priceElem) : this.drawWidgetOnElement(widget, elem);\n });\n },\n\n /**\n * Paint the widgets in the page and observe the DOM to refresh the widgets when the page changes.\n * @param {boolean} forcePriceSelector If true, the price selector will be forced to the simple product price selector.\n */\n drawWidgetsOnPage: function (forcePriceSelector = true) {\n if (!this.widgets.length && !this.miniWidgets.length) {\n return;\n }\n\n if (this.mutationObserver) {\n this.mutationObserver.disconnect();\n }\n\n this.forcePriceSelector = forcePriceSelector;\n\n this.refreshWidgets();\n\n // Then, observe the DOM to refresh the widgets when the page changes.\n this.mutationObserver = new MutationObserver((mutations) => {\n this.mutationObserver.disconnect();// disable the observer to avoid multiple calls to the same function.\n for (const mutation of mutations) {\n if (['childList', 'subtree', 'characterData'].includes(mutation.type)) {\n this.refreshWidgets();\n break;\n }\n }\n this.mutationObserver.observe(document, { childList: true, subtree: true, characterData: true }); // enable the observer again.\n });\n\n this.mutationObserver.observe(document, { childList: true, subtree: true, characterData: true });\n },\n\n isMiniWidget: function (widget) {\n return this.miniWidgets.indexOf(widget) !== -1;\n },\n\n drawMiniWidgetOnElement: function (widget, element, priceElem) {\n if (!priceElem) {\n const priceSrc = this.getPriceSelector(widget);\n priceElem = document.querySelector(priceSrc);\n if (!priceElem) {\n console.error(priceSrc + ' is not a valid css selector to read the price from, for seQura mini-widget.');\n return;\n }\n }\n const cents = this.nodeToCents(priceElem);\n\n\n\n const className = 'sequra-educational-popup';\n const modifierClassName = className + '--' + widget.product;\n\n const oldWidget = element.parentNode.querySelector('.' + className + '.' + modifierClassName);\n if (oldWidget) {\n if (cents == oldWidget.getAttribute('data-amount')) {\n return; // no need to update the widget, the price is the same.\n }\n\n oldWidget.remove();// remove the old widget to draw a new one.\n }\n\n if (widget.maxAmount && widget.maxAmount < cents) {\n return;\n }\n\n const widgetNode = document.createElement('small');\n widgetNode.className = className + ' ' + modifierClassName;\n widgetNode.setAttribute('data-amount', cents);\n widgetNode.setAttribute('data-product', widget.product);\n\n const creditAgreements = Sequra.computeCreditAgreements({ amount: cents, product: widget.product })[widget.product];\n let creditAgreement = null\n do {\n creditAgreement = creditAgreements.pop();\n } while (cents < creditAgreement.min_amount.value && creditAgreements.length > 1);\n if (cents < creditAgreement.min_amount.value && !widget.messageBelowLimit) {\n return;\n }\n\n if (cents >= creditAgreement.min_amount.value) {\n widgetNode.innerText = widget.message.replace('%s', creditAgreement.instalment_total.string);\n } else {\n if (!widget.messageBelowLimit) {\n return;\n }\n widgetNode.innerText = widget.messageBelowLimit.replace('%s', creditAgreement.min_amount.string);\n }\n\n if (element.nextSibling) {//Insert after\n element.parentNode.insertBefore(widgetNode, element.nextSibling);\n this.refreshComponents();\n } else {\n element.parentNode.appendChild(widgetNode);\n }\n\n },\n\n drawWidgetOnElement: function (widget, element) {\n const priceSrc = this.getPriceSelector(widget);\n const priceElem = document.querySelector(priceSrc);\n if (!priceElem) {\n console.error(priceSrc + ' is not a valid css selector to read the price from, for seQura widget.');\n return;\n }\n const cents = this.nodeToCents(priceElem);\n\n const className = 'sequra-promotion-widget';\n const modifierClassName = className + '--' + widget.product;\n\n const oldWidget = element.parentNode.querySelector('.' + className + '.' + modifierClassName);\n if (oldWidget) {\n if (cents == oldWidget.getAttribute('data-amount')) {\n return; // no need to update the widget, the price is the same.\n }\n\n oldWidget.remove();// remove the old widget to draw a new one.\n }\n\n const promoWidgetNode = document.createElement('div');\n promoWidgetNode.className = className + ' ' + modifierClassName;\n promoWidgetNode.setAttribute('data-amount', cents);\n promoWidgetNode.setAttribute('data-product', widget.product);\n\n const theme = this.presets[widget.theme] ? this.presets[widget.theme] : widget.theme;\n try {\n const attributes = JSON.parse(theme);\n for (let key in attributes) {\n promoWidgetNode.setAttribute('data-' + key, \"\" + attributes[key]);\n }\n } catch (e) {\n promoWidgetNode.setAttribute('data-type', 'text');\n }\n\n if (widget.campaign) {\n promoWidgetNode.setAttribute('data-campaign', widget.campaign);\n }\n if (widget.registrationAmount) {\n promoWidgetNode.setAttribute('data-registration-amount', widget.registrationAmount);\n }\n\n if (element.nextSibling) {//Insert after\n element.parentNode.insertBefore(promoWidgetNode, element.nextSibling);\n this.refreshComponents();\n } else {\n element.parentNode.appendChild(promoWidgetNode);\n }\n }\n }\n };\n\n SequraWidgetFacade.init()\n Sequra.onLoad(() => {\n SequraWidgetFacade.drawWidgetsOnPage();\n if ('undefined' !== typeof jQuery) {\n const variationForm = jQuery('.variations_form');\n if (variationForm.length) {\n variationForm.on('show_variation', () => SequraWidgetFacade.drawWidgetsOnPage(false));\n variationForm.on('hide_variation', () => SequraWidgetFacade.drawWidgetsOnPage());\n }\n }\n });\n });\n})();"],"names":["document","addEventListener","SequraConfigParams","SequraWidgetFacade","_objectSpread","widgets","miniWidgets","mutationObserver","forcePriceSelector","presets","L","R","legacy","legacyL","legacyR","minimal","minimalL","minimalR","init","_this","uniqueWidgets","this","forEach","widget","Object","keys","key","decodeEntities","some","w","price_src","dest","product","theme","reverse","campaign","push","getText","selector","querySelector","textContent","nodeToCents","node","textToCents","selectorToCents","encodedString","match","elem","createElement","innerHTML","text","thousandSeparator","decimalSeparator","replace","indexOf","floatToCents","parseFloat","value","parseInt","toFixed","refreshComponents","Sequra","onLoad","isVariableProduct","getPriceSelector","isVariableSel","variationPriceSel","priceSel","getWidgetTargets","parentElem","observedAt","targets","_step","children","querySelectorAll","productObservedAttr","_iterator","_createForOfIteratorHelper","s","n","done","child","getAttribute","setAttribute","err","e","f","getMiniWidgetTargets","prices","priceObservedAttr","i","length","priceElem","priceValue","getObservedAt","Date","now","removeWidgetsOnPage","disconnect","remove","observe","childList","subtree","refreshWidgets","_step2","_this2","_iterator2","widgetTargets","apply","_toConsumableArray","_step3","_iterator3","miniWidget","target","isMiniWidget","drawMiniWidgetOnElement","drawWidgetOnElement","drawWidgetsOnPage","_this3","arguments","undefined","MutationObserver","mutations","_step4","_iterator4","mutation","includes","type","characterData","element","priceSrc","console","error","cents","className","modifierClassName","oldWidget","parentNode","maxAmount","widgetNode","creditAgreements","computeCreditAgreements","amount","creditAgreement","pop","min_amount","messageBelowLimit","innerText","message","instalment_total","string","nextSibling","insertBefore","appendChild","promoWidgetNode","attributes","JSON","parse","registrationAmount","jQuery","variationForm","on"],"sourceRoot":""}