PageSourceSearch

https://mediashop24.ru/catalog/view/javascript/shipping/cdek_official.js

js mediashop24.ru collected 2026-09-28 11:14:43 UTC 5,656 bytes, 119 lines download raw bytes

1'use strict';
2
3$(() => {
4
5    function debounce(func, ms) {
6        let timeout;
7        return function() {
8            clearTimeout(timeout);
9            timeout = setTimeout(() => func.apply(this, arguments), ms);
10        };
11    }
12
13    let mapLoaded = false;
14
15    const updateGlobalData = () => $.getJSON(
16      'index.php?route=extension/shipping/cdek_official/getParams',
17      {},
18      data => {
19          window.cdek = data;
20          if (!mapLoaded && !Object.prototype.hasOwnProperty.call(window, 'CDEKWidget')) {
21              $.getScript(`//cdn.jsdelivr.net/npm/@cdek-it/widget@${data.map_version}`);
22              $('<style data-cdek>' +
23                  '.cdek_btn{' +
24                    'background:rgb(26, 178, 72);' +
25                    'color:rgb(255, 255, 255);' +
26                    'border:none;' +
27                    'padding:5px;' +
28                    'width:100px;' +
29                    'border-radius:5px;' +
30                    'margin:0 5px;' +
31                  '}' +
32                  '</style>').appendTo(document.head);
33              mapLoaded = true;
34          }
35      });
36
37    const addButton = debounce((e) => {
38        $('.cdek_btn').remove();
39        if (e.target.value.indexOf('cdek_official') === -1) return;
40
41        if (e.target.value.split('.')[1].indexOf('office') === -1) return;
42
43        const object = $(e.target);
44
45        if (!object.nextAll('.cdek_btn').length) {
46            object.after($('<button class="cdek_btn" type="button">Нажмите для выбора ПВЗ</button>').on('click', () => {
47                updateGlobalData().done(() => {
48                    if (window.cdekWidget === undefined) {
49                        window.cdekWidget = new window.CDEKWidget({
50                                                                      apiKey: window.cdek.apikey,
51                                                                      defaultLocation: window.cdek.city,
52                                                                      popup: true,
53                                                                      canChoose: true,
54                                                                      hideDeliveryOptions: {
55                                                                          office: false,
56                                                                          door: true,
57                                                                      },
58                                                                      servicePath: 'index.php?route=extension/shipping/cdek_official/map',
59                                                                      onChoose: function(type,
60                                                                        tariff,
61                                                                        address) {
62                                                                          $.post(
63                                                                            'index.php?route=extension/shipping/cdek_official/cacheOfficeCode',
64                                                                            {
65                                                                                office_code: address.code,
66                                                                                office_address: address.address,
67                                                                            })
68                                                                           .done(
69                                                                             updateGlobalData);
70                                                                      },
71                                                                  });
72                    } else {
73                        window.cdekWidget.updateLocation(window.cdek.city);
74                        $.get(
75                          'index.php?route=extension/shipping/cdek_official/map')
76                         .done(data => {
77                             $('#cdek_official_office_error').hide();
78                             window.cdekWidget.updateOfficesRaw(data);
79                         }).fail(xhr => {
80                            const error = JSON.parse(xhr.responseText);
81                            console.debug('[CDEKDelivery] ' + error.message);
82                            $('#cdek_official_office_error')
83                              .text(error.message)
84                              .show();
85                            window.cdekWidget.close();
86                        });
87                    }
88                    window.cdekWidget.open();
89                });
90            }));
91        }
92
93        if (!Object.prototype.hasOwnProperty.call(window, 'cdek') ||
94          !Object.prototype.hasOwnProperty.call(window.cdek, 'office_code') ||
95          window.cdek.office_code === null) {
96            return;
97        }
98        $('.cdek_office_info').remove();
99        $('button.cdek_btn')
100          .before($('<div class="cdek_office_info"></div>')
101                    .html(`[${window.cdek.office_code}] ${window.cdek.office_address}`));
102    }, 100);
103
104    const checkShippingMethods = debounce(() => {
105        const shippingInputs = $('[name="shipping_method"]');
106        if (shippingInputs.length === 0) return;
107
108        shippingInputs.on('change', addButton);
109
110        shippingInputs.each((i, e) => {
111            if (e.type === 'radio' && !e.checked) return;
112            addButton({ target: e });
113        });
114    }, 300);
115
116    $(document).on('ajaxComplete', checkShippingMethods);
117    checkShippingMethods();
118    updateGlobalData();
119});

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.