PageSourceSearch

https://www.slivki.by/js/subscription.js?v=55

js slivki.by collected 2026-09-29 22:29:15 UTC 10,224 bytes, 288 lines download raw bytes

1function showModalSubscriptionProcess(message) {
2    $('#subscriptionProcess').modal('show');
3    $(this).find('.message').html(message);
4}
5
6function hideModalSubscriptionProcess() {
7    $('#subscriptionProcess').modal('hide');
8}
9
10let urlParams = new URLSearchParams(window.location.search);
11
12if (urlParams.get('checkOrder') != undefined || urlParams.get('status') === 'successful' && urlParams.get('codesCount') === null) {
13    $('#subscriptionSuccess').modal('show');
14}
15
16if (urlParams.get('show') === 'demo') {
17    let popupDemoSubscrBtn = $('#popupDemoSubscrBtn');
18    $('#cardSubscriptionID').val(popupDemoSubscrBtn.attr('data-id'));
19    popupDemoSubscrBtn.trigger('click');
20}
21
22$('#subscriptionSuccess').on('hidden.bs.modal', function () {
23    window.history.replaceState(null, null, window.location.pathname);
24});
25
26function initSubscription() {
27    $('.subscribe-block .select-credit-card-control input').change(function () {
28        $('.subscribe-block .select-credit-card-control').removeClass('active');
29        $(this).closest('.select-credit-card-control').addClass('active');
30    });
31    $('#subscriptionForm').submit(function () {
32        $.get($(this).attr('action') + '/' + $('.subscribe-block .select-credit-card-control input:checked').val());
33        return false;
34    });
35    $('.subscription-form #addNewCard').click(function () {
36        $.get($(this).closest('form').attr('action')).done(function (redirectURL) {
37            document.location = redirectURL;
38        });
39    });
40}
41
42initSubscription();
43
44
45$('.js-subscribe-btn').on('click', function () {
46    let thisSubscriptionInfo = $(this).closest('.subscription-card').find('.subscription-info').html();
47    let popupSubscriptionInfo = $('.js-subscription-confirm-box').find('.subscription-info');
48
49    if ($(this).hasClass('disabled')) {
50        return false;
51    }
52
53    let subscriptionPlanID = $(this).data('id');
54
55    $('.modal').modal('hide');
56    $('#cardSubscriptionID').val(subscriptionPlanID);
57    popupSubscriptionInfo.html(thisSubscriptionInfo);
58    if (subscriptionPlanID == 24) {
59        $('.js-subscription-card').find('.subscription-codes').addClass('d-none');
60    }
61    $('.js-subscription-card').modal('show');
62    return false;
63});
64
65let subscriptionLegalRadio = $('.subscription-legal-radio');
66
67if (subscriptionLegalRadio.length) {
68    $('.subscription-legal-radio:checked').closest('.subscribe-legal-info').addClass('active');
69    subscriptionLegalRadio.on('click', function () {
70        $('.subscribe-legal-info').removeClass('active');
71        $(this).closest('.subscribe-legal-info').addClass('active');
72    });
73}
74
75$('.js-subscribe-for-legal-btn').on('click', function () {
76    $('.modal').modal('hide');
77    let thisSubscriptionInfo = $('.subscribe-legal-info.active');
78    let thisSubscriptionInfoType = $('.subscribe-legal-card-type').html();
79    let subscriptionLegalRate = thisSubscriptionInfo.find('.subscription-legal-rate');
80    let thisSubscriptionInfoDescr = thisSubscriptionInfo.find('.subscribe-legal-info-descr');
81    let popupSubscriptionInfo = $('.js-subscription-confirm-box').find('.subscription-info');
82    let checked = $('[name=forLegalRadio]:checked');
83    let subscriptionPlanID = checked.val();
84
85    if ($(this).hasClass('disabled')) {
86        return false;
87    }
88
89    $('#cardSubscriptionID').val(subscriptionPlanID);
90
91    popupSubscriptionInfo.html(thisSubscriptionInfoDescr.clone());
92    popupSubscriptionInfo.prepend(subscriptionLegalRate.clone().removeClass('custom-control-label'));
93    popupSubscriptionInfo.prepend('<h5 class="subscribe-legal-card-type font-size-1250 sf-bold-font m-0 mb-3 text-uppercase">' + thisSubscriptionInfoType + '</h5>');
94
95    $('.js-subscription-card').modal('show');
96    return false;
97});
98
99$('#popupDemoSubscrBtn').on('click', function () {
100    $('#cardSubscriptionID').val($(this).attr('data-id'));
101});
102
103function subscriptionSubscribe() {
104    showModalSubscriptionProcess('Пожалуйста, подождите. Идет подписка.');
105
106    fetch('/subscription', {
107        method: 'POST',
108        body: JSON.stringify({
109            planId: $('#cardSubscriptionID').val(),
110        })
111    }).then(function (response) {
112        return response.json();
113    }).then(function (result) {
114        if (result.error) {
115            hideModalSubscriptionProcess();
116            showNewMessageBox('Подписка', 'Произошла ошибка');
117
118            return false;
119        }
120
121        if (result.hasOwnProperty('redirectUrl')) {
122            hideModalSubscriptionProcess();
123
124            if (result.redirectUrl) {
125                document.location = result.redirectUrl;
126            } else {
127                document.location.replace(window.location.origin + window.location.pathname + '?status=successful');
128            }
129
130            return false;
131        } else {
132            checkStatusAfterSubscription();
133        }
134    });
135}
136
137let subscriptionStatus = $('.subscription-status').val();
138let currentNumberAttempts = 0;
139let NumberAttempts = 50;
140
141async function checkStatusSubscription() {
142    let responseCheckStatus = await fetch('/subscription/status');
143    let responseCheckStatusJSON = await responseCheckStatus.json();
144
145    try {
146        if (responseCheckStatus.status === 200) {
147            if (responseCheckStatusJSON.subscribedStatus === 'CANCELED') {
148                subscriptionSubscribe();
149            } else if (currentNumberAttempts <= NumberAttempts) {
150                setTimeout(await checkStatusSubscription, 800);
151                currentNumberAttempts++;
152
153                if (currentNumberAttempts >= NumberAttempts) {
154                    hideModalSubscriptionProcess();
155                    showNewMessageBox('Ой! Что-то пошло не так', 'Попробуйте еще раз');
156                    return false;
157                }
158            }
159        }
160    } catch (e) {
161        hideModalSubscriptionProcess();
162        showNewMessageBox('Ой! Что-то пошло не так', 'Попробуйте еще раз');
163    }
164}
165
166async function checkStatusAfterSubscription() {
167    let responseCheckStatus = await fetch('/subscription/status');
168    let responseCheckStatusJSON = await responseCheckStatus.json();
169
170    try {
171        if (responseCheckStatus.status === 200) {
172            if (responseCheckStatusJSON.subscribedStatus === 'ACTIVE') {
173
174                document.location.replace(window.location.origin + window.location.pathname + '?status=successful');
175                return false;
176            } else if (currentNumberAttempts <= NumberAttempts) {
177                setTimeout(await checkStatusAfterSubscription, 800);
178                currentNumberAttempts++;
179
180                if (currentNumberAttempts >= NumberAttempts) {
181                    hideModalSubscriptionProcess();
182                    showNewMessageBox('Ой! Что-то пошло не так', 'Попробуйте еще раз');
183
184                    return false;
185                }
186            }
187        }
188    } catch (e) {
189        hideModalSubscriptionProcess();
190        showNewMessageBox('Ой! Что-то пошло не так', 'Попробуйте еще раз');
191    }
192}
193
194async function updateSubscription() {
195    try {
196        let response = await fetch('/subscription/cancel', {
197            method: 'PATCH'
198        });
199
200        if (response.status === 204) {
201            await checkStatusSubscription();
202        }
203
204    } catch (e) {
205        hideModalSubscriptionProcess();
206        showNewMessageBox('Ой! Что-то пошло не так', 'Попробуйте еще раз');
207    }
208}
209
210$('.js-pay-subscription-btn').on('click', function () {
211
212    if ($(this).hasClass('disabled')) {
213        return false
214    }
215
216    if (subscriptionStatus) {
217        $('.modal').modal('hide');
218        showModalSubscriptionProcess('Пожалуйста, подождите. Идет обновление подписки.');
219        updateSubscription();
220    } else {
221        $('.modal').modal('hide');
222        subscriptionSubscribe();
223
224        return false;
225    }
226});
227
228if ($('#clickSubscribeBtn').length) {
229    let subscriptionPlanID = $('#clickSubscribeBtn').val();
230    if ($('#buttonDemoTarif').length == 0) {
231        $('#alertPopupSubscription').modal();
232        ym(20933521, 'reachGoal', 'popup-subs-noone');
233    }
234    if ($('.js-subscribe-btn[data-id=' + subscriptionPlanID + ']').length && subscriptionPlanID != 1) {
235        $('.js-subscribe-btn[data-id=' + subscriptionPlanID + ']').trigger('click');
236    } else if ($('#defaultCheck' + subscriptionPlanID).length) {
237        $('#defaultCheck' + subscriptionPlanID).trigger('click');
238        $('.js-subscribe-for-legal-btn').trigger('click');
239    }
240}
241
242$('#offerSubscriptionButton').on('click', function () {
243    window.location.href = '/subscription-landing/' + $('#offerID').val() + '/' + parseInt($.trim($('#units').text()));
244});
245
246$('#unsubscribeBtn').on('click', function () {
247    $('#slivkiConfirmPopupUnscribed').modal('show')
248});
249
250$('.no-unscribed-popup').click(function () {
251    ym(20933521, 'reachGoal', 'popup-cancel-subs-stay');
252});
253
254$('.yes-unscribed-popup').click(function () {
255    showProgress('Отписка...');
256
257    fetch('/subscription/cancel', {
258        method: 'PATCH'
259    }).then(function () {
260        location.reload();
261
262        ym(20933521, 'reachGoal', 'popup-cancel-subs-undo');
263    });
264});
265
266if ($('#popupSubscribe').length) {
267
268    $('#popupSubscribe').on('show.bs.modal', function () {
269        ga('send', 'event', 'popup-subscribe-index-page', 'appeared');
270        if (typeof yaCounter20933521 !== 'undefined') {
271            yaCounter20933521.reachGoal('popup-subscribe-index-page-appeared');
272        }
273    });
274
275    $('#popupSubscribe').on('hidden.bs.modal', function () {
276        ga('send', 'event', 'popup-subscribe-index-page', 'closed');
277        if (typeof yaCounter20933521 !== 'undefined') {
278            yaCounter20933521.reachGoal('popup-subscribe-index-page-closed');
279        }
280    });
281
282    $('#popupSubscribeBtn').on('click', function () {
283        ga('send', 'event', 'popup-subscribe-index-page', 'click');
284        if (typeof yaCounter20933521 !== 'undefined') {
285            yaCounter20933521.reachGoal('popup-subscribe-index-page-click');
286        }
287    });
288}

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.