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AOY,UAErDZ,EAAOiI,oBACPJ,EAAgBpE,aAAa,2BAA4BzD,EAAOiI,oBAGhE3B,EAAQqB,aACRrB,EAAQ5H,WAAWC,aAAakJ,EAAiBvB,EAAQqB,aACzD7H,KAAKqC,qBAELmE,EAAQ5H,WAAWkJ,YAAYC,EAzCnC,MAFIrB,QAAQC,MAAMF,EAAW,0EA6CjC,IAIRvI,mBAAmB2B,OACnByC,OAAOC,QAAO,WAEV,GADArE,mBAAmB0H,oBACf,oBAAuBwC,OAAQ,CAC/B,IAAMC,EAAgBD,OAAO,oBACzBC,EAAcnE,SACdmE,EAAcC,GAAG,kBAAkB,kBAAMpK,mBAAmB0H,mBAAkB,EAAM,IACpFyC,EAAcC,GAAG,kBAAkB,kBAAMpK,mBAAmB0H,mBAAmB,IAEvF,CACJ,IACJ,G","sources":["webpack://sequra-wc/./assets/js/src/page/widget-facade.js"],"sourcesContent":["if (SequraWidgetFacade) {\n (function (i, s, o, g, r, a, m) { i['SequraConfiguration'] = g; i['SequraOnLoad'] = []; i[r] = {}; i[r][a] = function (callback) { i['SequraOnLoad'].push(callback); }; (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); a.async = 1; a.src = g.scriptUri; m.parentNode.insertBefore(a, m); })(window, document, 'script', SequraWidgetFacade, 'Sequra', 'onLoad');\n}\n(function () {\n document.addEventListener('DOMContentLoaded', () => {\n if (!SequraWidgetFacade) {\n return;\n }\n\n SequraWidgetFacade = {\n ...{\n widgets: [],\n miniWidgets: [],\n },\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":["i","s","o","g","r","a","m","SequraWidgetFacade","window","document","callback","push","createElement","getElementsByTagName","async","src","scriptUri","parentNode","insertBefore","addEventListener","_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","getText","selector","querySelector","textContent","nodeToCents","node","textToCents","selectorToCents","encodedString","match","elem","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","n","done","child","getAttribute","setAttribute","err","e","f","getMiniWidgetTargets","prices","priceObservedAttr","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","maxAmount","widgetNode","creditAgreements","computeCreditAgreements","amount","creditAgreement","pop","min_amount","messageBelowLimit","innerText","message","instalment_total","string","nextSibling","appendChild","promoWidgetNode","attributes","JSON","parse","registrationAmount","jQuery","variationForm","on"],"sourceRoot":""}