Working book shop.
[prawokultury.git] / shop / static / shop / shop.js
1 $(function() {
2
3     $('.cost-items').each(function() {
4
5         var $items = $(this);
6         var price = parseFloat($items.attr('data-cost-price')) * 100;
7         var cost_const = parseFloat($items.attr('data-cost-const')) * 100;
8         var cost_per_item = parseFloat($items.attr('data-cost-per-item')) * 100;
9
10         var decimal_separator = $items.attr('data-decimal-separator');
11
12         var money = function(amount) {
13             return amount.toFixed(2).replace(".", decimal_separator);
14         }
15
16         var update_costs = function() {
17             var items = $items.val();
18             if (items < 1)
19                 items = 1;
20             var total_costs = cost_per_item * items + cost_const;
21             var final = price * items + total_costs;
22             $("#cost-costs").text(money(total_costs / 100) + " zł");
23             $("#cost-final").text(money(final / 100) + " zł");
24         }
25
26         $items.change(update_costs);
27         update_costs();
28
29     });
30
31 });