PageSourceSearch

https://konstantinkult.ru/g/s3/lp/js/lp.core.js

js konstantinkult.ru collected 2026-10-08 22:40:06 UTC 15,466 bytes, 547 lines download raw bytes

1var s3LP = {
2	init: function(options) {
3		var self = this;
4		if (options){
5			this.is_cms = options.is_cms ? true : false;
6		}
7		this.initForms();
8
9		lp_init($('body'));
10
11		self.popupForm();
12		
13		if (s3LP.page_blocking) {
14			self.pageBlocking();
15		}
16		
17		if ($('body').find('._lp-image-container').length) {
18			if (!window.hasOwnProperty('img_convert_cache')) {
19				window.img_convert_cache = {};
20			}
21			var debounce = (function () {
22				return function (fn, time) {
23					var timer, func;
24					func = function() {
25						var args = [].slice.call(arguments, 0);
26						window.clearTimeout(timer);
27						timer = window.setTimeout(function () {
28							window.requestAnimationFrame && window.requestAnimationFrame(function() {
29								fn.apply(null, args);
30							}) || fn.apply(null, args);
31						}, time)
32					};
33					return func;
34				}
35			}());
36			self.convertImages($('body'));
37			$(window).on('resize', debounce(function() {
38				self.convertImages($('body'));
39			}, 200));
40		}
41	},
42
43	pageBlocking: function() {
44		$('html, body').css({
45			'overflow': 'hidden',
46			'height': '100%'
47		});
48		$('<div />', {
49			'class' : 'page-blocked'
50		}).appendTo($('body'));
51		
52		$('.page-blocked').css({
53			'background': 'rgba(0,0,0,.8)',
54			'position': 'absolute',
55			'left': 0,
56			'right': 0,
57			'bottom': 0,
58			'top': 0,
59			'z-index': 100000,
60			'color': '#fff',
61			'font-size': '28px',
62			'display': 'flex',
63			'align-items': 'center',
64			'flex-direction': 'column',
65			'padding': '10px',
66			'text-align': 'center',
67			'line-height':'1.5',
68			'align-items': 'center',
69			'justify-content': 'center'
70		}).append('<b>Страница заблокирована</b><div style="font-size: 18px;">обратитесь в техническую поддержку</div>');
71
72	},
73
74	initForms: function(parent) {
75		var self = this;
76		if (!parent) parent = document;
77		if (!$(parent).is('[data-api-url][data-api-type=form]')) {
78			parent = $(parent).find('[data-api-url][data-api-type=form]');
79		}
80
81		$(parent).each(function() {
82			var obj = $(this);
83			var objParent = obj.closest('[data-block-layout]');
84			var form = obj.is("form") ? obj : obj.find("form");
85
86			if (self.is_cms) {
87				form.attr('title', JS_LP_FORM_NOTE).tooltip();
88				form.submit(function() {
89					return false;
90				});
91			} else if (!form.data('anketa2')) {
92				form.submit(function(event) {
93				
94					/*var inputPhone = $(form).find('input[data-validator="phone"]'),
95						inputPhonesError = false;
96				
97					inputPhone.each(function(i){
98						if ($(this).val() != '' || $(this).parents('.tpl-field').hasClass('field-required')) {
99							var validateField = s3LP.validateFormFields($(this).val(), "phone");
100							if (!validateField.valid) {
101								inputPhonesError = true;
102								$(this).parents('.tpl-field').addClass('field-error');
103							}
104						}
105					});
106					
107					if (inputPhonesError) {
108						return false;
109					}*/
110					
111					$.post(obj.data('api-url'), form.serialize(), function(response) {
112						if (response.result.success && response.result.redirect_url) {
113							document.location.href = response.result.redirect_url.replace(/&amp;/g, '&');
114						} else {
115							if (response.result.html) {
116
117								var replacement = $(response.result.html.replace(/[\r\n]/g, '').replace(/<script[^>]*>.*?<\/script>/g, ''));
118								
119								var uploaders_inits = '';
120								var scripts = response.result.html.match(/<script[^>]*>[^<]*newSWFU[^<]*<\/script>/gm);
121								if (scripts) {
122									for (var i = 0; i < scripts.length; i++) {
123										uploaders_inits += scripts[i].replace(/<script[^>]*>([^<]+)<\/script>/, "$1");
124									}
125								}
126
127								if (!$(replacement).is('[data-api-url][data-api-type=form]')) {
128									replacement = $(replacement).find('[data-api-url][data-api-type=form]');
129								}
130								
131								obj.replaceWith(replacement);
132								
133								if (response.result && response.result.success){
134									replacement.parent().find(`[data-path="title"]`).parent().remove();
135								}
136								
137								if (typeof self.successForm == 'function' && response.result.success) {
138									self.successForm(objParent);
139								}
140								
141								var inputMask = $('input[data-mask="mask"]');
142								if (inputMask.length) {
143									$.getScript('/g/libs/jquery-maskedinput/1.3.1//jquery.maskedinput.min.js', function() {
144										inputMask.mask("+7 (999) 999-99-99");
145									});
146								}
147								
148								var inputDates = $('input[data-calendar="calendar"], input[data-calendar="calendar-interval"]');
149								
150								if (inputDates.length) {
151									$.getScript('/g/s3/lp/js//datepicker.min.js', function() {
152										var inputCalender = $('input[data-calendar="calendar"]'),
153											inputCalenderInterval = $('input[data-calendar="calendar-interval"]');
154											
155										if (typeof lp_template.datepicker == 'function') {
156											lp_template.datepicker.call(inputCalender)
157										}
158										
159										if (typeof lp_template.datepicker_range == 'function') {
160											lp_template.datepicker_range.call(inputCalenderInterval)
161										}
162									});
163								}
164			
165								function inituploaders() {
166									if (uploaders_inits) {
167										eval(uploaders_inits);
168									}
169								}
170								
171								var $captcha = replacement.find('input[name=_cn]');
172								if ($captcha.length) {
173									$.getScript('http://captcha.oml.ru/static/captcha.js?2', function() {
174										var $d = replacement.find("[id^=s3_captcha_cn]");
175										mgCaptcha.draw("/my/s3/captcha/get.php", ($d.length ? $d.get(0) : null));
176									});
177								}
178								
179								self.initForms(replacement);
180								
181								var $uploads = obj.find('input[type="hidden"][id^="hidUploadField"]');
182								if ($uploads.length) {
183									if (!!$uploads.eq(0).closest('form').data('new-inited-upload')) {
184										var $newUploads = replacement.find('input[type="hidden"][id^="hidUploadField"]');
185										$newUploads.each(function(){
186											var thisAttr = $(this).data('init-upload');
187											newSWFU.apply(void 0, thisAttr);
188											
189										});
190									} else {
191										if (typeof window['newSWFU'] !== 'function') {
192											$.getScript('/assets/site/s3/plupload/plupload.all.pack.js', function() {
193												inituploaders();
194											});
195										} else {
196											inituploaders();
197										}
198									}
199								}
200							}
201						}
202					});
203					event.preventDefault();
204				});
205			}
206		})
207	},
208
209	validateFormFields: function(value, type, options) {
210		if (value == undefined) {
211			console.log("Error: " + type + " - value is undefined");
212			return false;
213		}
214		
215		var settings = options || {
216			canBeEmpty: false,
217			messages: {
218				EMPTY_FIELD: "Заполните поле",
219				WRONG_EMAIL: "Некорректный E-mail",
220				WRONG_SITE: "Некорректный адрес сайта",
221				WRONG_PHONE: "Некорректный номер",
222				TOO_SHORT_PHONE: "Короткий номер"
223			}
224		};
225
226		var reg = null;
227		var response = {
228			valid: true,
229			message: '',
230			empty: false
231		};
232		value = value.trim();
233		
234		switch (type) {
235			case 'phone':
236				reg = /^[\+\-\d\s\(\)]+$/i;
237				response.message = settings.messages.WRONG_PHONE;
238				break;
239
240			case 'email':
241				reg = /^.+@.+\..+$/i;
242				response.message = settings.messages.WRONG_EMAIL;
243				break;
244			case 'site':
245				reg = /^.+\..{2,}$/i;
246				response.message = settings.messages.WRONG_SITE;
247				break;
248			default:
249				reg = /.+/;
250				response.message = settings.messages.EMPTY_FIELD;
251				break;
252		}
253		response.empty = (value.length == 0);
254		if (response.empty) {
255			if (settings.canBeEmpty) {
256				response.valid = true;
257				return response;
258			} else {
259				response.valid = false;
260				response.message = settings.messages.EMPTY_FIELD;
261				return response;
262			}
263		}
264
265		response.valid = reg.test(value);
266
267		if (!response.valid) {
268			return response;
269		}	else if (type === 'phone') {
270			var tmp = value.match(/\d/g);
271			if (!tmp || tmp.length < 7) {           // кол-во цифр в строке.
272				response.valid = false;
273				response.message = settings.messages.TOO_SHORT_PHONE;
274				return response;
275			}
276		}
277
278		return response;
279	},
280
281	popupForm: function() {
282		var $body = $('body'),
283			$html = $('html'),
284			self = this;
285
286		$('<div class="lp-popup-wrapper js-popup-wrapper"><div class="lp-popup-overlay"></div><div class="lp-popup-inner js-popup-inner"></div></div>').appendTo($body);
287
288		var $wrapper = $('.js-popup-wrapper'),
289			$newBlock = null,
290			$container = $wrapper.find('.js-popup-inner'),
291			$readyPopup = $body.find('[data-popup-type="ready"]'),
292			$finishPopup = $body.find('[data-popup-type="finish"]'),
293			$inactionPopup = $body.find('[data-popup-type="inaction"]'),
294			$popupCookieTime = $body.find('[data-hide-time]').data('hide-time');
295			openedClass = '_opened';
296
297		var isFramed = false;
298	    try {
299	        isFramed = window != window.top || document != top.document || self.location != top.location;
300	    } catch (e) {
301	        isFramed = true;
302	    }
303		
304		if ($finishPopup.length) {
305	        $finishPopup.each(function () {
306	            var $this = $(this);
307	            $('html').one('mouseleave', function () {
308	                if (!$wrapper.hasClass(openedClass) && !self.is_cms) {
309	                    $newBlock = self.appendPopupForm($this, $container, $wrapper);
310	                    if ($this.parent('.lpc-popup-decor').length === 1) {
311	                        document.dispatchEvent(new Event('lpcTriggerPopupInitDone', {
312	                            bubbles: true
313	                        }));
314	                    }
315	                }
316	            });
317	        });
318	    }
319		
320		function popupTimer() {
321			if ($readyPopup.length) {
322				$readyPopup.each(function() {
323					var $this = $(this);
324					
325					setTimeout(function(){
326						if (!$wrapper.hasClass(openedClass) && !self.is_cms) {
327							$newBlock = self.appendPopupForm($this, $container, $wrapper);
328						}
329					}, +$this.data('popup-time'))
330				});
331			}
332		};
333		
334		popupTimer();
335		
336		if ($inactionPopup.length) {
337			$inactionPopup.each(function() {
338				var $this = $(this),
339					thisTime = +$this.data('popup-time'),
340					idleTimer = null,
341					idleState = false;
342					
343				$(document).on('mousemove keydown scroll', function(){
344					clearTimeout(idleTimer); // отменяем прежний временной отрезок
345				
346					if(idleState == true) return;
347				
348					idleState = false;
349					
350					idleTimer = setTimeout(function(){ 
351						if (!$wrapper.hasClass(openedClass)) {
352							$newBlock = self.appendPopupForm($this, $container, $wrapper);
353							idleState = true; 
354						};
355					}, thisTime);
356				});
357				
358				$(document).trigger('mousemove');
359			});
360		}
361
362		$body.on('click', 'a[href^="popup:"]', function(e){
363			e.preventDefault();
364			
365			var $thisBlock = $('#' + this.href.replace(':', ''));
366			
367			if ($thisBlock.length == 1) {
368				if (!$wrapper.hasClass(openedClass)) {
369					$newBlock = self.appendPopupForm($thisBlock, $container, $wrapper, $newBlock);
370				}
371			}
372
373			if ($(this).closest('.lp-popup-wrapper').length != 0) {
374	            $newBlock.appendTo($('body'));
375	            $container.html('');
376	            
377	            var $thisBlock = $('#' + this.href.replace(':', ''));
378	            
379	            $newBlock = self.appendPopupForm($thisBlock, $container, $wrapper, $newBlock);
380	        }
381		});
382		
383		$container.on('click', '.js-close-popup', function(e) {
384			e.preventDefault();
385			
386			if ($newBlock.find('[data-popup-trigger-type]').length) {
387	            if ($popupCookieTime == 30 || $popupCookieTime == 60) {
388	                var $new_minut = $popupCookieTime / 1440;
389	                createCookie("lptrigger", "1", $new_minut);
390	            } else {
391	                createCookie("lptrigger", "1", $popupCookieTime);
392	            }
393	            $newBlock.hide();
394	        }
395			
396			$newBlock.appendTo($('body'));
397			$newBlock = null;
398			
399			$container.html('');
400			$wrapper.removeClass(openedClass);
401			
402			$html.css({
403				overflow: 'auto'
404			});
405
406
407			/*if (!$wrapper.hasClass(openedClass)) {
408	            popupTimer();
409	        }*/
410		});
411		
412		$container.on('click',  function (e) {
413	    	if (s3LP.templateID == 1461 && !$(e.target).closest('.lp-popup-body').length){
414	    		e.preventDefault();
415
416				if ($newBlock) {
417					$newBlock.appendTo($('body'));
418					$newBlock = null;
419				}
420				
421				$container.html('');
422				$wrapper.removeClass(openedClass);
423				
424				$html.css({
425					overflow: 'auto'
426				});
427	    	}
428	    });
429		
430		$(document).on('keyup', function(e){
431			if (e.keyCode != 27) return;
432			
433			if ($newBlock) {
434				$newBlock.appendTo($('body'));
435				$newBlock = null;
436			}
437			
438			$container.html('');
439			$wrapper.removeClass(openedClass);
440			
441			$html.css({
442				overflow: 'auto'
443			});
444
445			/*if (!$wrapper.hasClass(openedClass)) {
446	            popupTimer();
447	        }*/
448		});
449	},
450
451	appendPopupForm: function($block, $container, $wrap, $newBlock) {
452		if ($newBlock) {
453			$newBlock.appendTo($('body'));
454		}
455
456		var $newBlock2 = $block.prependTo($container),
457			$html = $('html'),
458			openedClass = '_opened';
459			
460		if (!$wrap.find('.lp-form-step-popup-inner').length) {
461			var $uploads = $container.find('input[type="hidden"][id^="hidUploadField"]');
462
463			if ($uploads.length) {
464				$uploads.each(function(){
465					var thisAttr = $(this).data('init-upload');
466					newSWFU(void 0, thisAttr);
467				});
468			}
469			
470		} else {
471			var $block = $wrap.find('.js-lp-steps-form');
472			$block.html('');
473			$block.formsteps();
474		}
475		
476		$html.css({
477			overflow: 'hidden'
478		});
479
480		$wrap.addClass(openedClass);
481		
482		return $newBlock2;
483		
484	},
485	
486	convertImages: function ($container) {
487		var self = this;
488
489		$container.find('._lp-image-container').each(function() {
490			var $img = $(this).find('img');
491
492			if ($img.length) {
493				var img_src = $img.attr('src');
494				if (!window.img_convert_cache.hasOwnProperty(img_src)) window.img_convert_cache[img_src] = {};
495				self.convertImg(window.img_convert_cache[img_src], $img);
496			}
497		});
498	},
499
500	convertImg : function (cache_img, $img) {
501		var self = this;
502		$img.css({"max-width": "100%", "max-height": "100%"});
503
504		if (!$img.parent().hasClass('lp-img-contain')) {
505			var img_width,
506				img_height;
507
508			if (!cache_img.hasOwnProperty('width') || !cache_img.hasOwnProperty('height')) {
509				if ($img.is('svg') || ($img.attr('src') && $img.attr('src').slice(-3) == 'svg')) {
510					img_width = $img.parent().width();
511					img_height = $img.parent().height();
512				} else {
513					img_width = $img[0].naturalWidth;
514					img_height = $img[0].naturalHeight;
515				}
516			} else {
517				img_width = cache_img.width;
518				img_height = cache_img.height;
519			}
520
521			self.setImgStyles($img, img_width, img_height, null);
522		}
523	},
524
525	setImgStyles: function ($img, img_width, img_height, svg) {
526		var $wrap = $img.parent();
527		var wrap_width = parseInt($wrap.width()),
528			wrap_height = parseInt($wrap.height()),
529			wrap_prop = wrap_width/wrap_height;
530
531		var min_width = wrap_height/img_height * img_width;
532
533		if(img_width && img_height) {
534			var img_prop = img_width/img_height;
535
536			if (wrap_prop > img_prop) {
537				$img.css({"max-width": "100%", "width": img_width > wrap_width ? wrap_width : img_width, "min-width": "0", "max-height": "none", "height": "auto"});
538			} else {
539				$img.css({"max-width": "none", "width": "auto", "min-width": min_width > img_width ? img_width : min_width, /*"min-height": "100%",*/  "max-height": "100%", "height": img_height > wrap_height ? wrap_height : img_height});
540
541				if (svg) {
542					$img.css('min-height', '100%');
543				}
544			}
545		}
546	}
547}

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.