PageSourceSearch

https://medcafedra.ru/bitrix/templates/aspro-allcorp3-med/js/custom.js

js medcafedra.ru collected 2026-10-01 12:39:16 UTC 10,230 bytes, 338 lines download raw bytes

1/*
2You can use this file with your scripts.
3It will not be overwritten when you upgrade solution.
4*/
5
6var $globaltitle = jQuery('title').html();
7
8const phoneMask = '+7 (999) 999-99-99';
9
10function mask_gift(event) {
11	var blank = "+_ (___) ___-__-__";
12	var i = 0;
13	var val = this.value.replace(/\D/g, "").replace(/^0/, "70").replace(/^1/, "71").replace(/^2/, "72").replace(/^3/, "73").replace(/^4/, "74").replace(/^5/, "75").replace(/^6/, "76").replace(/^7/, "7").replace(/^8/, "7").replace(/^9/, "79")
14		.replace(/^7888888888888/, "7")
15		.replace(/^788888888888/, "7")
16		.replace(/^78888888888/, "7")
17		.replace(/^7888888888/, "7")
18		.replace(/^788888888/, "7")
19		.replace(/^78888888/, "7")
20		.replace(/^7888888/, "7")
21		.replace(/^788888/, "7")
22		.replace(/^78888/, "7")
23		.replace(/^7888/, "7")
24		.replace(/^788/, "7")
25		.replace(/^78/, "7");
26	this.value = blank.replace(/./g, function(char) {
27		if (/[_\d]/.test(char) && i < val.length)
28			return val.charAt(i++);
29		return i >= val.length ? "" : char;
30	});
31	if (event.type == "blur") {
32		if (this.value.length == 2)
33			this.value = "";
34	} else {
35		setCursorPosition_gift(this, this.value.length);
36	}
37};
38function setCursorPosition_gift(elem, pos) {
39	elem.focus();
40	if (elem.setSelectionRange) {
41		elem.setSelectionRange(pos, pos);
42		return;
43	}
44	if (elem.createTextRange) {
45		var range = elem.createTextRange();
46		range.collapse(true);
47		range.moveEnd("character", pos);
48		range.moveStart("character", pos);
49		range.select();
50		return;
51	}
52}
53
54jQuery( document ).ready(function() {
55	
56	$('body').on('input','[name="TELEGRAM"],[name="gift_telegram"]', function() {
57		var $v = $(this).val()
58		if($v&&$v.length>0&&$v!='@') $v = '@' + $v.replace(/[^a-zA-Z0-9_]/g, "");
59		$(this).val($v)
60	});
61	
62	$('body').on('click','.reviews-menu a', function(e) {
63		e.preventDefault();
64		var target = $($(this).attr('href'));
65		if(target) {
66			var $scrollTop = target.offset().top - 100;
67			$('html, body').animate({
68				scrollTop: $scrollTop
69			}, 1000);
70		}
71	});
72	
73	$('.allery-item-wrapper-more>div.btn').on('click', function (e) {
74		var $container = $(this).closest('.big_gallery');
75		if( $('.gallery-item-wrapper:hidden',$container).length>0 ) {
76			$('.gallery-item-wrapper:hidden',$container).each(function($index){
77				if($index<12) $(this).slideDown('slow');
78			});
79			if( $('.gallery-item-wrapper:hidden',$container).length==0 ) $('.allery-item-wrapper-more',$container).hide();
80		} else {
81			$('.allery-item-wrapper-more',$container).hide();
82		}
83    });
84	
85	jQuery('table').each(function(){
86		jQuery(this).wrap( '<div class="tables-responsive swipeignore"></div>' )
87	});
88	
89    const giftAppealBlocks = document.querySelectorAll('.gift-appeal,.gift-appeal2');
90	
91    if (giftAppealBlocks.length === 0) return;
92
93    giftAppealBlocks.forEach((block) => {
94		
95        const form = block.querySelector('.gift-appeal__form');
96		
97		if(form) {
98			const action = form.action;
99
100			var inputs = form.querySelectorAll('.gift-appeal__input input[required]');
101			const submitBtn = form.querySelector('.gift-appeal__submit');
102			
103			$('body').on('change','[name="gift_method"]', function() {
104				var $c = $(this).closest('form');
105				
106				$('[name="WHERE"]').val($(this).val());
107				
108				if($(this).val()=='telegram'){
109					$('[name="gift_telegram"]',$c).prop('required',true);
110					$('[name="gift_telegram"]',$c).closest('.gift-appeal__input').show();
111					//////
112					$('[name="TELEGRAM"]',$c).prop('required',true);
113					$('[name="TELEGRAM"]',$c).closest('.row').show();
114				} else {
115					$('[name="gift_telegram"]',$c).removeAttr('required');
116					$('[name="gift_telegram"]',$c).closest('.gift-appeal__input').hide();
117					//////
118					$('[name="TELEGRAM"]',$c).removeAttr('required');
119					$('[name="TELEGRAM"]',$c).closest('.row').hide();			
120				}
121				
122				if($(this).val()=='email'){
123					$('[name="gift_email"]',$c).prop('required',true);
124					$('[name="gift_email"]',$c).closest('.gift-appeal__input').show();
125					// $('[name="gift_phone"]',$c).removeAttr('required');
126					// $('[name="gift_phone"]',$c).closest('.gift-appeal__input').hide();
127					// $('[name="gift_phone"]',$c).val('');
128					//////
129					$('[name="EMAIL"]',$c).prop('required',true);
130					$('[name="EMAIL"]',$c).closest('.row').show();
131					// $('[name="PHONE"]',$c).removeAttr('required');
132					// $('[name="PHONE"]',$c).closest('.row').hide();
133					// $('[name="PHONE"]',$c).val('');
134					
135				} else {
136					$('[name="gift_phone"]',$c).prop('required',true);
137					$('[name="gift_phone"]',$c).closest('.gift-appeal__input').show();
138					$('[name="gift_email"]',$c).removeAttr('required');
139					$('[name="gift_email"]',$c).closest('.gift-appeal__input').hide();
140					$('[name="gift_email"]',$c).val('');
141					//////
142					// $('[name="PHONE"]',$c).prop('required',true);
143					// $('[name="PHONE"]',$c).closest('.row').show();
144					$('[name="EMAIL"]',$c).removeAttr('required');
145					$('[name="EMAIL"]',$c).closest('.row').hide();
146					$('[name="EMAIL"]',$c).val('');
147				}
148				
149				inputs = form.querySelectorAll('.gift-appeal__input input[required]');
150				submitBtn.classList.remove('disabled');
151				
152				inputs.forEach((input) => {
153					input.addEventListener('focus', (e) => {
154						hideError(input);
155					});
156					input.addEventListener('input', (e) => {
157						validateInput(input);
158					});
159					input.addEventListener('blur', (e) => {
160						validateInput(input);
161					});
162				});
163			});
164			
165			var input = document.querySelectorAll('[name="gift_phone"]');
166			for (var i = 0; i < input.length; i++) {
167				input[i].addEventListener("input", mask_gift);
168				input[i].addEventListener("focus", mask_gift);
169				input[i].addEventListener("blur", mask_gift);
170			}
171
172			/* const phoneInput = form.querySelector(
173			  ".gift-appeal__input input[data-validate='phone']"
174			);
175
176			const mask = new Inputmask({
177				mask: phoneMask,
178				showMaskOnHover: false,
179			});
180			mask.mask(phoneInput); */
181
182			submitBtn.addEventListener('click', (e) => {
183				e.preventDefault();
184
185				inputs.forEach((input) => {
186					validateInput(input);
187				});
188
189				const allValid = validateForm();
190
191				if (allValid) {
192					const formData = new FormData(form);
193					submitBtn.disabled = true;
194
195					const request = new XMLHttpRequest();
196					request.open('POST', '/ajax/form_snippet.php?v=1.104');
197					request.onreadystatechange = function () {
198						if (
199						  request.readyState == XMLHttpRequest.DONE &&
200						  request.status == 200
201						) {
202							form.reset();
203							submitBtn.disabled = false;
204							
205							window.dataLayer = window.dataLayer || [];
206							window.dataLayer.push({
207								'event' : 'open-form'
208							});
209							window.dataLayer.push({
210								'event' : 'allform'
211							});
212							
213							jQuery('.gift-appeal .js-valid').removeClass('js-valid');
214							jQuery('.gift-appeal .js-error').removeClass('js-error');
215							// alert('Спасибо! Ваша заявка успешно отправлена!');
216							// Поднимаем тут какую-то модалку
217							jQuery('#success').modal('toggle');
218						} else if (
219						  request.readyState == XMLHttpRequest.DONE &&
220						  request.status != 200
221						) {
222							alert('Произошла ошибка отпраки, попробуйте снова чуть позже');
223							submitBtn.disabled = false;
224						}
225					};
226					request.send(formData);
227				}
228			});
229			
230			inputs.forEach((input) => {
231				input.addEventListener('focus', (e) => {
232					hideError(input);
233				});
234				input.addEventListener('input', (e) => {
235					validateInput(input);
236				});
237				input.addEventListener('blur', (e) => {
238					validateInput(input);
239				});
240			});
241
242			function validateForm() {
243				const areInputsValid = [...inputs].every((input) =>
244				  input.parentElement.classList.contains('js-valid')
245				);
246				if (areInputsValid) {
247					submitBtn.classList.remove('disabled');
248					return true;
249				} else {
250					submitBtn.classList.add('disabled');
251					return false;
252				}
253			}
254
255			function validateInput(target) {
256				
257				const type = target.dataset.validate;
258				
259				if (type === 'email') {
260					validateEmail(target);
261				} else if (type === 'phone') {
262					validatePhone(target);
263				} else {
264					if (jQuery(target).attr('name') === 'licenses') {
265						validateLicenses(target);
266					} else {
267						validateTextInput(target);
268					}
269				}
270
271				validateForm();
272			}
273		}
274    });
275
276    function isEmailValid(value) {
277        const emailRegex =
278          /(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.))+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]/i;
279        const result = value.match(emailRegex);
280        if (result && result[0]) return true;
281        return false;
282    }
283
284    function validatePhone(phone) {
285        const isValid = Inputmask.isValid(phone.value, {
286            mask: phoneMask,
287        });
288
289        debugger;
290
291        if (isValid) {
292            showValid(phone);
293        } else {
294            showError(phone);
295        }
296
297        return isValid;
298    }
299
300    function validateEmail(input) {
301        if (input.value.length === 0 || !isEmailValid(input.value)) {
302            showError(input);
303        } else {
304            showValid(input);
305        }
306    }
307
308    function validateTextInput(input) {
309        if (input.value.trim().length === 0) {
310            showError(input);
311        } else {
312            showValid(input);
313        }
314    }
315
316    function validateLicenses(input) {
317        if (jQuery(input).is(':checked')) {
318            showValid(input);
319        } else {
320            showError(input);
321        }
322    }
323
324    function showError(input) {
325        input.parentElement.classList.remove('js-valid');
326        input.parentElement.classList.add('js-error');
327    }
328
329    function showValid(input) {
330        input.parentElement.classList.remove('js-error');
331        input.parentElement.classList.add('js-valid');
332    }
333
334    function hideError(input) {
335        input.parentElement.classList.remove('js-error');
336    }
337	
338});

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.