PageSourceSearch

https://www.diving-shop.sk/assets/javascripts/buy_button.js?_=2026-10-07-00-00

js diving-shop.sk collected 2026-10-08 22:59:31 UTC 4,112 bytes, 116 lines download raw bytes

1document.addEventListener('click', function (e) {
2    if (e.target.closest('.buy-button-action')) {
3        const button = e.target.closest('.buy-button-action');
4
5        // kontroly byli již provedeny, můžu přeskočit
6        if (button.dataset.controlComplete === 'true') {
7            button.dataset.controlComplete = 'false';
8            return;
9        }
10        e.preventDefault();
11        e.stopPropagation();
12
13        const product_id = button.dataset.id;
14        const variant_id = parseInt(button.dataset.variantId) || 0;
15
16        const xhr = new XMLHttpRequest();
17        xhr.open('POST', `/request.php?action=Basket_control&main_id=${encodeURIComponent(product_id)}&id_zakaznik=${encodeURIComponent(BS.User.id)}`, true);
18        xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
19        xhr.onload = function () {
20            if (xhr.status === 200) {
21                const data = JSON.parse(xhr.responseText);
22                button.dataset.controlComplete = 'true';
23                
24                if (variant_general && (variant_id === 0 && data.params.choose_variant) && data.success)
25                {
26                    window.location.href = `${data.params.url}?variant=not_selected`;
27                }
28                else
29                {
30                    if (typeof data.params.control_type !== 'undefined') {
31                        switch (data.params.control_type) {
32                            case "restricted_access":
33                                BS.Fce.restricted_popup2(data.params.variables, button);
34                                return;
35                        }
36                    }
37                    var kusy = get_buy_button_count(button);
38
39                    kusy = BS.Basket.calcMultiplesInc(button, kusy);
40                    add_to_basket_events(product_id, variant_id, kusy);
41
42                    // kliknu znovu abych spustil samotné vložení do košíku už s přeskočením kontrol
43                    button.click();
44                }
45            }
46        };
47        xhr.send();
48    }
49    if (e.target.closest('.basket-delete-action'))
50    {
51        e.preventDefault();
52        const button = e.target.closest('.basket-delete-action');
53        const product_id = button.dataset.id;
54        const variant_id = parseInt(button.dataset.variantId) || 0;
55        const qty = button.dataset.qty || 1;
56        remove_from_basket_events(product_id, variant_id, qty);
57        const href = button.getAttribute('href');
58        if (href) {
59            window.location.href = href;
60        }
61    }
62    if(e.target.closest('.product-box-link'))
63    {
64        e.preventDefault();
65        const button = e.target.closest('.product-box-link');
66        const product_id = button.dataset.id;
67        const variant_id = parseInt(button.dataset.variantId) || 0;
68        const location = button.dataset.location;
69        select_item_events(product_id, variant_id, location);
70        const href = button.getAttribute('href');
71        if (href) {
72            if(e.ctrlKey || e.metaKey) {
73                window.open(href);
74            } else {
75                window.location.href = href;
76            }
77        }
78    }
79
80}, {capture: true});
81
82function get_buy_button_count(button)
83{
84    var form = button.closest('form');
85    var countElement = form ? form.querySelector('.prKs, input[name="kusy"]') : null;
86    if (countElement)
87    {
88        return countElement.value;
89    }
90
91    var kusyElement = document.querySelector('#kusy');
92    return kusyElement ? kusyElement.value : null;
93}
94
95function add_to_basket_events(product_id, variant_id, count)
96{
97    // odešlu event do GA
98    BS.Fce.call_conversion_request('add_to_cart', {
99        product_id, variant_id, count
100    });
101}
102
103function remove_from_basket_events(product_id, variant_id, count)
104{
105    // odešlu event do GA
106    BS.Fce.call_conversion_request('remove_from_cart', {
107        product_id, variant_id, count
108    });
109}
110
111function select_item_events(product_id, variant_id, location)
112{
113    BS.Fce.call_conversion_request('select_item', {
114        product_id, variant_id, location
115    });
116}

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.