PageSourceSearch

https://endurotrails.pl/static/lib/base-shop/js/shop.js

js endurotrails.pl collected 2026-10-06 20:27:55 UTC 7,418 bytes, 247 lines download raw bytes

1var shopBasket;
2
3$(function () {
4    inputCounterInit();
5    shopBasket = new Basket();
6    shopBasket.init();
7
8});
9
10function Basket() {
11    this.basketUrl = BASKET_URL;
12    this.basketUpdateTimeout;
13
14    this.init = function () {
15        var _this = this;
16
17        this.tooltips();
18
19        $('form.shop-add-to-basket').bind('submit', function () {
20            var $form = $(this);
21            _this.addToBasket($form);
22
23            return false;
24        });
25
26        $('.shop-update-basket input').bind('change', function () {
27            var $form = $(this).closest('form');
28
29            $('#progressBar').remove();
30            var progress = false;
31            var wrapper = $('#container-page'),
32                progressBar = $('<div></div>').attr('id', 'progressBar').addClass('progressbar').css({width: 0});
33
34            var speed = 3000;
35
36            clearTimeout(_this.basketUpdateTimeout);
37
38            wrapper.prepend(progressBar);
39            progressBar.stop().animate({
40                width: "100%"
41            }, speed, function () {
42
43            });
44
45            _this.basketUpdateTimeout = setTimeout(function () {
46                $form.submit();
47            }, speed);
48
49            return false;
50        });
51    };
52
53    this.addToBasket = function ($form) {
54        var _this = this;
55
56        $.ajax({
57            url: this.basketUrl + '/add',
58            method: "POST",
59            data: $form.serialize(),
60            success: function (data, textStatus, jqXHR) {
61
62                var content = data.message,
63                    footer = '';
64
65                if (data.status === 1) {
66                    footer = '<button type="button" class="btn btn-default pull-left" data-dismiss="modal">' + getLang('basket.modal.btn.continue') + '</button>' +
67                        '<a href="' + _this.basketUrl + '" class="btn btn-primary">' + getLang('basket.modal.btn.go-to-basket') + '</a>';
68                } else {
69                    content = '<div class="text-danger">' + content + '</div>';
70                    footer = '<button type="button" class="btn btn-default" data-dismiss="modal">' + getLang('modal.btn.close') + '</button>';
71                }
72
73                modalBox(getLang('basket.modal.header'), content, footer);
74
75                _this.updateLayout(data.basketInfo);
76            },
77            error: function (jqXHR, textStatus, errorThrown) {
78                var data = jqXHR.responseJSON;
79                _this.updateLayout(data.basketInfo);
80            }
81        });
82    };
83
84    this.updateLayout = function (options) {
85        var _this = this;
86        var text;
87
88        if (typeof options === 'undefined') {
89            return;
90        }
91
92        if (typeof options.miniBasketBox !== 'undefined') {
93            $('.mini-basket-box').html(options.miniBasketBox);
94            _this.initScrollBar();
95            delete options["miniBasketBox"];
96        }
97
98        $.each(options, function(k, v) {
99            $('.shop-' + k).html(v);
100        });
101    };
102
103    this.initScrollBar = function() {
104        if (!isDesktop()) return;
105        $('.mini-basket-box .tinyscrollbar').tinyscrollbar();
106    }
107
108    this.summaryUpdate = function ($form) {
109        var _this = this;
110
111        var $container = $('.delivery-alert-container'),
112            $shopBaskeSummary = $('.shop-basket-summary');
113        $container.html('');
114
115        $shopBaskeSummary.animate({opacity: 0.4}, 300);
116        $.ajax({
117            url: this.basketUrl + '/summary',
118            method: "POST",
119            data: $form.serialize(),
120            success: function (data, textStatus, jqXHR) {
121                $shopBaskeSummary.html(data.summaryBox).animate({opacity: 1}, 300);
122
123                // $form.find(':submit').prop('disabled', false);
124            },
125            error: function (jqXHR, textStatus, errorThrown) {
126                var data = jqXHR.responseJSON;
127
128                var $alert = $('<div class="alert alert-danger"></div>');
129                $alert.html(data.message);
130                $container.append($alert);
131
132                $shopBaskeSummary.animate({opacity: 1}, 300);
133                // $form.find(':submit').prop('disabled', true);
134            }
135        });
136    };
137
138    this.tooltips = function() {
139        $(function () {
140            $('[data-toggle="shop-tooltip"]').tooltip();
141        })
142    }
143}
144
145function ProductVariants(containerParam, variantsPrices) {
146    this.container = $(containerParam);
147    this.variantsPrices = JSON.parse($.base64.decode(variantsPrices));
148    this.productPriceDiv = '.product-price-net';
149    this.productBasePrice = 0;
150    this.productTaxRate = 0;
151    this.productCurrency = 'PLN';
152
153    this.bindChangeActions = function () {
154        var $this = this;
155
156        $this.container.on('touch change', '[name*="variant"]', function () {
157            $this.recalculatePrice();
158        });
159    };
160
161    this.recalculatePrice = function () {
162        var $this = this,
163            variantTotalPrice = parseFloat($this.productBasePrice);
164
165        $this.container.find('[name*="variant"]').each(function () {
166
167            var variantId = parseInt($(this).attr('name').toString().replace('variant[', '').replace(']', ''));
168            var variantOptionId = parseInt($(this).val());
169
170            if (!variantId || !variantOptionId) {
171                return;
172            }
173
174            if (typeof $this.variantsPrices[variantId] !== 'undefined' && typeof $this.variantsPrices[variantId][variantOptionId] !== 'undefined') {
175                variantTotalPrice += parseFloat($this.variantsPrices[variantId][variantOptionId]);
176            }
177        });
178
179        variantTotalPrice = variantTotalPrice.toFixed(2);
180        $('.shop-product-price-net').html(variantTotalPrice.replace('.', ',') + ' ' + $this.productCurrency);
181    };
182
183
184    this.init = function () {
185        var $this = this;
186
187        this.bindChangeActions();
188    };
189}
190
191function inputCounterInit() {
192    var input = $(".input-qty, .input-quantity, .form-group-quantity input, input[name=quantity]"),
193        less = $(".quantity-dec"),
194        more = $(".quantity-inc");
195
196    less.click(function () {
197        var input = $(this).parent().find("input[type=text]");
198        var v = parseInt(input.val());
199        if (isNaN(v))
200            v = 1;
201        else if (--v <= 0) {
202            return;
203        }
204
205        input.val(v);
206        input.trigger("change");
207        return false;
208    });
209
210    more.click(function () {
211        var input = $(this).parent().find("input[type=text]");
212        var v = parseInt(input.val());
213        if (isNaN(v))
214            v = 1;
215        else
216            v++;
217        input.val(v);
218        input.trigger("change");
219        return false;
220    });
221
222    input.bind('keyup change click', function (e) {
223        var value = $(this).val();
224
225        if (value.match(/^[0-9]+$/)) {
226            if (value >= 100000) {
227                value = 100000;
228            } else if (value <= 0) {
229                value = 1;
230            }
231
232            $(this).val(value);
233            $(this).data("previousValue", value);
234        } else {
235            $(this).val($(this).data("previousValue"));
236        }
237    });
238
239    input.add('.form-group-quantity button').bind('focus blur', function (e) {
240        if (e.type === 'focus') {
241            $(this).closest('div').addClass('focused');
242        }
243        else if (e.type === 'blur') {
244            $(this).closest('div').removeClass('focused');
245        }
246    });
247}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.