(function(){
var __webpack_exports__={};
window.germanized=window.germanized||{};
(function ($, germanized){
germanized.unit_price_observer_queue={
queue: {},
timeout: null,
params: {},
request: null,
init: function (){
this.params=wc_gzd_unit_price_observer_queue_params;
this.queue={};
this.queuesInExecution={};
this.latestQueueInExection='';
this.aborted={};
this.timeout=null;
this.request=null;
},
execute: function (){
var self=germanized.unit_price_observer_queue,
data=[],
currentQueueId=Date.now() + '';
self.queuesInExecution[currentQueueId]={
...self.queue
};
self.latestQueueInExection=currentQueueId;
self.queue={};
Object.keys(self.queuesInExecution[currentQueueId]).forEach(function (queueKey){
data=data.concat([{
'product_id': self.queuesInExecution[currentQueueId][queueKey].productId,
'price': self.queuesInExecution[currentQueueId][queueKey].priceData.price,
'price_sale': self.queuesInExecution[currentQueueId][queueKey].priceData.sale_price,
'quantity': self.queuesInExecution[currentQueueId][queueKey].priceData.quantity,
'is_range': self.queuesInExecution[currentQueueId][queueKey].priceData.hasOwnProperty('is_range') ? self.queuesInExecution[currentQueueId][queueKey].priceData.is_range:false,
'key': queueKey
}]);
});
self.request=$.ajax({
type: "POST",
url: self.params.wc_ajax_url.toString().replace('%%endpoint%%', 'gzd_refresh_unit_price'),
data: {
'security': self.params.refresh_unit_price_nonce,
'products': data,
'queue_id': currentQueueId
},
queueId: currentQueueId,
success: function (data){
var xhrQueueId=this.queueId,
currentQueue=self.queuesInExecution.hasOwnProperty(xhrQueueId) ? self.queuesInExecution[xhrQueueId]:{},
aborted=self.aborted.hasOwnProperty(xhrQueueId) ? self.aborted[xhrQueueId]:{};
Object.keys(currentQueue).forEach(function (queueId){
if(!aborted.hasOwnProperty(queueId)){
var current=currentQueue[queueId],
observer=current.observer,
priceData=current.priceData,
priceSelector=current.priceSelector,
isPrimary=current.isPrimary,
unitPrices=self.getUnitPricesFromMap(priceData.unit_price);
if(observer){
if(data.products.hasOwnProperty(queueId)){
var response=data.products[queueId];
observer.stopObserver(observer, priceSelector);
if(parseInt(response.product_id)===observer.getCurrentProductId(observer)){
if(response.hasOwnProperty('unit_price_html')){
observer.unsetUnitPriceLoading(observer, unitPrices, response.unit_price_html);
}else{
observer.unsetUnitPriceLoading(observer, unitPrices);
}}else{
observer.unsetUnitPriceLoading(observer, unitPrices);
}
observer.startObserver(observer, priceSelector, isPrimary);
}else{
observer.stopObserver(observer, priceSelector);
observer.unsetUnitPriceLoading(observer, unitPrices);
observer.startObserver(observer, priceSelector, isPrimary);
}}
}else{
delete self.aborted[xhrQueueId][queueId];
}});
delete self.queuesInExecution[xhrQueueId];
},
error: function (){
var xhrQueueId=this.queueId,
currentQueue=self.queuesInExecution.hasOwnProperty(xhrQueueId) ? self.queuesInExecution[xhrQueueId]:{},
aborted=self.aborted.hasOwnProperty(xhrQueueId) ? self.aborted[xhrQueueId]:{};
Object.keys(currentQueue).forEach(function (queueId){
if(!aborted.hasOwnProperty(queueId)){
var current=currentQueue[queueId],
observer=current.observer,
priceData=current.priceData,
priceSelector=current.priceSelector,
isPrimary=current.isPrimary,
unitPrices=self.getUnitPricesFromMap(priceData.unit_price);
if(observer){
observer.stopObserver(observer, priceSelector);
observer.unsetUnitPriceLoading(observer, unitPrices);
observer.startObserver(observer, priceSelector, isPrimary);
}}else{
delete self.aborted[xhrQueueId][queueId];
}});
delete self.queuesInExecution[xhrQueueId];
},
dataType: 'json'
});
},
getUnitPricesFromMap: function (unitPriceMap){
let unitPrices=[];
unitPriceMap.forEach(function (unitPrice){
unitPrices=$.merge(unitPrices, $(unitPrice));
});
return $(unitPrices);
},
getQueueKey: function (productId){
return (productId + '').replace(/[^a-zA-Z0-9]/g, '');
},
getLatestQueueInExecution(){
var self=germanized.unit_price_observer_queue;
return self.queuesInExecution.hasOwnProperty(self.latestQueueInExection) ? self.queuesInExecution[self.latestQueueInExection]:{};},
exists: function (productId){
var self=germanized.unit_price_observer_queue,
queueKey=self.getQueueKey(productId);
return self.queue.hasOwnProperty(queueKey)||self.getLatestQueueInExecution().hasOwnProperty(queueKey);
},
get: function (productId){
var self=germanized.unit_price_observer_queue,
queueKey=self.getQueueKey(productId),
queueInExecution=self.getLatestQueueInExecution().hasOwnProperty(queueKey);
if(queueInExecution.hasOwnProperty(queueKey)){
return queueInExecution[queueKey];
}else if(self.queue.hasOwnProperty(queueKey)){
return self.queue[queueKey];
}
return false;
},
abort: function (productId){
var self=germanized.unit_price_observer_queue,
queueKey=self.getQueueKey(productId),
latestQueueInExecutionKey=self.latestQueueInExection,
latestQueueInExecution=self.queuesInExecution.hasOwnProperty(latestQueueInExecutionKey) ? self.queuesInExecution[latestQueueInExecutionKey]:{};
if(latestQueueInExecution.hasOwnProperty(queueKey)){
var current=latestQueueInExecution[queueKey],
observer=current.observer,
priceData=current.priceData,
priceSelector=current.priceSelector,
isPrimary=current.isPrimary,
unitPrices=self.getUnitPricesFromMap(priceData.unit_price);
if(observer){
observer.stopObserver(observer, priceSelector);
observer.unsetUnitPriceLoading(observer, unitPrices);
observer.startObserver(observer, priceSelector, isPrimary);
}
if(!self.aborted.hasOwnProperty(latestQueueInExecutionKey)){
self.aborted[latestQueueInExecutionKey]={};}
self.aborted[latestQueueInExecutionKey][queueKey]=current;
return true;
}
return false;
},
add: function (observer, productId, priceData, priceSelector, isPrimary){
var self=germanized.unit_price_observer_queue,
queueKey=self.getQueueKey(productId);
if(self.queue.hasOwnProperty(queueKey)){
priceData['unit_price'].each(function (i, obj){
if(!self.queue[queueKey]['priceData']['unit_price'].has(obj)){
self.queue[queueKey]['priceData']['unit_price'].set(obj, obj);
}});
}else{
var unitPrices=new Map();
priceData['unit_price'].each(function (i, obj){
unitPrices.set(obj, obj);
});
priceData['unit_price']=unitPrices;
self.queue[queueKey]={
'productId': productId,
'observer': observer,
'priceData': priceData,
'priceSelector': priceSelector,
'isPrimary': isPrimary
};}
clearTimeout(self.timeout);
self.timeout=setTimeout(self.execute, 500);
}};
$(document).ready(function (){
germanized.unit_price_observer_queue.init();
});
})(jQuery, window.germanized);
((window.germanized=window.germanized||{})["static"]=window.germanized["static"]||{})["unit-price-observer-queue"]=__webpack_exports__;
})()
;
!function(n,r){var e={version:"0.4.1",settings:{currency:{symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3},number:{precision:0,grouping:3,thousand:",",decimal:"."}}},t=Array.prototype.map,o=Array.isArray,a=Object.prototype.toString;function i(n){return!!(""===n||n&&n.charCodeAt&&n.substr)}function u(n){return o?o(n):"[object Array]"===a.call(n)}function c(n){return n&&"[object Object]"===a.call(n)}function s(n,r){var e;for(e in n=n||{},r=r||{})r.hasOwnProperty(e)&&null==n[e]&&(n[e]=r[e]);return n}function f(n,r,e){var o,a,i=[];if(!n)return i;if(t&&n.map===t)return n.map(r,e);for(o=0,a=n.length;o<a;o++)i[o]=r.call(e,n[o],o,n);return i}function p(n,r){return n=Math.round(Math.abs(n)),isNaN(n)?r:n}function l(n){var r=e.settings.currency.format;return"function"==typeof n&&(n=n()),i(n)&&n.match("%v")?{pos:n,neg:n.replace("-","").replace("%v","-%v"),zero:n}:n&&n.pos&&n.pos.match("%v")?n:i(r)?e.settings.currency.format={pos:r,neg:r.replace("%v","-%v"),zero:r}:r}var m,d=e.unformat=e.parse=function(n,r){if(u(n))return f(n,function(n){return d(n,r)});if("number"==typeof(n=n||0))return n;r=r||e.settings.number.decimal;var t=new RegExp("[^0-9-"+r+"]",["g"]),o=parseFloat((""+n).replace(/\((.*)\)/,"-$1").replace(t,"").replace(r,"."));return isNaN(o)?0:o},g=e.toFixed=function(n,r){r=p(r,e.settings.number.precision);var t=Math.pow(10,r);return(Math.round(e.unformat(n)*t)/t).toFixed(r)},h=e.formatNumber=e.format=function(n,r,t,o){if(u(n))return f(n,function(n){return h(n,r,t,o)});n=d(n);var a=s(c(r)?r:{precision:r,thousand:t,decimal:o},e.settings.number),i=p(a.precision),l=n<0?"-":"",m=parseInt(g(Math.abs(n||0),i),10)+"",y=m.length>3?m.length%3:0;return l+(y?m.substr(0,y)+a.thousand:"")+m.substr(y).replace(/(\d{3})(?=\d)/g,"$1"+a.thousand)+(i?a.decimal+g(Math.abs(n),i).split(".")[1]:"")},y=e.formatMoney=function(n,r,t,o,a,i){if(u(n))return f(n,function(n){return y(n,r,t,o,a,i)});n=d(n);var m=s(c(r)?r:{symbol:r,precision:t,thousand:o,decimal:a,format:i},e.settings.currency),g=l(m.format);return(n>0?g.pos:n<0?g.neg:g.zero).replace("%s",m.symbol).replace("%v",h(Math.abs(n),p(m.precision),m.thousand,m.decimal))};e.formatColumn=function(n,r,t,o,a,m){if(!n)return[];var g=s(c(r)?r:{symbol:r,precision:t,thousand:o,decimal:a,format:m},e.settings.currency),y=l(g.format),b=y.pos.indexOf("%s")<y.pos.indexOf("%v"),v=0;return f(f(n,function(n,r){if(u(n))return e.formatColumn(n,g);var t=((n=d(n))>0?y.pos:n<0?y.neg:y.zero).replace("%s",g.symbol).replace("%v",h(Math.abs(n),p(g.precision),g.thousand,g.decimal));return t.length>v&&(v=t.length),t}),function(n,r){return i(n)&&n.length<v?b?n.replace(g.symbol,g.symbol+new Array(v-n.length+1).join(" ")):new Array(v-n.length+1).join(" ")+n:n})},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=e),exports.accounting=e):"function"==typeof define&&define.amd?define([],function(){return e}):(e.noConflict=(m=n.accounting,function(){return n.accounting=m,e.noConflict=void 0,e}),n.accounting=e)}(this);
(function(){
var __webpack_exports__={};
;
(function ($, window, document, undefined){
var GermanizedUnitPriceObserver=function ($wrapper){
var self=this;
self.params=wc_gzd_unit_price_observer_params;
self.$wrapper=$wrapper.closest(self.params.wrapper);
self.$form=self.$wrapper.find('.variations_form, .cart').length > 0 ? self.$wrapper.find('.variations_form, .cart'):false;
self.isVar=self.$form ? self.$form.hasClass('variations_form'):false;
self.$product=self.$wrapper.closest('.product');
self.requests=[];
self.observer={};
self.timeout=false;
self.priceData=false;
self.productId=0;
if(self.$wrapper.length <=0){
self.$wrapper=self.$product;
}
self.replacePrice=self.$wrapper.hasClass('bundled_product') ? false:self.params.replace_price;
if("MutationObserver" in window||"WebKitMutationObserver" in window||"MozMutationObserver" in window){
self.$wrapper.addClass('has-unit-price-observer');
self.initObservers(self);
if(self.isVar&&self.$form){
self.productId=parseInt(self.$form.find('input[name=product_id]').length > 0 ? self.$form.find('input[name=product_id]').val():self.$form.data('product_id'));
self.variationId=parseInt(self.$form.find('input[name=variation_id]').length > 0 ? self.$form.find('input[name=variation_id]').val():0);
if(self.$form.find('input[name=variation_id]').length <=0){
self.variationId=parseInt(self.$form.find('input.variation_id').length > 0 ? self.$form.find('input.variation_id').val():0);
}
self.$form.on('reset_data.unit-price-observer', {
GermanizedUnitPriceObserver: self
}, self.onResetVariation);
self.$form.on('found_variation.unit-price-observer', {
GermanizedUnitPriceObserver: self
}, self.onFoundVariation);
}else{
if(self.$form&&self.$form.find('*[name=add-to-cart][type=submit]').length > 0){
self.productId=parseInt(self.$form.find('*[name=add-to-cart][type=submit]').val());
}else if(self.$form&&self.$form.data('product_id')){
self.productId=parseInt(self.$form.data('product_id'));
}else{
var classList=self.$product.attr('class').split(/\s+/);
$.each(classList, function (index, item){
if('post-'===item.substring(0, 5)){
var postId=parseInt(item.substring(5).replace(/[^0-9]/g, ''));
if(postId > 0){
self.productId=postId;
return true;
}}
});
if(self.productId <=0&&1===self.$product.find('a.ajax_add_to_cart[data-product_id], a.add_to_cart_button[data-product_id]').length){
self.productId=parseInt(self.$product.find('a.ajax_add_to_cart, a.add_to_cart_button').data('product_id'));
}}
}
if(self.productId <=0){
self.destroy(self);
return false;
}
if(self.params.refresh_on_load){
$.each(self.params.price_selector, function (priceSelector, priceArgs){
var isPrimary=priceArgs.hasOwnProperty('is_primary_selector') ? priceArgs['is_primary_selector']:false,
$price=self.getPriceNode(self, priceSelector, isPrimary),
$unitPrice=self.getUnitPriceNode(self, $price);
if(!isPrimary){
return;
}
if($unitPrice.length > 0){
self.stopObserver(self, priceSelector);
self.setUnitPriceLoading(self, $unitPrice);
setTimeout(function (){
self.stopObserver(self, priceSelector);
var priceData=self.getCurrentPriceData(self, $price, priceArgs['is_total_price'], isPrimary, priceArgs['quantity_selector']);
if(priceData){
self.refreshUnitPrice(self, priceData, priceSelector, isPrimary);
}else if($unitPrice.length > 0){
self.unsetUnitPriceLoading(self, $unitPrice);
}
self.startObserver(self, priceSelector, isPrimary);
}, 250);
}});
}}
$wrapper.data('unitPriceObserver', self);
};
GermanizedUnitPriceObserver.prototype.destroy=function (self){
self=self||this;
self.cancelObservers(self);
if(self.$form){
self.$form.off('.unit-price-observer');
}
self.$wrapper.removeClass('has-unit-price-observer');
};
GermanizedUnitPriceObserver.prototype.getTextWidth=function ($element){
var htmlOrg=$element.html();
var html_calc='<span>' + htmlOrg + '</span>';
$element.html(html_calc);
var textWidth=$element.find('span:first').width();
$element.html(htmlOrg);
return textWidth;
};
GermanizedUnitPriceObserver.prototype.getPriceNode=function (self, priceSelector, isPrimarySelector, visibleOnly){
isPrimarySelector=typeof isPrimarySelector==='undefined' ? false:isPrimarySelector;
visibleOnly=typeof visibleOnly==='undefined' ? true:visibleOnly;
let visibleSelector=visibleOnly ? ':visible':'';
var $node=self.$wrapper.find(priceSelector + ':not(.price-unit)' + visibleSelector).not('.variations_form .single_variation .price').first();
if(isPrimarySelector&&self.isVar&&($node.length <=0||!self.replacePrice)){
$node=self.$wrapper.find('.woocommerce-variation-price span.price:not(.price-unit):last' + visibleSelector);
}else if(isPrimarySelector&&$node.length <=0){
$node=self.$wrapper.find('.price:not(.price-unit):last' + visibleSelector);
}
if($node.length <=0&&self.$wrapper.hasClass('wc-block-product')){
$node=self.$wrapper.find('.wc-block-grid__product-price');
}
return $node;
};
GermanizedUnitPriceObserver.prototype.getObserverNode=function (self, priceSelector, isPrimarySelector){
var $node=self.getPriceNode(self, priceSelector, isPrimarySelector, false);
if(isPrimarySelector&&self.isVar&&!self.replacePrice){
$node=self.$wrapper.find('.single_variation:last');
}
return $node;
};
GermanizedUnitPriceObserver.prototype.getUnitPriceNode=function (self, $price){
if($price.length <=0){
return [];
}
var $element=[];
var isSingleProductBlock=$price.parents('.wp-block-woocommerce-product-price[data-is-descendent-of-single-product-template]').length > 0;
var isProductGridBlock=self.$wrapper.hasClass('wc-block-product');
if('SPAN'===$price[0].tagName){
$element=self.$wrapper.find('.price-unit');
}else{
if(isSingleProductBlock){
$element=self.$wrapper.find('.wp-block-woocommerce-gzd-product-unit-price[data-is-descendent-of-single-product-template] .price-unit');
}else if(isProductGridBlock){
$element=self.$wrapper.find('.price-unit:not(.wc-gzd-additional-info-placeholder)');
}else{
$element=self.$wrapper.find('.price-unit:not(.wc-gzd-additional-info-placeholder, .wc-gzd-additional-info-loop)');
}}
if($element.length > 0){
if($element.is(':empty')||$element.find('.wc-gzd-additional-info-placeholder').is(':empty')){
$element=[];
}}
return $element;
};
GermanizedUnitPriceObserver.prototype.stopObserver=function (self, priceSelector){
var observer=self.getObserver(self, priceSelector);
if(observer){
observer.disconnect();
}};
GermanizedUnitPriceObserver.prototype.startObserver=function (self, priceSelector, isPrimary){
var observer=self.getObserver(self, priceSelector),
$node=self.getObserverNode(self, priceSelector, isPrimary);
if(observer){
self.stopObserver(self, priceSelector);
if($node.length > 0){
observer.observe($node[0], {
attributes: true,
childList: true,
subtree: true,
characterData: true,
attributeFilter: ['style']
});
}
return true;
}
return false;
};
GermanizedUnitPriceObserver.prototype.initObservers=function (self){
if(Object.keys(self.observer).length!==0){
return;
}
$.each(self.params.price_selector, function (priceSelector, priceArgs){
var isPrimary=priceArgs.hasOwnProperty('is_primary_selector') ? priceArgs['is_primary_selector']:false,
$observerNode=self.getObserverNode(self, priceSelector, isPrimary),
currentObserver=false;
if($observerNode.length > 0&&$observerNode.is(':visible')){
var callback=function (mutationsList, observer){
var $priceNode=self.getPriceNode(self, priceSelector, isPrimary);
for (let mutation of mutationsList){
let $element=$(mutation.target);
if($element.length > 0){
let $priceElement;
if($element.is(priceSelector)){
$priceElement=$element;
}else{
$priceElement=$element.parents(priceSelector);
}
if($priceElement.length > 0){
$priceNode=$priceElement;
}}
}
if(self.timeout){
clearTimeout(self.timeout);
}
var $unitPrice=self.getUnitPriceNode(self, $priceNode),
hasRefreshed=false;
if($priceNode.length <=0){
return false;
}
self.stopObserver(self, priceSelector);
if($unitPrice.length > 0){
self.setUnitPriceLoading(self, $unitPrice);
self.timeout=setTimeout(function (){
self.stopObserver(self, priceSelector);
$priceNode=self.getPriceNode(self, priceSelector, isPrimary);
if($priceNode.length > 0){
var priceData=self.getCurrentPriceData(self, $priceNode, priceArgs['is_total_price'], isPrimary, priceArgs['quantity_selector']);
var isVisible=$priceNode.is(':visible');
if(priceData){
if(self.isRefreshingUnitPrice(self.getCurrentProductId(self))){
self.abortRefreshUnitPrice(self.getCurrentProductId(self));
}
hasRefreshed=true;
self.refreshUnitPrice(self, priceData, priceSelector, isPrimary);
}
if(!hasRefreshed&&$unitPrice.length > 0){
self.unsetUnitPriceLoading(self, $unitPrice);
if(!isVisible&&isPrimary){
$unitPrice.hide();
}}
}
self.startObserver(self, priceSelector, isPrimary);
}, 500);
}};
if("MutationObserver" in window){
currentObserver=new window.MutationObserver(callback);
}else if("WebKitMutationObserver" in window){
currentObserver=new window.WebKitMutationObserver(callback);
}else if("MozMutationObserver" in window){
currentObserver=new window.MozMutationObserver(callback);
}
if(currentObserver){
self.observer[priceSelector]=currentObserver;
self.startObserver(self, priceSelector, isPrimary);
}}
});
};
GermanizedUnitPriceObserver.prototype.getObserver=function (self, priceSelector){
if(self.observer.hasOwnProperty(priceSelector)){
return self.observer[priceSelector];
}
return false;
};
GermanizedUnitPriceObserver.prototype.cancelObservers=function (self){
for (var key in self.observer){
if(self.observer.hasOwnProperty(key)){
self.observer[key].disconnect();
delete self.observer[key];
}}
};
GermanizedUnitPriceObserver.prototype.onResetVariation=function (event){
var self=event.data.GermanizedUnitPriceObserver;
self.variationId=0;
};
GermanizedUnitPriceObserver.prototype.onFoundVariation=function (event, variation){
var self=event.data.GermanizedUnitPriceObserver;
if(variation.hasOwnProperty('variation_id')){
self.variationId=parseInt(variation.variation_id);
}
self.initObservers(self);
};
GermanizedUnitPriceObserver.prototype.getCurrentPriceData=function (self, priceSelector, isTotalPrice, isPrimary, quantitySelector){
quantitySelector=quantitySelector&&''!==quantitySelector ? quantitySelector:self.params.qty_selector;
var $price=typeof priceSelector==='string'||priceSelector instanceof String ? self.getPriceNode(self, priceSelector, isPrimary):priceSelector;
if($price.length > 0){
$price.find(':hidden').addClass('wc-gzd-is-hidden');
var $unit_price=self.getUnitPriceNode(self, $price),
$priceCloned=$price.clone();
$priceCloned.find('.woocommerce-price-suffix').remove();
$priceCloned.find('.wc-gzd-is-hidden').remove();
var sale_price='',
$priceInner=$priceCloned.find('.amount:first'),
$qty=$(self.params.wrapper + ' ' + quantitySelector + ':first'),
qty=1,
is_range=false;
if($qty.length > 0){
qty=parseFloat($qty.val());
}
if($priceInner.length <=0){
if($priceCloned.find('.price').length > 0){
$priceInner=$priceCloned.find('.price');
}else{
$priceInner=$priceCloned;
}}
var price=self.getRawPrice($priceInner, self.params.price_decimal_sep);
if($priceCloned.find('.amount').length > 1){
var $sale_price=$($priceCloned.find('.amount')[1]);
sale_price=self.getRawPrice($sale_price, self.params.price_decimal_sep);
}
if(sale_price&&$priceCloned.find('del').length <=0){
is_range=true;
}
$price.find('.wc-gzd-is-hidden').removeClass('wc-gzd-is-hidden');
if($unit_price.length > 0&&price){
if(isTotalPrice){
price=parseFloat(price) / qty;
if(sale_price){
sale_price=parseFloat(sale_price) / qty;
}}
return {
'price': price,
'unit_price': $unit_price,
'sale_price': sale_price,
'quantity': qty,
'is_range': is_range
};}}
return false;
};
GermanizedUnitPriceObserver.prototype.getCurrentProductId=function (self){
var productId=self.productId;
if(self.variationId > 0){
productId=self.variationId;
}
return parseInt(productId);
};
GermanizedUnitPriceObserver.prototype.getRawPrice=function ($el, decimal_sep){
var price_raw=$el.length > 0 ? $el.text():'',
price=false;
try {
price=accounting.unformat(price_raw, decimal_sep);
} catch (e){
price=false;
}
return price;
};
GermanizedUnitPriceObserver.prototype.setUnitPriceLoading=function (self, $unit_price){
var unitPriceOrg=$unit_price.html();
if(!$unit_price.hasClass('wc-gzd-loading')){
var textWidth=self.getTextWidth($unit_price),
textHeight=$unit_price.find('span').length > 0 ? $unit_price.find('span').innerHeight():$unit_price.height();
$unit_price.html('<span class="wc-gzd-placeholder-loading"><span class="wc-gzd-placeholder-row" style="height: ' + $unit_price.height() + 'px;"><span class="wc-gzd-placeholder-row-col-4" style="width: ' + textWidth + 'px; height: ' + textHeight + 'px;"></span></span></span>');
$unit_price.addClass('wc-gzd-loading');
}
$unit_price.data('org-html', unitPriceOrg);
return unitPriceOrg;
};
GermanizedUnitPriceObserver.prototype.unsetUnitPriceLoading=function (self, $unit_price, newHtml){
newHtml=newHtml||$unit_price.data('org-html');
$unit_price.html(newHtml);
if($unit_price.hasClass('wc-gzd-loading')){
$unit_price.removeClass('wc-gzd-loading');
}
if(typeof newHtml==="string"&&newHtml.length > 0){
$unit_price.show();
}};
GermanizedUnitPriceObserver.prototype.isRefreshingUnitPrice=function (currentProductId){
return germanized.unit_price_observer_queue.exists(currentProductId);
};
GermanizedUnitPriceObserver.prototype.abortRefreshUnitPrice=function (currentProductId){
return germanized.unit_price_observer_queue.abort(currentProductId);
};
GermanizedUnitPriceObserver.prototype.refreshUnitPrice=function (self, priceData, priceSelector, isPrimary){
germanized.unit_price_observer_queue.add(self, self.getCurrentProductId(self), priceData, priceSelector, isPrimary);
};
$.fn.wc_germanized_unit_price_observer=function (){
if($(this).data('unitPriceObserver')){
$(this).data('unitPriceObserver').destroy();
}
new GermanizedUnitPriceObserver(this);
return this;
};
$(function (){
if(typeof wc_gzd_unit_price_observer_params!=='undefined'){
$(wc_gzd_unit_price_observer_params.wrapper).each(function (){
if($(this).is('body')){
return;
}
$(this).wc_germanized_unit_price_observer();
});
}});
})(jQuery, window, document);
window.germanized=window.germanized||{};
((window.germanized=window.germanized||{})["static"]=window.germanized["static"]||{})["unit-price-observer"]=__webpack_exports__;
})()
;
var WPMLCore=WPMLCore||{};
WPMLCore.XdomainData=function(){
this.links=document.querySelectorAll('.' + wpml_xdomain_data.css_selector + ' a');
var self=this;
for(var i=0; i < this.links.length; i++){
this.links[i].addEventListener('click', function(e){
var link=self.getClosestLink(e.target);
var currentUrl=window.location.href;
var targetUrl=link.getAttribute('href');
if('#'!==targetUrl&&currentUrl!==targetUrl){
e.preventDefault();
self.onLinkClick(link);
}});
}};
WPMLCore.XdomainData.prototype={
getClosestLink: function(maybeLink){
var tagName=maybeLink.nodeName.toLowerCase();
if(tagName==='a'){
return maybeLink;
}
return this.getClosestLink(maybeLink.parentNode);
},
onLinkClick: function(link){
var self=this;
var originalUrl=link.getAttribute('href');
originalUrl=originalUrl.replace(/&xdomain_data(=[^&]*)?(?=&|$)|xdomain_data(=[^&]*)?(&|$)/, '');
originalUrl=originalUrl.replace(/\?$/, '');
var data={
action:        'switching_language',
from_language: wpml_xdomain_data.current_language,
_nonce:        wpml_xdomain_data._nonce,
};
var params=[];
for(var prop in data){
if(typeof data[prop]!=='undefined'){
params.push(encodeURIComponent(prop) + '=' + encodeURIComponent(data[prop]));
}}
params=params.join('&', params);
var req=new XMLHttpRequest();
req.open("POST", wpml_xdomain_data.ajax_url);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.setRequestHeader('Accept', 'application/json, text/javascript, */*; q=0.01');
req.onload=function(){
const response=JSON.parse(req.response);
self.onSuccess(response, originalUrl);
};
req.onerror=function(){
location.href=originalUrl;
};
req.send(params);
},
onSuccess: function(response, originalUrl){
var argsGlue;
var url;
var hash;
var urlSplit;
var xdomain;
var form;
if(response.data.xdomain_data){
if(response.success){
if('post'===response.data.method){
form=document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', originalUrl);
xdomain=document.createElement('input');
xdomain.setAttribute('type', 'hidden');
xdomain.setAttribute('name', 'xdomain_data');
xdomain.setAttribute('value', response.data.xdomain_data);
form.appendChild(xdomain);
document.body.appendChild(form);
form.submit();
}else{
urlSplit=originalUrl.split('#');
hash='';
if(1 < urlSplit.length){
hash='#' + urlSplit[1];
}
url=urlSplit[0];
if(url.indexOf('?')===-1){argsGlue='?';}else{argsGlue='&';}
/** @namespace response.data.xdomain_data */
url=originalUrl + argsGlue + 'xdomain_data=' + response.data.xdomain_data + hash;
location.href=url;
}}else{
url=originalUrl;
location.href=url;
}}else{
location.href=originalUrl;
}},
};
document.addEventListener('DOMContentLoaded', function(){
var xd=new WPMLCore.XdomainData();
});