PageSourceSearch

https://fungiline.ru/wp-content/themes/fungi-theme-v4-8-1/assets/js/product-card.js?ver=1.4.6

js fungiline.ru collected 2026-09-24 13:02:34 UTC 10,739 bytes, 364 lines download raw bytes

1jQuery(document).ready(function($) {
2	
3	$('.add_to_cart_button').each(function () {
4		var $btn = $(this);
5		if (!$btn.data('initial-html')) {
6			$btn.data('initial-html', $btn.html());
7		}
8	});
9	
10    function initializeTooltips() {
11        $('[data-toggle="tooltip"]').each(function(){
12            var options = { html: true };
13
14            if ($(this)[0].hasAttribute('data-type')) {
15                options['template'] =
16                    '<div class="tooltip ' + $(this).attr('data-type') + '" role="tooltip">' +
17                    '   <div class="tooltip-inner"></div>' +
18                    '</div>';
19            }
20
21            $(this).tooltip(options);
22        });
23    }
24	
25	function ensureInCartButton(wrap){
26		if(wrap.find('.in-cart-btn').length === 0){
27			wrap.find('.quantity').after(
28				'<a href="/cart/" class="in-cart-btn">В корзине</a>'
29			);
30		}
31	}
32	function toggleInCartState(wrap, inCart){
33		ensureInCartButton(wrap);
34		wrap.toggleClass('in-cart', inCart);
35	}
36	
37    $('#main-page-bestsellers-block .products-container').each(function () {
38
39        var $this = $(this);
40
41        if (!$this.data('plugin-options')) {
42
43            $this.data('plugin-options', {
44                items: 4,
45                nav: true,
46                dots: false,
47                loop: false,
48                autoplay: false,
49				margin: 10,
50                responsive: {
51                    0: { items: 1,
52                        touchDrag: false,
53                        mouseDrag: false
54
55                    },
56                    576: { items: 2,
57                        touchDrag: false,
58                        mouseDrag: false},
59                    768: { items: 3,
60                        touchDrag: true,
61                        mouseDrag: true},
62                    992: { items: 4,
63                        touchDrag: true,
64                        mouseDrag: true}
65                }
66            });
67
68        }
69
70        if (!$this.hasClass('owl-loaded')) {
71            $this.owlCarousel($this.data('plugin-options'));
72        }
73
74    });
75    function stopOwlPropagation(element) {
76        jQuery(element).on('to.owl.carousel', function(e) { e.stopPropagation(); });
77        jQuery(element).on('next.owl.carousel', function(e) { e.stopPropagation(); });
78        jQuery(element).on('prev.owl.carousel', function(e) { e.stopPropagation(); });
79        jQuery(element).on('destroy.owl.carousel', function(e) { e.stopPropagation(); });
80    }
81    stopOwlPropagation('.owl-carousel');
82    function initializeOwlCarousel() {
83        $('.product-image-slider.owl-carousel').each(function() {
84            let $carousel = $(this);
85
86            if (!$carousel.hasClass('owl-loaded')) {
87                // Инициализируем карусель
88                $carousel.owlCarousel({
89                    items: 1,
90                    loop: false,
91                    margin: 0,
92                    nav: false,
93                    dots: true,
94                    dotsEach: true,
95                    lazyLoad: true,
96                    autoplay: false,
97                    autoplayHoverPause: true,
98                    responsiveRefreshRate: 200,
99                    navRewind: false,
100					autoHeight: false,
101					mouseDrag: false
102                });
103            }
104
105            let totalSlides = $carousel.find('.owl-item:not(.cloned)').length;
106            let isMouseInside = false;
107
108            $carousel.closest('.product-image-wrapper').on('mouseenter', function(e) {
109                isMouseInside = true;
110            });
111
112            $carousel.closest('.product-image-wrapper').on('mouseleave', function(e) {
113                isMouseInside = false;
114                $carousel.trigger('to.owl.carousel', [0, 10]);
115            });
116
117            $carousel.closest('.product-image-wrapper').on('mousemove', function(e) {
118                if (!isMouseInside) return;
119
120                let currentX = e.pageX;
121
122                let containerWidth = $carousel.width();
123                let areaWidth = containerWidth / totalSlides;
124
125                let relativeX = currentX - $carousel.offset().left;
126                let zoneIndex = Math.floor(relativeX / areaWidth);
127
128                zoneIndex = Math.max(0, Math.min(zoneIndex, totalSlides - 1));
129
130                let activeItem = $carousel.find('.owl-item.active');
131                let currentActiveIndex = activeItem.index();
132
133                if (zoneIndex !== currentActiveIndex) {
134                    $carousel.trigger('to.owl.carousel', [zoneIndex, 10]);
135                }
136            });
137        });
138    }
139
140    function initializeCountdowns() {
141        let countdownElements = $('.sale-product-daily-deal-new');
142
143        countdownElements.each(function() {
144            let $element = $(this);
145            let endDateString = $element.attr('data-end-date');
146            if (endDateString) {
147                initializeCountdown($element.find('.custom-countdown'), endDateString);
148            }
149        });
150    }
151
152    function initializeAll() {
153        initializeTooltips();
154        initializeOwlCarousel();
155        initializeCountdowns();
156    }
157
158    initializeAll();
159
160    function initializeCountdown($countdownElement, endDateString) {
161        let endDate = new Date(endDateString);
162
163        function updateCountdown() {
164            let now = new Date();
165            let timeDiff = endDate - now;
166
167            if (timeDiff <= 0) {
168                $countdownElement.text('00д:00ч:00м');
169                clearInterval(countdownInterval);
170                return;
171            }
172
173            let days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
174            let hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
175            let minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
176
177            let formattedDays = String(days).padStart(2, '0');
178            let formattedHours = String(hours).padStart(2, '0');
179            let formattedMinutes = String(minutes).padStart(2, '0');
180
181            $countdownElement.text(formattedDays + 'д:' + formattedHours + 'ч:' + formattedMinutes + 'м');
182        }
183
184        updateCountdown();
185
186        let countdownInterval = setInterval(updateCountdown, 60000);
187    }
188
189    function lock(wrap, state=true){
190        wrap.find('button, input, a.add_to_cart_button').prop('disabled', state);
191    }
192
193    function refresh(){
194        $(document.body).trigger('wc_fragment_refresh');
195    }
196
197    function initCatalogCartState(){
198
199        $.post('/wp-admin/admin-ajax.php', {action:'get_cart_items'}, function(data){
200
201            $('.new-product-inner .add-links').each(function(){
202
203                var wrap = $(this);
204                var btn = wrap.find('.add_to_cart_button');
205                var id = btn.data('product_id');
206
207				if(data[id]){
208					btn.removeClass('show');
209					wrap.find('.quantity')
210						.addClass('show')
211						.find('input.qty')
212						.val(data[id].qty);
213					toggleInCartState(wrap, true);
214				}else{
215					btn.addClass('show');
216					wrap.find('.quantity').removeClass('show');
217					toggleInCartState(wrap, false);
218				}
219
220            });
221
222        });
223
224    }
225    initCatalogCartState();
226
227    $(document.body).on('wc_fragments_refreshed removed_from_cart', function() {
228        initCatalogCartState();
229    });
230
231    $(document).on('click','.add_to_cart_button',function(e){
232
233        e.preventDefault();
234
235        var btn = $(this);
236        var wrap = btn.closest('.add-links');
237        var id = btn.data('product_id');
238
239        lock(wrap,true);
240
241		$.post('/?wc-ajax=add_to_cart',{product_id:id,quantity:1},function(){
242			btn.removeClass('show');
243			wrap.find('.quantity')
244				.addClass('show')
245				.find('input.qty').val(1);
246			toggleInCartState(wrap, true);
247			lock(wrap,false);
248			refresh();
249		});
250    });
251
252
253    $(document).on('click','.new-product-inner .quantity .plus',function(){
254
255        var wrap = $(this).closest('.add-links');
256        var input = wrap.find('input.qty');
257        var id = wrap.find('.add_to_cart_button').data('product_id');
258        var qty = parseInt(input.val()) + 1;
259
260        lock(wrap,true);
261
262        $.post('/wp-admin/admin-ajax.php',{
263            action:'set_cart_qty',
264            product_id:id,
265            qty:qty
266        },function(){
267
268            input.val(qty);
269            lock(wrap,false);
270            refresh();
271        });
272    });
273
274
275    $(document).on('click','.new-product-inner .quantity .minus',function(){
276
277        var wrap = $(this).closest('.add-links');
278        var input = wrap.find('input.qty');
279        var btn = wrap.find('.add_to_cart_button');
280        var id = btn.data('product_id');
281        var qty = parseInt(input.val()) - 1;
282
283        lock(wrap,true);
284
285        $.post('/wp-admin/admin-ajax.php',{
286            action:'set_cart_qty',
287            product_id:id,
288            qty:qty
289        },function(){
290
291			if(qty <= 0){
292				wrap.find('.quantity').removeClass('show');
293				btn.addClass('show').html(btn.data('initial-html') || 'Купить');
294				input.val(0);
295				toggleInCartState(wrap, false);
296			}else{
297				input.val(qty);
298			}
299
300            lock(wrap,false);
301            refresh();
302        });
303    });
304
305
306    $(document).on('change','.new-product-inner .quantity input.qty',function(){
307
308        var input = $(this);
309        var wrap = input.closest('.add-links');
310        var btn = wrap.find('.add_to_cart_button');
311        var id = btn.data('product_id');
312        var qty = parseInt(input.val());
313
314        lock(wrap,true);
315
316        $.post('/wp-admin/admin-ajax.php',{
317            action:'set_cart_qty',
318            product_id:id,
319            qty:qty
320        },function(){
321
322            if(qty <= 0){
323                wrap.find('.quantity').removeClass('show');
324                btn.addClass('show').html(btn.data('initial-html') || 'В корзину');
325            }
326
327            lock(wrap,false);
328            refresh();
329        });
330    });
331
332    jQuery(window).on('porto_posts_updated', function (e) {
333
334
335        initializeAll();
336        initCatalogCartState();
337    });
338	
339	$(document).on('click', '.product-inner[data-product-url]', function (e) {
340		if ($(e.target).closest('a, button, input, select, textarea, label, .add_to_cart_button, .owl-nav, .owl-dots').length) {
341			return;
342		}
343
344		var url = $(this).data('product-url');
345		if (!url) return;
346
347		if (e.ctrlKey || e.metaKey || e.button === 1) {
348			window.open(url, '_blank');
349		} else {
350			window.location.href = url;
351		}
352	});
353
354	$(document).on('mousedown', '.product-inner[data-product-url]', function (e) {
355		if (e.button !== 1) return;
356		if ($(e.target).closest('a, button, input, select, textarea, label, .add_to_cart_button, .owl-nav, .owl-dots').length) {
357			return;
358		}
359		e.preventDefault();
360		var url = $(this).data('product-url');
361		if (url) window.open(url, '_blank');
362	});
363
364});

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.