X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/91117520dbe0336cd5acc91c6d8e23d81141f9df..c66b8465f48325fe5fdc0fcf600f97dcc7bb7a26:/shop/static/shop/shop.js diff --git a/shop/static/shop/shop.js b/shop/static/shop/shop.js new file mode 100755 index 0000000..96b9f9d --- /dev/null +++ b/shop/static/shop/shop.js @@ -0,0 +1,31 @@ +$(function() { + + $('.cost-items').each(function() { + + var $items = $(this); + var price = parseFloat($items.attr('data-cost-price')) * 100; + var cost_const = parseFloat($items.attr('data-cost-const')) * 100; + var cost_per_item = parseFloat($items.attr('data-cost-per-item')) * 100; + + var decimal_separator = $items.attr('data-decimal-separator'); + + var money = function(amount) { + return amount.toFixed(2).replace(".", decimal_separator); + } + + var update_costs = function() { + var items = $items.val(); + if (items < 1) + items = 1; + var total_costs = cost_per_item * items + cost_const; + var final = price * items + total_costs; + $("#cost-costs").text(money(total_costs / 100) + " zł"); + $("#cost-final").text(money(final / 100) + " zł"); + } + + $items.change(update_costs); + update_costs(); + + }); + +});