PageSourceSearch

https://bodo.su/wa-apps/shop/plugins/interfavorites/js/interfavorites.js?1.0.0

js bodo.su collected 2026-09-24 12:08:49 UTC 5,152 bytes, 140 lines download raw bytes

1"use strict";
2
3//Обработка событие клик по товару
4$(document).ready(function () {
5
6    function bypassingHearts(data, hide = false) {
7        $(".wishlist-list-button").each(function (index) {
8                let productId = $(this).attr('data-product-id');
9                let hasClass = $(this).hasClass('wishlist-list-active-button');
10
11                //Есть класс но не входит ИЛИ класса нет но в массив входит
12                if (hasClass && !data.products.includes(productId) ||
13                    !hasClass && data.products.includes(productId)
14                ) {
15                    $(this).toggleClass('wishlist-list-active-button');
16                }
17
18                //Скрываем карточку если передан соотвесвующий сигнал и если сердечко снято
19                if (hide){
20                    if (hasClass && !data.products.includes(productId)){
21                        $(this).parents('li[itemtype="http://schema.org/Product"]').hide();
22                    }
23                    if (!hasClass && data.products.includes(productId)){
24                        location.reload();
25                        return;
26                    }
27                }
28            }
29        );
30    }
31
32
33    function periodicUpdateController(data) {
34        if (window.location.pathname == '/my/wishlist/') {
35            //location.reload();
36            bypassingHearts(data, true)
37            return;
38        }
39        //Изменить сердечко корзины в верхней части
40        changeTotal(data);
41        //Переобход сердечек на странице
42        bypassingHearts(data);
43    }
44
45
46//Циклическая проверка
47    var N = 5000; // 5 секунд
48    setInterval(function () {
49        //Если пользователь не авторизован проверка не требуется
50        if ($("#config").attr('userid') == 0) {
51            return;
52        }
53        let curentCount = $('span.wishlistcount').text();
54        let curentDate = $('span.wishlistcount').attr('lastdate');
55        $.ajax({
56            url: '/addinterfavorites/',
57            method: 'post',
58            dataType: 'json',
59            data: {mode: 'check'},
60            success: function (data) {
61                if (data.data == 'ok') {
62                    if (curentCount == 0 && data.count == 0) {
63                        return;
64                    }
65                    if (curentDate != data.date || data.count != curentCount) {
66                        //Даты не совпадают. Требуется обновление.
67                        periodicUpdateController(data);
68                        return;
69                    }
70                }
71            }
72        });
73        //$('#targetBlock').toggleClass('className');
74    }, N);
75
76
77    function changeTotal(data) {
78        $('span.wishlistcount').html(data.count);
79        $('span.wishlistcount').attr('lastdate', data.date);
80    }
81
82
83//Перехват нажатия на верхнее сердечко ПК
84    $(".pull-left.topFav").on("click", function () {
85        if ($("#config").attr('userid') == 0) {
86            $.fancybox.open($('#datafancybox').html());
87            return false;
88        }
89    });
90
91//Перехват нажатия на верхнее сердечко МОБ
92    $("div#favBlock").on("click", function () {
93        if ($("#config").attr('userid') == 0) {
94            $.fancybox.open($('#datafancybox').html());
95            return false;
96        }
97    });
98
99
100    $(".wishlist-list-button").on("click", function () {
101        //Пользователь не авторизован..
102        if ($("#config").attr('userid') == 0) {
103            $.fancybox.open($('#datafancybox').html());
104            return;
105        }
106        let productid = $(this).attr('data-product-id');
107        let mode = '';
108        if ($(this).hasClass('wishlist-list-active-button')) {
109            mode = 'dell';
110        } else {
111            mode = 'add';
112        }
113        let $this = $(this);
114        $.ajax({
115            url: '/addinterfavorites/',
116            method: 'post',
117            dataType: 'json',
118            data: {productid: productid, mode: mode},
119            success: function (data) {
120                if (data.data == 'ok') {
121                    $this.toggleClass('wishlist-list-active-button');
122                    changeTotal(data);
123
124
125
126                    //если действие из избранного то перезагружаем
127                    if (window.location.pathname == '/my/wishlist/') {
128                        //location.reload();
129                        $this.parents('li[itemtype="http://schema.org/Product"]').hide();
130                    }
131
132                }
133            }
134        });
135        //Запись выбранного значения
136        //let userid = $("#config").attr('userid');
137    });
138})
139;
140

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.