PageSourceSearch

https://www.machikogym.com/themes/carelux/modules/an_stickyaddtocart/views/js/front.js

js machikogym.com collected 2026-10-07 21:52:51 UTC 8,745 bytes, 252 lines download raw bytes

1
2(function ($, window, undefined) {
3	'use strict';
4	
5	resizeProduct();
6	
7	$(document).ajaxSuccess(function() {
8		resizeProduct();
9	});
10	
11	function resizeProduct(){
12		$('.js-product-miniature').each( function(){
13			var marginBottom = $(this).find('.an_stickyAddToCart').height()+40+'px'
14			$(this).find('.thumbnail-container').css('margin-bottom', marginBottom);		
15		});
16	}
17
18	$(document).on('change','.an_stickyAddToCart [data-product-attribute], .an_stickyAddToCart-select select', function() {
19		
20		var self = this;
21		
22		getData($(this).closest('.an_stickyAddToCartForm').serialize(), function(data){ 			
23			isAvailableForOrder($(self).closest('.an_stickyAddToCartForm').find('.js-an_stickyAddToCart-add-to-cart'), data);
24			setMaxQty($(self).closest('.an_stickyAddToCartForm').find('.an_stickyAddToCart-qty'), data);
25			setMinQty($(self).closest('.an_stickyAddToCartForm').find('.an_stickyAddToCart-qty'), data);			
26			setPrices($('.an_stickyAddToCart-product-price-and-shipping'), $('.an_stickyAddToCart-price-price'), data);
27 			setImages($('.js-an_stickyAddToCart-image'), data);
28			setVariants(self, data);
29		});
30	});
31
32	$(document).on('click','.an_stickyAddToCart-dropdown-menu li', function() {
33		
34		var self = this;
35				
36		if (attributeGroups){
37			generateInputs($(this).closest('.an_stickyAddToCartForm'), parseInt($('.js-an_stickyAddToCart').attr('data-id-product')), $(this).data('value'));
38		}		
39
40		getData($(this).closest('.an_stickyAddToCartForm').serialize(), function(data){ 
41			isAvailableForOrder($(self).closest('.an_stickyAddToCartForm').find('.js-an_stickyAddToCart-add-to-cart'), data);
42			setMaxQty($(self).closest('.an_stickyAddToCartForm').find('.an_stickyAddToCart-qty'), data);
43			setMinQty($(self).closest('.an_stickyAddToCartForm').find('.an_stickyAddToCart-qty'), data);
44			setPrices($('.an_stickyAddToCart-product-price-and-shipping'), $('.an_stickyAddToCart-price-price'), data);
45 			setImages($('.js-an_stickyAddToCart-image'), data);
46		});
47	}); 
48	
49 	
50	
51	$(document).on('input','.an_stickyAddToCart-qty', function() {
52		changeButInput(this);
53	});
54	
55	
56function changeButInput(self){
57	var val = parseInt($(self).val());
58	var max = parseInt($(self).attr('data-max'));
59	var addToCart = $(self).closest('.an_stickyAddToCartForm').find('.js-an_stickyAddToCart-add-to-cart');
60	var addToCartStatus = parseInt(addToCart.attr('data-status'));
61
62	if (max && val > max){
63		addToCart.attr('disabled', 'disabled');
64	} else if (addToCartStatus){
65		addToCart.removeAttr('disabled');
66	} else {
67		addToCart.attr('disabled', 'disabled');
68	}
69}
70	
71	
72
73function getData(dataUrl, callback){	
74	$.ajax({
75		type: "POST",
76		url: an_stickyaddtocart.controller,
77		async: false,
78		data: dataUrl + '&action=getProductAttributes',
79		dataType: 'json',
80	}).done(function(data){
81		callback(data);
82	});
83}
84
85function generateInputs(an_stickyAddToCartForm, productId, attrebuteID){
86	$('.an_stickyAddToCart-hiddeninputs').remove();
87	
88	$.each(attributeGroups[productId][attrebuteID], function(index, value) {
89		an_stickyAddToCartForm.append("<input name='group[" + value['id_attribute_group'] + "]' value='" + value['id_attribute'] + "' type='hidden' class='an_stickyAddToCart-hiddeninputs' />");
90	});
91}
92	
93function isAvailableForOrder(addToCart, data){
94	if (!data.availableForOrder){
95		addToCart.attr('disabled', 'disabled');
96	} else {
97		addToCart.removeAttr('disabled');
98	}
99	addToCart.attr('data-status', data.availableForOrder);
100}
101
102function setVariants(self, data){
103	if (data.variants){
104		$(self).closest('.js-an_stickyAddToCart-standart').html(data.variants);
105	}
106}
107	
108 function setMaxQty(qty, data){
109	if (data.order_out_of_stock){
110		qty.attr('data-max', data.quantity);
111	} else {
112		qty.removeAttr('data-max');
113	}
114}
115	
116function setMinQty(qty, data){
117	if (data.minimal_quantity){
118		qty.attr('min', data.minimal_quantity).val(data.minimal_quantity);
119	}
120}
121	
122function setPrices(priceContainer, price, data){
123	priceContainer.find('.an_stickyAddToCart-regular-price').remove();
124	if (data.prices.regular_price){
125		priceContainer.prepend('<span class="an_stickyAddToCart-regular-price regular-price">'+data.prices.regular_price+'</span>');
126	}
127	
128	price.html(data.prices.price);
129}	
130
131function setImages(img, data){
132	if (data.images){
133		img.attr('src', data.images.home[data.cover_id]);
134	}
135}
136
137})(jQuery, window);
138
139$(document).ready(function () {
140	
141	selectFilling();
142	
143	$(document).ajaxSuccess(function() {
144		selectFilling();
145	});
146
147	$(document).mouseup(function (e){ // событие клика по веб-документу
148		var div = $(".an_stickyAddToCart .an_stickyAddToCart-product-selectbox");
148 // тут указываем ID элемента
149		if (!div.is(e.target) // если клик был не по нашему блоку
150			&& div.has(e.target).length === 0) { // и не по его дочерним элементам
151			div.removeClass('open'); // скрываем его
152		}
153	});
154	$(document).on('click','.an_stickyAddToCart-dropdown-toggler', function() {
155		$(this).parents('.an_stickyAddToCart-dropdown').toggleClass('open');
156	});
157	
158	$(document).on('click','.an_stickyAddToCart-dropdown-menu', function() {
159		$(this).parents('.an_stickyAddToCart-dropdown').toggleClass('open');
160	});
161
162	$(document).on('click','.js-an_stickyAddToCart-product-selectbox li', function() {
163		$(this).parents('.js-an_stickyAddToCart-product-selectbox').find('.js-an_stickyAddToCart-filter-option').text($(this).children('.js-an_stickyAddToCart-text').text());
164		$(this).parents('.js-an_stickyAddToCart-select').find('option').removeAttr('selected');
165		$(this).parents('.js-an_stickyAddToCart-select').find('option').eq($(this).index()).attr('selected','');
166	});
167
168	$(document).on('mouseleave', '.an_stickyAddToCart', function() {
169		$('.an_stickyAddToCart-dropdown').removeClass('open');
170
171	});
172
173	function selectFilling(){
174		$('.js-an_stickyAddToCart-product-selectbox li.selected').each(function() {
175			let item = $(this).parents('.js-an_stickyAddToCart-product-selectbox').find('.js-an_stickyAddToCart-filter-option');
176			if (!item.hasClass('selected')) {
177				item.text($(this).children('.js-an_stickyAddToCart-text').text());
178				item.addClass('selected');
179			}
180		});
181	}
182
183	$('<div class="quantity-button quantity-up">' +
184		'+' +
185		'</div>').insertAfter('#an_stickyAddToCart_qty');
186	$('<div class="quantity-button quantity-down">' +
187		'-' +
188		'</div>').insertBefore('#an_stickyAddToCart_qty');
189	$('.an_stickyAddToCart-qty-container').each(function() {
190		var spinner = jQuery(this),
191			input = spinner.find('input[type="number"]'),
192			btnUp = spinner.find('.quantity-up'),
193			btnDown = spinner.find('.quantity-down'),
194			min = input.attr('min'),
195			max = input.attr('max');
196
197		btnUp.click(function() {
198			var oldValue = parseFloat(input.val());
199			if (oldValue >= max) {
200				var newVal = oldValue;
201			} else {
202				var newVal = oldValue + 1;
203			}
204			spinner.find("input").val(newVal);
205			spinner.find("input").trigger("change");
206		});
207
208		btnDown.click(function() {
209			var oldValue = parseFloat(input.val());
210			if (oldValue <= min) {
211				var newVal = oldValue;
212			} else {
213				var newVal = oldValue - 1;
214			}
215			spinner.find("input").val(newVal);
216			spinner.find("input").trigger("change");
217		});
218	});
219
220	let scrollStart = ($('.product-add-to-cart .add-to-cart').offset().top + $('.product-add-to-cart .add-to-cart').height() + 20);
221	stickyScroll(scrollStart);
222	$(window).scroll(function(){
223		stickyScroll(scrollStart);
224	})
225
226    $(function() {
227        if ($('.an_stickyAddToCart .btn').data('animation')) {
228            setInterval(function() {
229                var animationName = 'animated '+$('.an_stickyAddToCart .btn').data('animation');
230                var animationend = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
231                $('.an_stickyAddToCart .btn').addClass(animationName).one(animationend, function() {
232                    $(this).removeClass(animationName);
233                });
234            }, $('.an_stickyAddToCart .btn').data('interval'));
235        }
236    });
237});
238
239function stickyScroll (scrollStart) {
240	if($(window).scrollTop() > scrollStart && $('.an_stickyAddToCart').attr('data-hidden') == 1){
241		$('.an_stickyAddToCart').attr('data-hidden',0);
242		$('#footer').css('padding-bottom',$('.an_stickyAddToCart').height() + 'px');
243		$('#right-column #_desktop_cart').css('padding-bottom',$('.an_stickyAddToCart').height() + 'px');
244		$('#scrolltopbtn').css('margin-bottom',$('.an_stickyAddToCart').height() + 'px');
245	}
246	if($(window).scrollTop() < scrollStart && $('.an_stickyAddToCart').attr('data-hidden') == 0) {
247		$('.an_stickyAddToCart').attr('data-hidden',1);
248		$('#footer').css('padding-bottom', '0');
249		$('#right-column #_desktop_cart').css('padding-bottom', '0');
250		$('#scrolltopbtn').css('margin-bottom','0');
251	}
252}

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.