File: D:/HostingSpaces/Eurotools/euro-tools.nl/resources/assets/js/site/product.js
/* ==========================================================================
Navigation handler
========================================================================== */
/**
* Main navigation
*/
var Product = {
// Initialize click event
init: function () {
$('body.categories .order-box .increase').bind('click', function (ev) {
Product.updateProductValue(1);
ev.preventDefault();
return false;
});
$('body.categories .order-box .decrease').bind('click', function (ev) {
Product.updateProductValue(-1);
ev.preventDefault();
return false;
});
$('body.categories .order-box .amount-box .amount').bind('change', function (ev) {
Product.updateProductValue(0);
return false;
});
},
updateProductValue: function (update) {
var normalPrice = parseFloat($('body.categories .product-right .right .price').html().replace(/,/, '.'));
var el = $('body.categories .order-box .amount');
var amount = parseInt(el.val());
if (amount == '' || isNaN(amount) || amount <= 0) {
amount = 1;
}
if (amount + update > 0) {
amount += update;
el.val(amount);
}
var priceElement = $('body.categories .product-right .left .price');
var newPrice = normalPrice * amount;
var oldPrice = normalPrice * amount;
if ($('body.categories .product-right .right span.staffel_price').length > 0) {
var staffelpriceElement = $('body.categories .product-right .left .staffeldiscount-price');
var staffelPrice = parseFloat($('body.categories .product-right .right span.staffel_price').html().replace(/,/, '.'));
var staffelAmount = parseFloat($('body.categories .product-right .right .staffel').html());
if (amount >= staffelAmount) {
$('body.categories .product-right').addClass('staffel');
$('body.categories .product-right .no-staffeldiscount-message').hide();
$('body.categories .product-right .staffeldiscount-message').show();
$('body.categories .product-right .staffeldiscount-price').show();
newPrice = staffelPrice * amount;
staffelpriceElement.html('€' + parseFloat(oldPrice).toFixed(2));
} else {
$('body.categories .product-right').removeClass('staffel');
$('body.categories .product-right .no-staffeldiscount-message').show();
$('body.categories .product-right .staffeldiscount-message').hide();
$('body.categories .product-right .staffeldiscount-price').hide();
}
}
var newEuro = Math.floor(newPrice);
var newCents = Math.round(newPrice % 1 * 100);
priceElement.html('€ ' + newEuro + '<span>' + (newCents < 10 ? '0' + newCents : newCents) + '</span>');
}
};
Product.init();