PageSourceSearch

https://sklepwaneko.pl/modules/dpdshipping/views/js/dpdshipping-common.js?2.3.3

js sklepwaneko.pl collected 2026-10-02 23:59:30 UTC 15,564 bytes, 415 lines download raw bytes

1/*
2 * Copyright 2024 DPD Polska Sp. z o.o.
3 *
4 * NOTICE OF LICENSE
5 *
6 * Licensed under the EUPL-1.2 or later.
7 * You may not use this work except in compliance with the Licence.
8 *
9 * You may obtain a copy of the Licence at:
10 * https://joinup.ec.europa.eu/software/page/eupl
11 * It is also bundled with this package in the file LICENSE.txt
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the Licence is distributed on an AS IS basis,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the Licence for the specific language governing permissions
17 * and limitations under the Licence.
18 *
19 * @author    DPD Polska Sp. z o.o.
20 * @copyright 2024 DPD Polska Sp. z o.o.
21 * @license   https://joinup.ec.europa.eu/software/page/eupl
22 */
23
24// noinspection JSUnresolvedReference
25
26$(document).ready(function () {
27    handleDpdShippingPudo();
28    $(document).on('click', '.delivery_option_radio', handleDpdShippingPudo);
29    $(document).on('click', 'input[name^="delivery_option"]', handleDpdShippingPudo);
30
31    $('.dpdshipping-pudo-container').parent().css('border-right', '0');
32    $('.dpdshipping-pudo-cod-container').parent().css('border-right', '0');
33    $('.dpdshipping-pudo-swipbox-container').parent().css('border-right', '0');
34
35    $(document).on('click', '.dpdshipping-pudo-open-map-btn', (e) => showModal(e, '#dpdshippingPudoModal'));
36    $(document).on('click', '.dpdshipping-pudo-change-map-btn', (e) => showModal(e, '#dpdshippingPudoModal'));
37
38    $(document).on('click', '.dpdshipping-pudo-cod-open-map-btn', (e) => showModal(e, '#dpdshippingPudoCodModal'));
39    $(document).on('click', '.dpdshipping-pudo-cod-change-map-btn', (e) => showModal(e, '#dpdshippingPudoCodModal'));
40
41    $(document).on('click', '.dpdshipping-pudo-swipbox-open-map-btn', (e) => showModal(e, '#dpdshippingPudoSwipBoxModal'));
42    $(document).on('click', '.dpdshipping-pudo-swipbox-change-map-btn', (e) => showModal(e, '#dpdshippingPudoSwipBoxModal'));
43
44    dpdshippingStripDataToggle();
45
46    var _dpdshippingRefreshTimer = null;
47    $(document).ajaxComplete(function (event, xhr, settings) {
48        dpdshippingStripDataToggle();
49        if (!window._dpdshippingCustomCheckout) {
50            return;
51        }
52        if (settings.url && settings.url.indexOf('dpdshipping') !== -1) {
53            return;
54        }
55        clearTimeout(_dpdshippingRefreshTimer);
56        _dpdshippingRefreshTimer = setTimeout(function () {
57            if (typeof dpdshippingRefreshIframeUrls === 'function') {
58                dpdshippingRefreshIframeUrls(window._dpdshippingCountryIdOverride || null);
59            }
60            if (typeof handleDpdShippingPudo === 'function') {
61                handleDpdShippingPudo();
62            }
63        }, 700);
64    });
65});
66
67function dpdshippingSavePudoCode(pudoCode, modal) {
68    $.ajax({
69        url: dpdshipping_pickup_save_point_ajax_url,
70        type: 'POST',
71        data: {
72            dpdshipping_token: dpdshipping_token,
73            dpdshipping_csrf: dpdshipping_csrf,
74            dpdshipping_id_cart: dpdshipping_id_cart,
75            dpdshipping_pudo_code: pudoCode
76        },
77        success: function (response) {
78            const resultJson = JSON.parse(response)
79            if (resultJson.success) {
80                $('.dpdshipping-pudo-new-point').css("display", "none");
81                $('.dpdshipping-pudo-selected-point').css("display", "block");
82                dpdshippingEnableOrderProcessBtn();
83            } else {
84                $('.container_dpdshipping_pudo_error').css("display", "block");
85                dpdshippingDisableOrderProcessBtn();
86                console.error('Error:', response);
87            }
88            hideModal(modal);
89        },
90        error: function (error) {
91            console.log('Error:', error);
92            hideModal(modal);
93        }
94    });
95
96    function hideModal(modal) {
97        if (!modal || !modal.length) {
98            return;
99        }
100        setTimeout(function () {
101            if (window.jQuery && jQuery.fn && jQuery.fn.modal) {
102                modal.modal('hide');
103            } else if (window.bootstrap && window.bootstrap.Modal) {
104                var bsModal = window.bootstrap.Modal.getInstance(modal[0] || modal);
105                if (bsModal) bsModal.hide();
106            }
107            setTimeout(function () {
108                modal.removeClass('show in').css('display', 'none');
109                $('body').removeClass('modal-open');
110                $('.modal-backdrop').remove();
111            }, 300);
112        }, 500);
113    }
114
115}
116
117function dpdshippingGetPudoAddress(pudoCode, input) {
118    $.ajax({
119        url: dpdshipping_pickup_get_address_ajax_url,
120        type: 'GET',
121        data: {
122            dpdshipping_token: dpdshipping_token,
123            dpdshipping_csrf: dpdshipping_csrf,
124            dpdshipping_pudo_code: pudoCode
125        },
126        success: function (response) {
127            const resultJson = JSON.parse(response)
128            if (resultJson.success && resultJson.data)
129                input.text(resultJson.data);
130            else
131                console.log('Error:', response);
132        },
133        error: function (error) {
134            console.log('Error:', error);
135        }
136    });
137}
138
139function dpdshippingStripDataToggle() {
140    var btns = document.querySelectorAll(
141        '.dpdshipping-pudo-open-map-btn, .dpdshipping-pudo-change-map-btn,' +
142        '.dpdshipping-pudo-cod-open-map-btn, .dpdshipping-pudo-cod-change-map-btn,' +
143        '.dpdshipping-pudo-swipbox-open-map-btn, .dpdshipping-pudo-swipbox-change-map-btn'
144    );
145    for (var i = 0; i < btns.length; i++) {
146        btns[i].removeAttribute('data-toggle');
147        btns[i].removeAttribute('data-target');
148        btns[i].removeAttribute('data-bs-toggle');
149        btns[i].removeAttribute('data-bs-target');
150    }
151}
152
153function showModal(a, b) {
154    var el = _dpdshippingResolveModalElement(a, b);
155    if (!el) {
156        return;
157    }
158
159    dpdshippingEnsureIframe(el);
160
161    if (window.bootstrap && window.bootstrap.Modal) {
162        _dpdshippingShowModalBs5(el);
163    } else if (window.jQuery && jQuery.fn && jQuery.fn.modal
164        && jQuery.fn.modal.Constructor && jQuery.fn.modal.Constructor.VERSION
165        && parseInt(jQuery.fn.modal.Constructor.VERSION, 10) >= 5) {
166        _dpdshippingShowModalBs5Bridge(el);
167    } else if (window.jQuery && jQuery.fn && jQuery.fn.modal) {
168        _dpdshippingShowModalBs3(el);
169    } else {
170        _dpdshippingShowModalFallback(el);
171    }
172
173    var applyPudo = function () {
174        if (typeof handleDpdShippingPudo === 'function') {
175            handleDpdShippingPudo();
176        }
177    };
178
179    var refreshPromise = (typeof dpdshippingRefreshIframeUrls === 'function')
180        ? dpdshippingRefreshIframeUrls()
181        : null;
182
183    if (refreshPromise && typeof refreshPromise.always === 'function') {
184        refreshPromise.always(applyPudo);
185    } else {
186        applyPudo();
187    }
188}
189
190function _dpdshippingResolveModalElement(a, b) {
191    if (a && typeof a.preventDefault === 'function') {
192        a.preventDefault();
193        a.stopPropagation();
194        return typeof b === 'string' ? document.querySelector(b) : b;
195    }
196    var el = typeof a === 'string' ? document.querySelector(a) : a;
197    return (el instanceof Element) ? el : null;
198}
199
200function _dpdshippingShowModalBs5(el) {
201    window.bootstrap.Modal.getOrCreateInstance(el, { backdrop: 'static', keyboard: false }).show();
202}
203
204function _dpdshippingShowModalBs5Bridge(el) {
205    jQuery.fn.modal.Constructor.getOrCreateInstance(el, { backdrop: 'static', keyboard: false }).show();
206}
207
208function _dpdshippingShowModalBs3(el) {
209    var $el = jQuery(el);
210
211    $el.removeData('bs.modal');
212    $el.off('shown.bs.modal.dpd hidden.bs.modal.dpd');
213
214    $el.on('shown.bs.modal.dpd', function () {
215        el.classList.add('show');
216        el.style.display = 'block';
217    });
218
219    $el.on('hidden.bs.modal.dpd', function () {
220        el.classList.remove('show', 'in');
221        el.style.display = 'none';
222        document.body.classList.remove('modal-open');
223        jQuery('.modal-backdrop').remove();
224    });
225
226    $el.modal({ backdrop: 'static', keyboard: false });
227
228    setTimeout(function () {
229        if ($el.hasClass('in') || el.style.display === 'block') {
230            el.classList.add('show');
231        }
232    }, 50);
233}
234
235function _dpdshippingShowModalFallback(el) {
236    el.style.display = 'block';
237    el.classList.add('show');
238    document.body.classList.add('modal-open');
239
240    var backdrop = document.createElement('div');
241    backdrop.className = 'modal-backdrop fade show in';
242    document.body.appendChild(backdrop);
243
244    var closeBtn = el.querySelector('[data-dismiss="modal"], [data-bs-dismiss="modal"]');
245    if (closeBtn) {
246        closeBtn.addEventListener('click', function () {
247            el.style.display = 'none';
248            el.classList.remove('show');
249            document.body.classList.remove('modal-open');
250            if (backdrop.parentNode) backdrop.parentNode.removeChild(backdrop);
251        }, { once: true });
252    }
253}
254
255var dpdshippingIframeConfig = {
256    'dpdshippingPudoModal': {
257        scriptId: 'dpdshipping-widget-pudo',
258        iframeId: 'dpdshipping-widget-pudo-iframe',
259        urlVar: 'dpdshipping_iframe_url',
260        carrierFn: typeof getDpdshippingIdPudoCarrier === 'function' ? getDpdshippingIdPudoCarrier : null,
261        pointSelectedFn: 'dpdShippingPointSelected'
262    },
263    'dpdshippingPudoCodModal': {
264        scriptId: 'dpdshipping-widget-pudo-cod',
265        iframeId: 'dpdshipping-widget-pudo-cod-iframe',
266        urlVar: 'dpdshipping_iframe_cod_url',
267        carrierFn: typeof getDpdshippingIdPudoCodCarrier === 'function' ? getDpdshippingIdPudoCodCarrier : null,
268        pointSelectedFn: 'dpdShippingCodPointSelected'
269    },
270    'dpdshippingPudoSwipBoxModal': {
271        scriptId: 'dpdshipping-widget-pudo-swipbox',
272        iframeId: 'dpdshipping-widget-pudo-swipbox-iframe',
273        urlVar: 'dpdshipping_iframe_swipbox_url',
274        carrierFn: typeof getDpdshippingIdPudoSwipBoxCarrier === 'function' ? getDpdshippingIdPudoSwipBoxCarrier : null,
275        pointSelectedFn: 'dpdShippingSwipBoxPointSelected'
276    }
277};
278
279function dpdshippingEnsureIframe(modalEl) {
280    var config = dpdshippingIframeConfig[modalEl.id];
281    if (!config) return;
282
283    if (document.getElementById(config.iframeId)) return;
284
285    var iframeUrl = window[config.urlVar];
286    if (!iframeUrl) return;
287
288    var scriptTag = document.getElementById(config.scriptId);
289    var parent = scriptTag ? scriptTag.parentNode : modalEl.querySelector('.modal-body');
290    if (!parent) return;
291
292    var iframe = document.createElement('iframe');
293    iframe.id = config.iframeId;
294    iframe.setAttribute('allow', 'geolocation');
295    iframe.src = iframeUrl;
296    iframe.style.width = '100%';
297    iframe.style.border = 'none';
298    iframe.style.minHeight = '400px';
299    iframe.style.height = '768px';
300
301    if (scriptTag) {
302        scriptTag.parentNode.insertBefore(iframe, scriptTag);
303    } else {
304        parent.appendChild(iframe);
305    }
306}
307
308function handleDpdShippingPudo() {
309
310    $('.container_dpdshipping_pudo_cod_error').css("display", "none");
311    $('.container_dpdshipping_pudo_cod_warning').css("display", "none");
312
313    if (getDpdshippingSelectedCarrier() === getDpdshippingIdPudoCarrier()) {
314        $('.dpdshipping-pudo-new-point').css("display", "block");
315        $('.dpdshipping-pudo-selected-point').css("display", "none");
316
317        $('.dpdshipping-selected-point').text("");
318        const dpdShippingWidgetPudoIframe = $("#dpdshipping-widget-pudo-iframe")
319        dpdShippingWidgetPudoIframe.attr("src", dpdShippingWidgetPudoIframe.attr("src"));
320
321        dpdshippingDisableOrderProcessBtn();
322    } else if (getDpdshippingSelectedCarrier() === getDpdshippingIdPudoCodCarrier()) {
323        $('.dpdshipping-pudo-cod-new-point').css("display", "block");
324        $('.dpdshipping-pudo-cod-selected-point').css("display", "none");
325
326        $('.dpdshipping-cod-selected-point').text("");
327        const dpdShippingWidgetPudoCodIframe = $("#dpdshipping-widget-pudo-cod-iframe")
328        dpdShippingWidgetPudoCodIframe.attr("src", dpdShippingWidgetPudoCodIframe.attr("src"));
329
330        dpdshippingDisableOrderProcessBtn();
331    }  else if (getDpdshippingSelectedCarrier() === getDpdshippingIdPudoSwipBoxCarrier()) {
332        $('.dpdshipping-pudo-swipbox-new-point').css("display", "block");
333        $('.dpdshipping-pudo-swipbox-selected-point').css("display", "none");
334
335        $('.dpdshipping-swipbox-selected-point').text("");
336        const dpdShippingWidgetPudoSwipboxIframe = $("#dpdshipping-widget-pudo-swipbox-iframe")
337        dpdShippingWidgetPudoSwipboxIframe.attr("src", dpdShippingWidgetPudoSwipboxIframe.attr("src"));
338
339        dpdshippingDisableOrderProcessBtn();
340    } else {
341        dpdshippingEnableOrderProcessBtn();
342    }
343}
344
345function getDpdshippingIdPudoCarrier() {
346    return Number(dpdshipping_id_pudo_carrier);
347}
348
349function getDpdshippingIdPudoCodCarrier() {
350    return Number(dpdshipping_id_pudo_cod_carrier);
351}
352
353function getDpdshippingIdPudoSwipBoxCarrier() {
354    return Number(dpdshipping_id_pudo_swipbox_carrier);
355}
356
357function getDpdshippingSelectedCarrier() {
358    let idSelectedCarrier = $('input[name^="delivery_option"]:checked').val();
359
360    if (typeof idSelectedCarrier == 'undefined')
361        return null;
362
363    idSelectedCarrier = idSelectedCarrier.replace(',', '');
364    if (typeof idSelectedCarrier == 'undefined' || idSelectedCarrier === 0)
365        return null;
366
367    return Number(idSelectedCarrier);
368}
369
370function dpdshippingRefreshIframeUrls(idCountry) {
371    if (!idCountry && window._dpdshippingCountryIdOverride) {
372        idCountry = window._dpdshippingCountryIdOverride;
373    }
374    if (typeof dpdshipping_pickup_get_iframe_urls_ajax_url === 'undefined') {
375        return;
376    }
377    var requestData = {
378        dpdshipping_token: dpdshipping_token,
379        dpdshipping_csrf: dpdshipping_csrf
380    };
381    if (idCountry) {
382        requestData.id_country = idCountry;
383    }
384    return $.ajax({
385        url: dpdshipping_pickup_get_iframe_urls_ajax_url,
386        type: 'GET',
387        data: requestData,
388        success: function (response) {
389            var resultJson = typeof response === 'string' ? JSON.parse(response) : response;
390            if (resultJson.success && resultJson.data) {
391                var pudoIframe = document.getElementById('dpdshipping-widget-pudo-iframe');
392                if (pudoIframe && resultJson.data.iframe_url !== dpdshipping_iframe_url) {
393                    pudoIframe.src = resultJson.data.iframe_url;
394                }
395
396                var codIframe = document.getElementById('dpdshipping-widget-pudo-cod-iframe');
397                if (codIframe && resultJson.data.iframe_cod_url !== dpdshipping_iframe_cod_url) {
398                    codIframe.src = resultJson.data.iframe_cod_url;
399                }
400
401                var swipboxIframe = document.getElementById('dpdshipping-widget-pudo-swipbox-iframe');
402                if (swipboxIframe && resultJson.data.iframe_swipbox_url !== dpdshipping_iframe_swipbox_url) {
403                    swipboxIframe.src = resultJson.data.iframe_swipbox_url;
404                }
405
406                dpdshipping_iframe_url = resultJson.data.iframe_url;
407                dpdshipping_iframe_cod_url = resultJson.data.iframe_cod_url;
408                dpdshipping_iframe_swipbox_url = resultJson.data.iframe_swipbox_url;
409            }
410        },
411        error: function (error) {
412            console.error('DPD: Error refreshing iframe URLs:', error);
413        }
414    });
415}

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.