PageSourceSearch

https://hnojik.cz/wp-content/plugins/toret-ceska-posta/public/assets/js/public.js?ver=3.4.1

js hnojik.cz collected 2026-10-08 05:58:30 UTC 10,238 bytes, 281 lines download raw bytes

1jQuery(document).ready(function ($) {
2
3    sessionStorage.tcp_is_selected = false;
4    let isWidgetOpen = false;
5
6    function waitForOverlay() {
7        const overlay = document.getElementById('tcp-popup-select-pickup-point-overlay');
8        if (!overlay) {
9            setTimeout(waitForOverlay, 100);
10            return;
11        }
12        watchOverlay();
13    }
14
15    let overlayObserver = null;
16    let skipNextObserver = false;
17
18    function watchOverlay() {
19        const overlay = document.getElementById('tcp-popup-select-pickup-point-overlay');
20        if (!overlay) return;
21
22        if (overlayObserver) overlayObserver.disconnect();
23
24        let lastDisplay = overlay.style.display;
25
26        overlayObserver = new MutationObserver(function () {
27            const current = overlay.style.display;
28
29            if (current === 'flex') {
30                isWidgetOpen = true;
31            } else {
32                isWidgetOpen = false;
33            }
34
35            if (current === 'flex' && lastDisplay !== 'flex') {
36                if (!skipNextObserver) {
37                    init_dialog_direct();
38                }
39                skipNextObserver = false;
40            }
41            lastDisplay = current;
42        });
43
44        overlayObserver.observe(overlay, { attributes: true, attributeFilter: ['style'] });
45    }
46
47    waitForOverlay();
48
49    function isShippingVisible() {
50        return $('.woocommerce-shipping-methods').is(':visible');
51    }
52
53    function isTcpPickup(value) {
54        if (!value) return false;
55        const isBalikovna = value.indexOf('toret_tcp_balikovna') !== -1 && value.indexOf('toret_tcp_balikovna_na_adresu') === -1;
56        const isNaPosta = value.indexOf('toret_tcp_napostu') !== -1;
57        return isBalikovna || isNaPosta;
58    }
59
60    function init_dialog_direct() {
61        let method = jQuery('input[name^="shipping_method"]:checked').val();
62        if (!method) {
63            method = jQuery('input[name^="shipping_method"]').first().val();
64        }
65        let parameter = '';
66
67        if (!method) return;
68
69        if (method.indexOf('toret_tcp_balikovna') !== -1 && method.indexOf('toret_tcp_balikovna_na_adresu') === -1)
70            parameter = 'BALIKOVNY';
71        else if (method.indexOf('toret_tcp_napostu') !== -1)
72            parameter = 'POST_OFFICE';
73
74        if (parameter === '') return;
75
76        let url = 'https://b2c.cpost.cz/locations/?skipLocation=true&type=' + parameter;
77        let popup = document.querySelector('#tcp-popup-select-pickup-point-overlay .torlib-popup-content');
78
79        if (!popup) return;
80
81        popup.innerHTML =
82            '<iframe class="tcp-widget-iframe" title="Výběr místa pro vyzvednutí zásilky" src="' + url + '" allow="geolocation"></iframe>' +
83            '<input type="hidden" name="tcp_selected_shipping" id="tcp_selected_shipping" value="' + method + '"/>';
84    }
85
86    function init_dialog() {
87        if ($('#tcp-popup-select-pickup-point-overlay').css('display') === 'flex') {
88            return;
89        }
90
91        if (!isShippingVisible()) {
92            return;
93        }
94
95        init_dialog_direct();
96        skipNextObserver = true;
97        watchOverlay();
98        jQuery('#tcp-popup-select-pickup-point-overlay').css('display', 'flex');
99        isWidgetOpen = true;
100    }
101
102    function iframeListener(event) {
103        if (event.data.message === 'pickerResult') {
104            let zip = event.data.point.zip;
105            let id = event.data.point.id;
106            let name = event.data.point.name;
107            let city = event.data.point.municipality_name;
108            let address = event.data.point.address;
109            let type = event.data.point.type;
110            let subtype = event.data.point.subtype;
111            let addressArr = address.split(',');
112            let street = addressArr[0];
113
114            let text = id + ';' + name + ';' + city + ';' + street + ';' + zip + ';' + type + ';' + subtype + ';' + address;
115            $('#tcp_message').val(text);
116            $('#tcp_data').val(name + ', ' + address);
117
118            try {
119                const detail = {
120                    code: id, name: name, city: city, street: street,
121                    zipCode: zip, type: type, subtype: subtype,
122                    address: name + ', ' + address,
123                    raw: event.data.point || null
124                };
125                document.dispatchEvent(new CustomEvent('ppl-parcelshop-map', {detail}));
126            } catch (e) {}
127
128            $.post(wcp_localize_tcp.ajaxurl, {action: 'tcp_get_selected_branch', idecko: text}, function (response) {
129                $(checkoutSelected).empty().append(response);
130                sessionStorage.ceskapostaVybranaPobocka = $(checkoutSelected).html();
131                sessionStorage.ceskapostaselected = $('#selected_tcp').val();
132                sessionStorage.tcp_is_selected = true;
133                sessionStorage.tcp_user_closed = 'false';
134
135                closeWidget();
136                $(document.body).trigger('update_checkout');
137            });
138        }
139    }
140
141    window.removeEventListener('message', iframeListener);
142    window.addEventListener('message', iframeListener);
143
144    let checkoutSelected = '#table-tcp';
145
146    $('form.checkout').on('change', 'input[name^="shipping_method"]', function () {
147        if (isShippingVisible()) {
148            let value = this.value;
149
150            sessionStorage.tcp_is_selected = false;
151            sessionStorage.ceskapostaselected = '';
152            sessionStorage.ceskapostaVybranaPobocka = '';
153            sessionStorage.tcp_user_closed = 'false';
154
155            $(checkoutSelected).empty();
156            $('#selected_tcp').val('');
157            $('.tcp-selected-branche-td').html('');
158            $('.table-tcp').html('');
159
160            if (isTcpPickup(value)) {
161                if (wcp_localize_tcp.tcp_show_on_select === 'ok') {
162                    init_dialog();
163                }
164            }
165        }
166    });
167
168    $(document.body).on('updated_checkout', function () {
169        watchOverlay();
170        if (typeof sessionStorage.ceskapostaVybranaPobocka !== "undefined") {
171            $(checkoutSelected).empty().append(sessionStorage.ceskapostaVybranaPobocka);
172            $('#selected_tcp').val(sessionStorage.ceskapostaselected);
173        }
174
175        checkAndOpenPopup();
176    });
177
178    function checkAndOpenPopup() {
179        let value = jQuery('input[name^="shipping_method"]:checked').val();
180        if (!value) {
181            value = jQuery('input[name^="shipping_method"]').first().val();
182        }
183
184        if (isTcpPickup(value)) {
185            if (wcp_localize_tcp.tcp_show_on_select === 'ok') {
186
187                let isAlreadyOpen = ($('#tcp-popup-select-pickup-point-overlay').css('display') === 'flex');
188                let userClosedIt = (sessionStorage.tcp_user_closed === 'true');
189
190                if (isShippingVisible() &&
191                    $(checkoutSelected).html() === '' &&
192                    (!sessionStorage.tcp_is_selected || sessionStorage.tcp_is_selected === 'false') &&
193                    !isAlreadyOpen &&
194                    !userClosedIt
195                ) {
196                    init_dialog();
197                }
198            }
199        }
200    }
201
202    const shippingMethodsContainer = document.querySelector('.woocommerce-shipping-methods');
203    if (shippingMethodsContainer) {
204        const visibilityObserver = new IntersectionObserver((entries) => {
205            entries.forEach(entry => {
206                if (entry.isIntersecting) {
207                    setTimeout(checkAndOpenPopup, 300);
208                }
209            });
210        }, {
211            root: null,
212            threshold: 0.1
213        });
214
215        visibilityObserver.observe(shippingMethodsContainer);
216    } else {
217        const checkoutForm = document.querySelector('form.checkout');
218        if (checkoutForm) {
219            const fallbackObserver = new MutationObserver((mutations) => {
220                if (isShippingVisible()) {
221                    checkAndOpenPopup();
222                }
223            });
224            fallbackObserver.observe(checkoutForm, { attributes: true, subtree: true, attributeFilter: ['style', 'class'] });
225        }
226    }
227
228    jQuery('body').on('click', '#place_order', function () {
229        if ($(checkoutSelected).length) {
230            let val = jQuery('input[name^="shipping_method"]:checked').val();
231            if (!val) {
232                val = jQuery('input[name^="shipping_method"]').first().val();
233            }
234            if (isTcpPickup(val)) {
235                if ($(checkoutSelected).html() === '' && (!sessionStorage.tcp_is_selected || sessionStorage.tcp_is_selected === 'false')) {
236                    alert(wcp_localize_tcp.select_branch_tcp);
237                    return false;
238                }
239            } else {
240                sessionStorage.ceskapostaVybranaPobocka = '';
241                sessionStorage.ceskapostaselected = '';
242                sessionStorage.tcp_is_selected = false;
243            }
244        }
245    });
246
247    jQuery('body').on('click', '.torlib-popup-close', function () {
248        sessionStorage.tcp_user_closed = 'true';
249        closeWidget();
250    });
251
252    var checkout_form = $('form.checkout');
253    checkout_form.on('checkout_place_order', function () {
254        let val = jQuery('input[name^="shipping_method"]:checked').val();
255        if (!val) {
256            val = jQuery('input[name^="shipping_method"]').first().val();
257        }
258
259        if (isTcpPickup(val) && $(checkoutSelected).length) {
260            if ($(checkoutSelected).html() === '' && (!sessionStorage.tcp_is_selected || sessionStorage.tcp_is_selected === 'false')) {
261                alert(wcp_localize_tcp.select_branch_tcp);
262                return false;
263            }
264        }
265        sessionStorage.tcp_is_selected = false;
266        sessionStorage.ceskapostaselected = '';
267        sessionStorage.ceskapostaVybranaPobocka = '';
268        return true;
269    });
270
271    function closeWidget() {
272        const button = document.getElementById('tcp-open-popup-widget');
273        if (button) {
274            const spinner = button.querySelector('.button-spinner');
275            if (spinner) spinner.remove();
276        }
277        jQuery('#tcp-popup-select-pickup-point-overlay').hide();
278        isWidgetOpen = false;
279    }
280
281});

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.