PageSourceSearch

https://animalface.ru/js/frontend/content/shop.js?47

js animalface.ru collected 2026-10-08 09:22:32 UTC 9,907 bytes, 395 lines download raw bytes

1// JavaScript Document
2var timer;
3
4$(function() {
5
6    // FancyBox
7    $('[data-fancybox^="gallery"]').fancybox({		
8        buttons: [ "close" ]
9    });
10
11    // Image Gallery
12	if($('.carousel-block a').length > 1) {
13
14		$.each($('.carousel-block a'), function(i) {
15			$('.carousel-block .container').append('<div></div>');
16		});
17
18		$('.carousel-block .container div').first().addClass('current');
19
20
21		$('.carousel-block .container div').hover(function() {
22			$('.carousel-block .container div').removeClass('current');
23			$(this).addClass('current');
24			$('.item .carousel-block a').hide();
25			$('.item .carousel-block a').eq($(this).index()).show();
26		});
27
28	}
29
30	// Basket Actions 
31	$(document).on('click input', '[data-role="basket"]', function(event) { 		
32
33		if($(this).closest('#cdek-map').length == 1) {
34			return;
35		}
36
37		event.preventDefault();
38
39		let action = $(this).data('action');
40
41		// Show Spinner for Basket
42		if(action == 'show-spinner') {
43			$(this).parent().hide().next().show().find('div[data-type="add"]').trigger('click');
44		}
45				
46		// Update Basket via Spinner or Text Input
47		else if(action == 'spinner' || action == 'input') {
48			
49			$(this).parents('.spinner').removeClass('basket-input-error');
50			
51			// By Spinner 		
52			if(action == 'spinner')	{ 
53			
54				let id = $(this).parents('.spinner').find('input').data('id');
55
56				if(SetSpinner(id, $(this).data('type'), 0, 9999) === false) { 
57					return; 
58				}
59
60				let value = $(this).parents('.spinner').find('input').val();
61
62				UpdateBasket(id, value);
63
64			}
65			
66			// By Keys in Input 			
67			else if(action == 'input') { 
68				
69				// Check current Event				
70				if(event.type != 'input') {
71					return false;
72				}
73				
74				var _this = $(this);
75				
76				clearTimeout(timer);
77				
78				// Make Delay for 0.5 sec
79				timer = setTimeout(function() {
80					
81					// Check is Digit
82					if(/^[0-9]+$/.test(_this.val())) {
83
84						var id = _this.data('id'),
85							value = _this.val();
86
87							SelectRange(_this);
88
89					} else {
90
91						_this.parents('.spinner').addClass('basket-input-error');
92						SelectRange(_this);
93						return false;
94					}
95					
96					UpdateBasket(id, value);
97					
98				}, 500);
99					
100			}
101			
102		} 
103				
104		// Delivery Type (Pickup or Delivery)
105		else if(action === 'delivery') {
106
107			if($(this).hasClass('selected')) {
108				return true;   
109			}
110
111			// Fix CDEK Widget
112			$('#cdek-map input').addClass('no-hint').attr('autocomplete', 'off');
113			
114			$(this).parents('.selector-of-delivery').find('.selected').removeClass('selected');
115			$(this).parents('#delivery-block').find('div[data-role="layer"]').hide();
116			
117			$(this).addClass('selected');
118			$(this).parents('#delivery-block').find('div[data-role="layer"][data-type="' + $(this).data('type') + '"]').show();
119			
120			var sumTax = $('#payment-block div[data-type="online"]').data('sum') == undefined ? 0 : $('#payment-block div[data-type="online"]').data('sum'),
121				sum    = $('#payment-block div[data-type="bank"]').data('sum') == undefined ? 0 :  $('#payment-block div[data-type="bank"]').data('sum');
122
123
124			if($(this).data('type') == 'delivery') {
125
126				$('#delivery-field').val('delivery');
127
128				$('.address-container').show();
129				$('.selector-of-delivery')
130				
131				var totalTax = (sumTax +  $('.selector-of-delivery').data('delivery')).toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 '),
132					total = (sum +  $('.selector-of-delivery').data('delivery')).toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
133				
134			}
135
136			else {
137
138
139				$('#delivery-field').val($('#delivery-block div[data-role="layer"][data-type="pickup"]').find('.selected').data('city'));
140				$('.address-container').hide();
141
142				var totalTax = sumTax.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 '),
143					total = sum.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
144
145			}
146
147			
148			// Update Total with Delivery
149			$('#payment-block div[data-type="online"] .sum span').html(totalTax);
150			$('#payment-block div[data-type="bank"] .sum span').html(total);
151		}
152		
153		// Delivery City (Moscow or Saint-Petesburg)
154		else if(action === 'city') {
155			
156			if($(this).hasClass('selected')) {
157				return true;   
158			}
159			
160			$(this).parents('div[data-role="layer"][data-type="pickup"]').find('.selected').removeClass('selected');
161			$(this).addClass('selected');
162
163			$('#delivery-field').val($(this).data('city'));
164
165		}
166		
167		// Payment type Online or Bank)
168		else if(action === 'payment') {
169			
170			if($(this).hasClass('selected')) {
171				return true;   
172			}
173			
174			var opposite = ($(this).data('type') == 'online') ? 'bank' : 'online';
175			
176			$(this).parents('#payment-block').find('.selected')
177			.find('svg use').attr('xlink:href', '/i/svg/shop.svg#' + opposite + '-blue').end()
178			.parents('#payment-block').find('.selected').removeClass('selected');
179			
180			$(this).addClass('selected').find('svg use').attr('xlink:href', '/i/svg/shop.svg#' + $(this).data('type') + '-white');
181			$('#payment').val($(this).data('type'));
182			
183		}
184				
185		// Submit Basket Form
186		else if(action === 'submit') {
187			
188			$.post('/Shop/Submit', $(this).parents('form').serialize(), function(data) {
189
190				if(!DefineErrors(data)) { return; }
191				
192				if(data.payment == 'online') {
193						
194					$.post('/payments/createKey/shop', { order: data.order }, function(data) {
195
196						if(data.indexOf('Ошибка') + 1) { 
197							PopUpMessage('error', data); 
198						}
199
200						else {
201							$('.footer button[data-role="basket"]').remove();
202							location.href = data;
203						}
204					});
205					
206				}
207
208				else {
209
210					PopUpMessage(data.status, data.message);
211
212					$('.footer button[data-role="basket"]').remove();
213
214					setTimeout(function() {
215						location.href = '/shop/';
216					}, 3000);
217
218				}
219				
220			}, 'json');	
221		}
222		
223	});
224
225	$(document).on('submit', '#order-form', function(event) {
226		event.preventDefault();
227	});
228
229	// Tabs
230	$(document).on('click', '[data-tab="controll"] > div:first-child a', function(event) {
231
232		event.preventDefault();
233
234		$('[data-tab="pane"]').hide();
235		$('[data-tab-status="active"]').attr('data-tab-status', '');
236
237		$(`[data-id="${$(this).data('tab-id')}"]`).show();
238		$(this).attr('data-tab-status', 'active');
239
240	});
241
242	if($('#checkout').length > 0) {
243
244		if($('.selector-of-delivery > div[data-role="basket"]').length == 1) {
245			$('.selector-of-delivery > div[data-role="basket"]').trigger('click');
246		}
247
248		new window.CDEKWidget({
249			apiKey: $('#cdek-map').data('key'),
250			from: 'Москва',
251			defaultLocation: 'Москва',
252			servicePath: 'https://animalface.ru/shop/cdek/',
253			hideDeliveryOptions: { door: true },
254			onChoose(type, tariff, Address) {
255				$('#map-container [data-hint="#list"]').trigger('click');
256				$('#address').val(`город ${Address.city}, ${Address.address} (СДЭК: ${Address.code})`);
257				$('#pvz').val(Address.code);
258				$('body, html').animate({
259					scrollTop: $('#address').offset().top - 100
260				}, 800);
261			}
262		});
263
264		$('#address').suggestions({
265			token: 'd07f912cfa760bdb63731ca6d4df0b9ced977e8b',
266			type: 'ADDRESS',
267			count: 3,
268			onSelect: function(suggestion) {
269				$('#address').val(suggestion.data.postal_code + ', ' +  suggestion.value)
270			}
271		});
272
273	}
274
275
276
277});
278
279
280function UpdateBasket (id, qty) {
281
282	$.post('/Shop/Update', {'id': id, 'qty': qty}, function(data) {
283		
284		$('#basket-button span').html(data.total).finish().effect('bounce');
285		
286		let input = $(`input[data-id="${id}"]`);
287
288		if(data.category != 4) {
289			
290			var total = data.price * data.qty;
291			input.parents('.item').find('.title .sum').html(total.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ') + ' &#8381;');
292			
293		}
294
295		else {
296
297			// Get all NFC
298			$('.items input[data-category="4"]').each(function() {
299
300				var total = data.price * $(this).val();
301
302				$(this).parents('.item').find('.title .sum').html(total.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ') + ' &#8381;');
303			});
304			
305		}
306				
307		$('#items-in-basket .footer div span').html(data.sum + ' &#8381;');
308		
309	}, 'json');
310}
311
312function SetSpinner (id, type, min, max) {
313	
314	var input = $('input[data-id=' + id + ']');
315	
316	// Add to basket
317	if(type == 'add') {
318				
319		if(parseInt(input.val()) < max) {
320			input.val(parseInt(input.val()) + 1).data('value', input.val());
321			SelectRange(input);
322		} else {
323			return false;	
324		}
325				
326	// Subtract from basket	
327	} else if(type == 'subtract') {
328					
329		if(parseInt(input.val()) > min) {
330			input.val(parseInt(input.val()) - 1).data('value', input.val());
331			if(parseInt(input.val()) == 0) {
332				input.parents('.spinner-container').parent().find('.button-container').show().next().hide();	
333			}
334			SelectRange(input);
335		} else {
336			return false;	
337		}
338	} 
339	
340	return true;
341
342}
343
344// Set Color Range
345function SelectRange (input) {
346	
347	var found = false;
348	
349	input.parents('.item').find('.prices-block .item').each(function() {
350		
351		var from = parseInt($(this).data('from'));
352		var to = parseInt($(this).data('to'));
353
354		if(parseInt(input.val()) >= from && parseInt(input.val()) <= to) {
355			
356			if(!$(this).hasClass('selected-range')) {
357				input.parents('.item').find('.prices-block .item').removeClass('selected-range');
358				$(this).addClass('selected-range');	
359			}
360			
361			found = true;
362		}
363	});
364	
365	// For all NFC 
366	if(input.data('category') == 4) {
367		
368		var total = 0;
369
370		// Count all NFC
371		$('.items input[data-category="4"]').each(function() {
372			total += parseInt($(this).val())
373		});
374		
375			
376		$('.items input[data-category="4"]').parents('.item').find('.prices-block .item')
377		.removeClass('selected-range').each(function() {
378
379			var from = parseInt($(this).data('from'));
380			var to = parseInt($(this).data('to'));
381					
382			if(parseInt(total) >= from && parseInt(total) <= to && parseInt($(this).parents('.item').find('input[data-category="4"]').val()) > 0) {
383				$(this).addClass('selected-range');	
384				found = true;
385			}
386
387		});
388
389	}		
390	
391	if(found == false) {
392		input.parents('.item').find('.prices-block .item').removeClass('selected-range');
393	}
394	
395}

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.