PageSourceSearch

https://www.vetark.co.uk/javascript/cart/cart.js?time=1791193615

js vetark.co.uk collected 2026-10-05 09:47:03 UTC 11,778 bytes, 284 lines download raw bytes

1
2/* Cart */
3
4var Cart = function () {
5    this.init = function () {
6        jQuery.ajax({
7            method: 'GET',
8            url: wsUrls.showMini
9        }).done(function (html) {
10            if (jQuery('header div#mini-cart').length > 0) {                // show mini-cart
11                jQuery('header div#mini-cart').html(html);
12                jQuery('header span#mini-cart-num-items').html(jQuery('header div.single-mini-cart div[itemCart="1"]').length);
13            }
14            if (jQuery('div#spt_mobile_footer div#mini-cart').length > 0) { // show mini-cart mobile
15                jQuery('div#spt_mobile_footer div#mini-cart').html(html);
16            }
17        });
18        if (jQuery('div#cart').length > 0) {                                // show cart
19            jQuery('div#cart').load(wsUrls.show);
20        }
21        if (jQuery('div#static-cart').length > 0) {                         // show static-cart
22            jQuery('div#static-cart').load(wsUrls.showStatic);
23        }
24    };
25    this.add = function (item) {
26        var params = { item: item };
27        this.request('POST', wsUrls.addItem, params);
28        jQuery.notify(addItemToCart, 'success'); // -> javascrit.php -> site_it.php
29    };
30    this.remove = function (id) {                                               // ok
31        var params = { itemId: id };
32        this.request('POST', wsUrls.removeItem, params);
33        jQuery.notify(removeItemToCart, 'success'); // -> javascrit.php -> site_it.php
34    };
35    this.update = function (id, qt) {                                           // ok
36        var params = { itemId: id, qt: qt };
37        this.request('POST', wsUrls.updateItem, params);
38        jQuery.notify(updateCart, 'info'); // -> javascrit.php -> site_it.php
39    };
40    this.empty = function () {                                                  // ok
41        this.request('GET', wsUrls.free, {});
42        jQuery.notify(cartempty, 'info'); // -> javascrit.php -> site_it.php
43    };
44    this.request = function (method, action, params) {
45        var self = this;
46        jQuery.ajax({
47            method: method,
48            url: action,
49            data: params
50        }).done(function () {
51            self.sync();
52        });
53    };
54    this.bind = function () {
55        var self = this;
56        jQuery(document).on('click', '.cart-add-list', function () {
57            let prod = jQuery(this).closest('div.product');
58            let node_id = prod.attr('node_id');
59            let name = prod.find('input#name_product').val();
60            let qt = prod.find('#quantity').val();
61            let config_descriptions = {};
62            prod.find('select.config_descriptions, input.config_descriptions').each(function () {
63                let select = jQuery(this);
64                config_descriptions[select.attr('name')] = select.val();
65            });
66            let image_url = prod.find('img#primary_image').attr('src');
67            let unit_price = prod.find('input#unit_price').val();
68            let item = { node_id: node_id, name: name, config_descriptions: JSON.stringify(config_descriptions), qt: qt, unit_price: unit_price, image_url: image_url };
69            self.add(item);
70        });
71
72        jQuery(document).on('click', '.cart-add', function () {
73            if (jQuery('form#item-form').parsley().validate()) {
74                let prod = jQuery(this).closest('div.product');
75                let node_id = prod.attr('node_id');
76                let name = prod.find('div#name').text();
77                let qt = prod.find('#quantity').val();
78                let config_descriptions = {};
79                prod.find('select.config_descriptions, input.config_descriptions').each(function () {
80                    let select = jQuery(this);
81                    config_descriptions[select.attr('name')] = select.val();
82                });
83                let image_url = prod.find('img#primary_image').attr('src');
84                let unit_price = prod.find('input#unit_price').val();
85                let item = { node_id: node_id, name: name, config_descriptions: JSON.stringify(config_descriptions), qt: qt, unit_price: unit_price, image_url: image_url };
86                self.add(item);
87            }
88        });
89        jQuery(document).on('change', '.cart-update', function () {             // ok
90            let id = jQuery(this).closest('.cart-item').attr('id');
91            let qt = jQuery(this).val();
92            self.update(id, qt);
93            self.updateShippingMethods();
94        });
95        jQuery(document).on('click', '.cart-remove', function () {              // ok
96            let id = jQuery(this).closest('.cart-item').attr('id');
97            self.remove(id);
98            self.updateShippingMethods();
99        });
100        jQuery(document).on('click', '.cart-empty', function () {               // ok
101            //alert('@@@@');
102            self.empty();
103            //self.updateShippingMethods();
104        });
105    };
106    this.sync = function () {
107        var self = this;
108        jQuery.ajax({
109            method: 'GET',
110            url: wsUrls.showMini
111        }).done(function (html) {
112            if (jQuery('header div#mini-cart').length > 0) {                    // show mini-cart
113                jQuery('header div#mini-cart').html(html);
114                let nItems = jQuery('header div.single-mini-cart div[itemCart="1"]').length;
115                jQuery('header span#mini-cart-num-items').html(nItems);
116                if (jQuery('div#cart').length > 0 || jQuery('div#static-cart').length > 0) {
117                    if (jQuery('div#static-cart').length > 0) {
118                        jQuery('div#static-cart').load(wsUrls.showStatic);
119                    }
120                    if (jQuery('div#cart').length > 0) {
121                        jQuery('div#cart').load(wsUrls.show);
122                    }
123
124                    if (nItems === 0) {
125                        window.location.reload();
126                    }
127                }
128            }
129            if (jQuery('div#spt_mobile_footer div#mini-cart').length > 0) {     // show mini-cart mobile
130                jQuery('div#spt_mobile_footer div#mini-cart').html(html);
131            }
132        });
133        if (jQuery('div#cart').length > 0) {                                    // show cart
134            jQuery('div#cart').load(wsUrls.show);
135        }
136    };
137    this.updateShippingMethods = function () {
138
139        jQuery.ajax({
140            method: 'GET',
141            url: '/vetark/update-shipping-methods'
142        }).done(function (data) {
143            $('#shippingMethod').html(data);
144        });
145    }
146};
147
148/* init e load cart */
149
150jQuery(document).ready(function () {
151    var cart = new Cart();
152    cart.init();
153    cart.bind();
154});
155
156/* Stripe */
157jQuery(document).on('click', '.pay-button', function () {
158
159    var payButton = jQuery(this);
160    var responseContainer = payButton.closest('.stripe-button-container').find('.payment-response');
161    var paymentType = payButton.attr('payment-type');
162    var paymentGroup = payButton.attr('payment-group');
163
164    if (paymentType == 'Stripe') {
165        // sessione per il checkout relativo al payment group
166        var createCheckoutSession = function (stripe) {
167            return fetch('/stripe/checkout?paymentGroup=' + paymentGroup, {
168                method: 'POST',
169                headers: {
170                    'Content-Type': 'application/json',
171                },
172                body: JSON.stringify({
173                    checkoutSession: 1  // attributo della request
174                }),
175            }).then(function (result) {
176                console.log(result);
177                return result.json();
178            });
179        };
180        jQuery.get('/stripe/public-key-for-js', {}, function (stripeKey) {
181
182            payButton.disabled = true;
183
184            let stripe = Stripe(stripeKey);
185
186            createCheckoutSession().then(function (data) {
187                if (data.sessionId) {
188                    stripe.redirectToCheckout({
189                        sessionId: data.sessionId,
190                    }).then(handleResult);
191                } else {
192                    handleResult(data);
193                }
194            });
195
196            // errori provenienti dala action checkout
197            var handleResult = function (result) {
198                if (result.error) {
199                    jQuery(responseContainer).html('<p>' + result.error.message + '</p>');
200                }
201                payButton.disabled = false;
202            };
203        });
204    }
205});
206
207
208/* update shipping address */
209
210
211jQuery(document).ready(function () {
212    jQuery(document).on('click', 'a#change-shipping-address', function () {
213        jQuery('div#show-shipping-address').hide();
214        let vals = jQuery('div#show-shipping-address span');
215        jQuery(vals).each(function (i, val) {
216            let el = jQuery(val);
217            jQuery('input#' + el.attr('id').replace('show-', '')).val(el.html());
218        });
219        jQuery('div#show-update-shipping-address').show();
220    });
221    jQuery(document).on('click', 'a#change-shipping-address-none', function () {
222        jQuery('div#show-shipping-address').show();
223        jQuery('div#show-update-shipping-address').hide();
224    });
225    jQuery(document).on('click', 'button#update-shipping-address', function () {
226        jQuery.ajax({
227            method: 'POST',
228            url: wsUrls.updateShippingAddress,
229            data: jQuery('div#show-update-shipping-address input, div#show-update-shipping-address select').serialize()
230        }).done(function (msg) {
231            if (msg == 'Ok') {
232                //if (recheckShippingMethod !== undefined) {
233                //    window.location = wsUrls.recheckShippingMethod;
234                //} else {
235                let vals = jQuery('div#show-update-shipping-address input, div#show-update-shipping-address select');
236                jQuery(vals).each(function (i, val) {
237                    let el = jQuery(val);
238                    if (el.prop('tagName') == 'INPUT') {
239                        jQuery('span#show-' + el.attr('id')).html(el.val());
240                    } else {
241                        jQuery('span#show-' + el.attr('id')).html(jQuery('#' + el.attr('id') + ' option[value=' + el.val() + ']').text());
242                    }
243                });
244                jQuery('div#show-shipping-address').show();
245                jQuery('div#show-update-shipping-address').hide();
246
247                jQuery.ajax({
248                    method: 'GET',
249                    url: wsUrls.getShippingRule,
250
251                }).done(function (msg) {
252                    //console.log("AAAA "+msg);
253                    jQuery('span#shippingRule').html(msg);
254
255                    var cart = new Cart();
256                    cart.updateShippingMethods();
257
258                });
259                //}
260            } else {
261                jQuery('div#update-shipping-address-error').show().delay(1000).hide();
262            }
263        });
264    });
265
266
267    var spt_virtual_shop_cart = '.spt_virtual_shop_cart';
268    var spt_virtual_shop_cart_box = '#spt_virtual_shop_cart';
269    //   var spt_virtual_shop_cart_form_submit = '#spt_virtual_shop_cart form input[type="submit"]';
270    $(document).on('click', spt_virtual_shop_cart, function (e) {
271        e.preventDefault();
272        var self = $(this);
273        self.parent().find('.spt_active').removeClass('spt_active');
274        $(spt_virtual_shop_cart_box).addClass('spt_active');
275        return false;
276    });
277    $(document).on('click', function (e) {
278        if (!$(spt_virtual_shop_cart).is(e.target)) {
279            $(spt_virtual_shop_cart_box).removeClass('spt_active');
280        } else if (!$(spt_virtual_shop_cart_box).is(e.target)) {
281            $(spt_virtual_shop_cart_box).removeClass('spt_active');
282        }
283    });
284});

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.