PageSourceSearch

https://happyfishes.ru/wp-content/themes/scape/library/js/module-woocommerce.js?ver=1.0

js happyfishes.ru collected 2026-10-06 13:41:44 UTC 13,653 bytes, 501 lines download raw bytes

1
2(function() {
3	"use strict";
4	window.SCAPE = window.SCAPE || {};
5	var $ = jQuery.noConflict();
6
7	SCAPE.isotopeShop = {
8
9		init: function($container) {
10			$($container).each(function(){
11				$container = $(this);
12			});
13		},
14
15		setup: function($container) {
16			if ( $container.find('.wtbx-masonry-entry').length ) {
17				$(window).on('resize', function(){
18					SCAPE.waitForFinalEvent( function() {
19					}, SCAPE.timeToWaitForLast, 'shop_grid');
20				});
21			}
22		},
23
24		layout: function($container) {
25			var $item	= $container.find('.wtbx-product-entry');
26
27			var width		= $container.outerWidth(true);
28			var columns		= $container.data('columns');
29			var cat_columns	= $container.data('cat-columns');
30			var animate		= $container.data('animate');
31			var border		= $container.data('border') || 0;
32
33			if (width < 500) {
34				columns = 1;
35			} else if (width < 850) {
36				columns = Math.min(2,columns);
37			} else if (width < 1200) {
38				columns = Math.min(3,columns);
39			}
40
41			if (width < 500) {
42				cat_columns = 1;
43			} else if (width < 900) {
44				cat_columns = Math.min(2,cat_columns);
45			} else if (width < 1200) {
46				cat_columns = Math.min(3,cat_columns);
47			}
48
49			var column_width		= Math.floor( width / columns );
50			var cat_column_width	= Math.floor( width / cat_columns );
51
52			$container.find('.wtbx-product-single-entry').css({
53				'width': column_width + 'px'
54			});
55			$container.find('.wtbx-product-category-entry').css({
56				'width': cat_column_width + 'px'
57			});
58
59			$container.isotope({
60				itemSelector : '.wtbx-masonry-entry',
61				resizable : true,
62				layoutMode : 'masonry',
63				masonry: {
64					gutter: 0
65				},
66				transitionDuration: animate,
67				hiddenStyle: {
68					opacity: 0
69				},
70				visibleStyle: {
71					opacity: 1
72				}
73			});
74
75			if ( !$container.hasClass('wtbx-isotope-init') ) {
76				$container.find('.wtbx-product-wrapper').each(function(index) {
77					var $this = $(this);
78					setTimeout(function() {
79						$this.addClass('wtbx-element-visible');
80					}, index * 100);
81				});
82			}
83
84			$container.addClass('wtbx-isotope-init');
85
86		}
87
88	};
89
90
91
92	SCAPE.woocommerceModule = {
93
94		quantity: function($el) {
95
96			if ( !$el ) {
97				$el = $('.wtbx-quantity');
98			}
99
100			$el.each(function() {
101				var $container	= $(this),
102					$input		= $container.find('input'),
103					$plus		= $container.find('.plus'),
104					$minus		= $container.find('.minus'),
105					step		= parseInt($container.find('.qty').attr('step'));
106
107				$plus.unbind().on('click', function() {
108					var value	= parseInt($input.val()),
109						max		= $input.attr('max');
110					if ( value < max || !max ) {
111						$input.val(value + step);
112					}
113					if ( isNaN(value) ) {
114						$input.val(1);
115					}
116					$( 'div.woocommerce > form button[name="update_cart"], .wc-proceed-to-checkout > [name="update_cart"]' ).prop( 'disabled', false );
117				});
118				$minus.unbind().on('click', function() {
119					var value	= parseInt($input.val()),
120						min		= $input.attr('min') || 1;
121
122					value = value - step;
123					if ( value < min ) {
124						value = min;
125					}
126					$input.val(value);
127
128					$( 'div.woocommerce > form button[name="update_cart"], .wc-proceed-to-checkout > [name="update_cart"]' ).prop( 'disabled', false );
129				});
130
131				$input.on('blur', function() {
132					if ( $input.val() === '' || $input.val() === '0' ) {
133						$input.val(1);
134					}
135				});
136
137				var $variations	= $('.single_variation_wrap');
138				if ( $variations.length ) {
139					var $select	= $variations.find('.variation_id');
140					$select.on('change', function() {
141						setTimeout(function() {
142							var value	= parseInt($input.val()),
143								max		= $input.attr('max');
144							if ( max && value > max ) {
145								$input.val(max);
146							}
147						},100);
148					});
149				}
150
151			});
152		},
153
154		variations: function() {
155			var $variations	= $('.single_variation_wrap');
156			if ( $variations.length ) {
157				var $gallery = $variations.closest('.product').find('.images');
158				var $form	 = $variations.closest('.variations_form');
159				$gallery.on( 'woocommerce_gallery_reset_slide_position', function() {
160					var $curr_image		= $gallery.find('.thumbnails').find('.thumb-wrapper.active a'),
161						curr_image_id	= $curr_image.data('image'),
162						new_image_id	= $form.attr('current-image');
163
164					if ( curr_image_id && curr_image_id !== new_image_id ) {
165						$gallery.find('.thumbnails').find('a[data-image="' + new_image_id + '"]').closest('.thumb-wrapper').trigger('click');
166					}
167				} );
168
169				$(document).on('click', '.thumbnails a', function(e) {
170					SCAPE.stopEvent(e);
171				});
172			}
173		},
174
175		thumbnails: function() {
176
177			$('.woocommerce-product-gallery').each(function() {
178				var $container = $(this),
179					$thumbnails	= $container.find('.thumbnails'),
180					$mainImg	= $container.find('.woocommerce-main-image'),
181					$mainSlider = $container.find('.product-main-image');
182
183				if ( $thumbnails.length ) {
184					// add thumbnail images to main image slider
185
186					$thumbnails.find('.thumb-wrapper').each(function() {
187						$(this).clone().appendTo($mainSlider).find('a').addClass('wtbx-lightbox-item');
188					});
189
190					$mainSlider.find('.thumb-wrapper:first').clone().addClass('active').prependTo($thumbnails).find('.wtbx-lightbox-item').removeClass('wtbx-lightbox-item').addClass('thumb-image').end().find('.wtbx-preloader-wrapper').remove();
191
192					$thumbnails.find('.thumb-fullsize').remove();
193
194					$mainSlider.slick({
195						speed			: 400,
196						slidesToShow	: 1,
197						slidesToScroll	: 1,
198						swipeToSlide	: true,
199						infinite		: false,
200						autoplay		: false,
201						touchThreshold	: 8,
202						adaptiveHeight	: true,
203						useTransform	: true,
204						draggable		: false,
205						dots			: false,
206						arrows			: false,
207						swipe			: false,
208						cssEase			: 'cubic-bezier(0.6, 0, 0.2, 1)'
209					});
210
211					// change main image on thumbnail click
212					$thumbnails.find('.thumb-wrapper').on('click', function() {
213						$thumbnails.find('.thumb-wrapper').removeClass('active');
214						$(this).addClass('active');
215						$mainSlider.slick('slickGoTo', $(this).index());
216					});
217
218				}
219
220				// image zoom
221				$mainSlider.find('.thumb-wrapper')
222					.on('mouseenter', function() {
223						$(this).addClass('active');
224						$(this).find('.thumb-fullsize').css('opacity', '1');
225					})
226					.on('mouseleave', function() {
227						var $this = $(this);
228						$this.removeClass('active');
229						$this.find('.thumb-fullsize').css('opacity', '0');
230						setTimeout(function() {
231							if ( !$this.hasClass('active') ) {
232								$this.find('.thumb-fullsize').attr('style', '');
233							}
234						}, 500);
235					})
236					.on('mousemove', function(e) {
237						var $el		= $(this),
238							$full	= $el.find('.thumb-fullsize'),
239							xPos	= (e.pageX - $el.offset().left) / $el.width() * ($full.width() - $el.width()),
240							yPos	= (e.pageY - $el.offset().top) / $el.height() * ($full.width() - $el.width());
241
242						var transform = SCAPE.propertyPrefix('transform');
243						$full.css(transform, 'translate3d(-'+xPos+'px,-'+yPos+'px,0)');
244					});
245
246				$container.addClass('initialized');
247			});
248
249		},
250
251		productActions: function() {
252			var $actions = $('.wtbx-product-actions');
253			if ($actions.length) {
254				$actions.each(function() {
255					var $actions = $(this).closest('.wtbx-product-actions');
256					var $trigger = $actions.find('.product-actions-trigger');
257
258					$trigger.on('mouseenter touchend', function(e) {
259						if( !$actions.hasClass('active') ) {
260							$actions.addClass('active');
261						}
262					});
263
264					$actions.on('mouseleave touchend', function(e) {
265						var $actions = $(this);
266						if( $actions.hasClass('active') ) {
267							$actions.removeClass('active');
268						}
269					});
270				});
271			}
272		},
273
274		productCarousel: function($el) {
275
276			if ( !$el ) {
277				$el = $('.wtbx-grid-products');
278			}
279
280			$el.each(function() {
281				if ( !$(this).hasClass('product-carousel-init') ) {
282					if ( $(this).parent().parent('.woocommerce').length && $(this).closest('.product-slider').length ) {
283						var columns = $(this).attr('class');
284						columns = columns.split('columns-')[1];
285						columns = columns.split(' ')[0];
286						$(this).addClass('wtbx-product-carousel');
287						$(this).attr('data-perpage', columns);
288					}
289				}
290			});
291
292			$('.wtbx-product-carousel').each(function() {
293				var $slider		= $(this);
294
295				if ( !$slider.hasClass('product-carousel-init') ) {
296					var options = {
297						prevNextButtons:	false,
298						wrapAround:			true,
299						cellAlign:			'left',
300						selectedAttraction:	0.08,
301						friction:			0.8,
302						pageDots:			false
303					};
304
305					setTimeout(function() {
306						$slider.flickity(options);
307					});
308					$slider.addClass('product-carousel-init');
309
310					setTimeout(function() {
311						$slider.flickity('resize');
312					}, 500);
313				}
314			});
315		},
316
317		productGrid: {
318
319			init: function() {
320				$('.wtbx-grid-products').each(function(){
321					if ( !$(this).parent().parent('.woocommerce').length ) {
322						var $container = $(this);
323						SCAPE.woocommerceModule.productGrid.setup($container);
324					}
325				});
326			},
327
328			setup: function($container) {
329				if ( $container.find('.wtbx-grid-entry').length ) {
330					setTimeout(function() {
331						SCAPE.woocommerceModule.productGrid.layout($container);
332					});
333					$(window).on('resize', function(){
334						SCAPE.woocommerceModule.productGrid.layout($container);
335					});
336
337					setTimeout(function() {
338						SCAPE.woocommerceModule.productGrid.layout($container);
339					}, 1000);
340
341					if ( SCAPE.isMobile() ) {
342						$container.find('.wtbx-grid-entry .wtbx-product-link').hover(function() {
343							location.href = $(this).attr('href');
344						});
345					}
346				}
347			},
348
349			layout: function($container) {
350				var $item		= $container.find('.wtbx-grid-entry');
351				var count		= $container.find('.wtbx-product-single-entry').length;
352				var count_cat	= $container.find('.wtbx-product-category-entry').length;
353				var width		= $container.width();
354				var columns		= $container.data('columns');
355				var cat_columns	= $container.data('cat-columns');
356				var animate		= $container.data('animate');
357				var border		= $container.data('border') || 0;
358
359				if ( width < 540 ) {
360					columns = 1;
361				} else if ( width < 810 ) {
362					columns = 2;
363				} else {
364					if ( columns === 4 ) {
365						if ( width < 1080 ) {
366							if ( count % 3 === 0 ) {
367								columns = 3;
368							} else {
369								columns = 2;
370							}
371						}
372					} else if ( columns === 5 ) {
373						if ( width < 1080 ) {
374							if ( count % 3 === 0 ) {
375								columns = 3;
376							} else {
377								columns = 2;
378							}
379						} else if ( width < 1350 ) {
380							if ( count % 4 === 0 ) {
381								columns = 4;
382							} else if ( count % 3 === 0 ) {
383								columns = 3;
384							}
385						}
386					} else if ( columns === 6 ) {
387						if ( width < 1080 ) {
388							columns = 3;
389						} else if ( width < 1350 ) {
390							if ( count % 4 === 0 ) {
391								columns = 4;
392							} else {
393								columns = 3;
394							}
395						} else if ( width < 1620 ) {
396							if ( count % 5 === 0 ) {
397								columns = 5;
398							} else if ( count % 4 === 0 ) {
399								columns = 4;
400							} else {
401								columns = 3;
402							}
403						}
404					}
405				}
406
407				if ( width < 700 ) {
408					cat_columns = 1;
409				} else if ( width < 1050 ) {
410					cat_columns = 2;
411				} else if ( width < 1400 ) {
412					if ( cat_columns === 4 ) {
413						if ( count_cat % 3 === 0 ) {
414							cat_columns = 3;
415						} else {
416							cat_columns = 2;
417						}
418					}
419				}
420
421				var column_width		= Math.floor( width / columns );
422				var cat_column_width	= Math.floor( width / cat_columns );
423
424				$container.find('.wtbx-product-single-entry').css({
425					'width': column_width + 'px',
426					'display': 'block'
427				});
428				$container.find('.wtbx-product-category-entry').css({
429					'width': cat_column_width + 'px'
430				});
431
432				$('.wtbx-product-single-entry').each(function(index) {
433					$(this).removeClass('first last');
434					if ( (index + 1) % columns === 0 ) {
435						$(this).addClass('last').next().addClass('first');
436					}
437				});
438				$('.wtbx-product-category-entry').each(function(index) {
439					$(this).removeClass('first last');
440					if ( (index + 1) % cat_columns === 0 ) {
441						$(this).addClass('last').next().removeClass('first last').addClass('first');
442					}
443				});
444			}
445
446		},
447
448		wishlist: function() {
449			var $table			= $('.wtbx-wishlist-form'),
450				$button			= $table.find('.remove, .add_to_cart_button');
451
452			$(document).on('click', '.remove, .add_to_cart_button', function(evt) {
453				$table.addClass('processing');
454			});
455			$(document).on('removed_from_wishlist added_to_cart', function() {
456				$table.removeClass('processing');
457			});
458
459			$(document).on('added_to_wishlist removed_from_wishlist', function() {
460				$.ajax({
461					url: yith_wcwl_l10n.ajax_url,
462					type: 'POST',
463					data: {
464						action: 'update_wishlist_count'
465					},
466					success: function(data) {
467						if ( data !== 'false' ) {
468							$('.header_wishlist .wishlist_count').html(data);
469						}
470					}
471				})
472			});
473		},
474
475		widgets: function() {
476			$('.woocommerce.widget_layered_nav .wc-layered-nav-term span, .woocommerce.widget_product_categories .cat-item span').each(function() {
477				$(this).html($(this).html().replace('(', '').replace(')', ''));
478			});
479		}
480
481	};
482
483	jQuery(document).ready(function($) {
484		// SCAPE.isotopeShop.init($('.wtbx-grid-products'));
485
486		SCAPE.woocommerceModule.variations();
487		SCAPE.woocommerceModule.productGrid.init();
488		SCAPE.woocommerceModule.productActions();
489		SCAPE.woocommerceModule.productCarousel();
490		SCAPE.woocommerceModule.widgets();
491
492		SCAPE.woocommerceModule.quantity();
493		$(document.body).on( 'updated_cart_totals', function() {
494			SCAPE.woocommerceModule.quantity();
495			SCAPE.woocommerceModule.productCarousel();
496		});
497
498		SCAPE.woocommerceModule.wishlist();
499	});
500
501})(jQuery);

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.