/**
* Funktion für das Modul basketteaser
* Fügt die Produkte im Warenkorb ein
*/
function wpsg_mod_basketteaser_add(produkt_id)
{
var menge = jQuery('.wpsg_mod_basketteaser_row_' + produkt_id + ' input').val();
if (menge <= 0) menge = 1;
location.href = wpsg_ajax.ajaxurl + '?wpsg[menge]=' + menge + '&wpsg[produkt_id]=' + produkt_id + '&wpsg[submit]=1';
return false;
} // wpsg_mod_basketteaser_add(produkt_id)
/**
* Aktualisiert ein eventuell eingebundenes Warenkorbwidget
*/
function wpsg_refreshBasketWidget()
{
if (jQuery('.wpsg_basket_widget').length <= 0) return;
jQuery('.wpsg_basket_widget').html('
');
jQuery.ajax( {
url: wpsg_ajax.url_basket,
data: {
'wpsg[ajax]': 1,
'wpsg[action]': 'widget'
},
success: function(data) {
jQuery('.wpsg_basket_widget').html(data);
}
} );
} // function wpsg_refreshBasketWidget()
function wpsg_customerquestion(url_redirect)
{
jQuery('body,html').addClass('wpsg_noscroll');
jQuery('body').append('
');
jQuery.ajax( {
url: wpsg_ajax.url_basket,
data: {
'wpsg[ajax]': 1,
'wpsg[action]': 'customerquestion',
'wpsg[url]': url_redirect
},
success: function(data) {
jQuery('#wpsg_calc_layer .content').html(data);
}
} );
return false;
}
/* Minigallery */
function wpsg_product_bind()
{
// Prev im Produktcarousel
jQuery('.wpsg_productteaser .wpsg_productteaser_left').unbind('click').bind('click', function() {
if (typeof jQuery(this).attr("data-target") != "undefined") jQuery('#wpsg_slider_pt_' + jQuery(this).attr("data-target")).carousel("prev");
else jQuery(this).parents('.wpsg_productteaser').find('.carousel:visible').carousel("prev");
return false;
} );
// Next im Productcarousel
jQuery('.wpsg_productteaser .wpsg_productteaser_right').unbind('click').bind('click', function() {
if (typeof jQuery(this).attr("data-target") != "undefined") jQuery('#wpsg_slider_pt_' + jQuery(this).attr("data-target")).carousel("next");
else jQuery(this).parents('.wpsg_productteaser').find('.carousel:visible').carousel("next");
return false;
} );
// + / - im Produkttemplate
jQuery('.wpsg_product_sub, .wpsg_product_add').unbind('click').bind('click', function() {
var amount = parseInt(jQuery(this).parents('.product_add').find('.wpsg_amount').val());
if (amount == NaN || amount < 0) amount = 0;
if (jQuery(this).hasClass('wpsg_product_add')) amount ++;
else if (amount > 1) amount --;
jQuery(this).parents('.product_add').find('.wpsg_amount').val(amount);
return false;
} );
}
/**
* Sperrt die Funktionen im Produkttemplate, während einer Ajax Aktion
* @param template_index
*/
function wpsg_blockProductTemplate(template_index)
{
jQuery('#wpsg_produktform_' + template_index).append('');
} // function wpsg_blockProductTemplate(template_index)
/**
* Entsperrt die Funktionen im Produkttemplate nach einer Ajax Aktion
* @param template_index
*/
function wpsg_unblockProductTemplate(template_index)
{
jQuery('#wpsg_produktform_' + template_index + ' .wpsg_product_layer').remove();
} // function wpsg_unblockProductTemplate(template_index)
wpsg_numberformat = function (number, decimals, dec_point, thousands_sep)
{
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function (n, prec)
{
var k = Math.pow(10, prec);
return '' + Math.round(n * k) / k;
};
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
if (s[0].length > 3)
{
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
}
if ((s[1] || '').length < prec)
{
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0');
}
return s.join(dec);
};
wpsg_tf = function(value)
{
if (value == null) return;
if (typeof value == "number") return parseFloat(value);
if (value.lastIndexOf(".") == -1)
{
// 1500,50
return parseFloat(value.replace(/,/, "."));
}
else
{
if (value.lastIndexOf(",") == -1)
{
// 1500.50
return parseFloat(value);
}
else
{
if (value.lastIndexOf(",") > value.lastIndexOf("."))
{
// 1.500,50
return parseFloat(value.replace(/\./, "").replace(/,/, "."));
}
else
{
// 1,500.50
return parseFloat(value.replace(/,/, ""));
}
}
}
};
wpsg_round = function(value, exp) {
if (typeof exp === 'undefined' || +exp === 0) return Math.round(value);
value = +value;
exp = +exp;
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) return NaN;
value = value.toString().split('e');
value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)));
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp));
}
/**
* Bildleiste der Produktseite im Modus „neu“: zeigt das gewählte Bild groß (Punkt 8.2)
*/
document.addEventListener('click', function(event) {
var thumb = event.target.closest('.wpsg-product__thumb');
if (!thumb) return;
var media = thumb.closest('.wpsg-product__media');
var index = thumb.getAttribute('data-wpsg-image');
media.querySelectorAll('.wpsg-product__image').forEach(function(image) { image.style.display = ((image.getAttribute('data-wpsg-image') === index)?'':'none'); });
media.querySelectorAll('.wpsg-product__thumb').forEach(function(button) { button.setAttribute('aria-pressed', ((button === thumb)?'true':'false')); });
} );
/**
* Brotkrumen der Produktseite im Modus „neu“: die Kategorie, von der der Besucher kam (Punkt 8.4)
*
* Der Server gibt die erste Kategorie aus, damit die Seite für Seiten-Caches gleich bleibt.
*/
function wpsg_productBreadcrumbs() {
if (!document.referrer) return;
var referrer = document.referrer.split(/[?#]/)[0].replace(/\/page\/\d+\/?$/, '/').replace(/\/?$/, '/');
document.querySelectorAll('.wpsg-product__breadcrumbs[data-wpsg-trails]').forEach(function(nav) {
var trails = JSON.parse(nav.getAttribute('data-wpsg-trails'));
var trail = trails.find(function(t) { return (t[t.length - 1].url.replace(/\/?$/, '/') === referrer); });
if (!trail) return;
var list = nav.querySelector('ol');
list.querySelectorAll('.wpsg-product__crumb-category').forEach(function(li) { li.remove(); });
trail.forEach(function(crumb) {
var li = document.createElement('li');
var a = document.createElement('a');
li.className = 'wpsg-product__crumb-category';
a.href = crumb.url;
a.textContent = crumb.name;
li.appendChild(a);
list.insertBefore(li, list.lastElementChild);
} );
} );
} // function wpsg_productBreadcrumbs()
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', wpsg_productBreadcrumbs); else wpsg_productBreadcrumbs();
// Der Variantenwechsel ersetzt das Produkt per Ajax
jQuery(document).ajaxComplete(wpsg_productBreadcrumbs);
/**
* GARAN-Label (Tooltip): bleibt im Fenster, ohne verkleinert zu werden (W8)
*
* Das Label ist mit Rahmen 317 px breit; auf 320 px breiten Bildschirmen hat die Inhaltsspalte weniger. Es wird
* nur nach links verschoben, rechts bleiben 4 px Abstand, links notfalls keiner.
*/
function wpsg_garanTooltipPosition() {
var vw = document.documentElement.clientWidth;
document.querySelectorAll('.wpsg_product_garan > .tooltip').forEach(function(tooltip) {
tooltip.style.left = '';
var rect = tooltip.getBoundingClientRect();
var over = rect.right - (vw - 4);
if (over > 0) tooltip.style.left = (parseFloat(getComputedStyle(tooltip).left) - Math.min(over, rect.left)) + 'px';
} );
} // function wpsg_garanTooltipPosition()
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', wpsg_garanTooltipPosition); else wpsg_garanTooltipPosition();
window.addEventListener('resize', wpsg_garanTooltipPosition);
jQuery(document).ajaxComplete(wpsg_garanTooltipPosition);
/**
* GARAN-Label per Tipp und Tastatur (K69)
*
* Der erste Tipp klappt das Label auf, der zweite folgt dem Link zur EU-Seite. Maus: Darüberfahren zeigt es,
* Klick folgt dem Link. Tastatur: Der Fokus zeigt es (CSS :focus-visible), Enter folgt dem Link.
* Escape oder ein Tipp daneben schließt es.
*/
var wpsg_garanPointer = '';
function wpsg_garanSet(label, open, dismissed) {
label.classList.toggle('is-open', open);
label.classList.toggle('is-dismissed', !!dismissed);
label.setAttribute('aria-expanded', ((open)?'true':'false'));
} // function wpsg_garanSet(label, open, dismissed)
document.addEventListener('pointerdown', function(event) { wpsg_garanPointer = event.pointerType; }, true);
document.addEventListener('keydown', function(event) {
wpsg_garanPointer = '';
if (event.key === 'Escape') document.querySelectorAll('a.wpsg_product_garan').forEach(function(label) { if (label.classList.contains('is-open') || label === document.activeElement) wpsg_garanSet(label, false, true); } );
}, true);
document.addEventListener('click', function(event) {
var label = event.target.closest('a.wpsg_product_garan');
document.querySelectorAll('a.wpsg_product_garan.is-open').forEach(function(open) { if (open !== label) wpsg_garanSet(open, false); } );
if (!label || (wpsg_garanPointer !== 'touch' && wpsg_garanPointer !== 'pen')) return;
if (!label.classList.contains('is-open')) {
event.preventDefault();
wpsg_garanSet(label, true);
}
} );
document.addEventListener('focusout', function(event) { if (event.target.matches && event.target.matches('a.wpsg_product_garan')) event.target.classList.remove('is-dismissed'); } );