Advertisement
Igor150195

lpc core

Nov 2nd, 2023
756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var s3LP = {
  2.     init: function(options) {
  3.         var self = this;
  4.         if (options){
  5.             this.is_cms = options.is_cms ? true : false;
  6.         }
  7.         console.log(document.location)
  8.         this.initForms();
  9.  
  10.         try {
  11.             lp_init($('body'));
  12.         } catch(e) {
  13.             console.log(e);
  14.         }
  15.         this.pageBlocking();
  16.        
  17.         self.popupForm();
  18.        
  19.         document.dispatchEvent(new Event('lpcPopupFormInitDone', {bubbles: true}));
  20.        
  21.         if ($('body').find('._lp-image-container').length) {
  22.             if (!window.hasOwnProperty('img_convert_cache')) {
  23.                 window.img_convert_cache = {};
  24.             }
  25.             var debounce = (function () {
  26.                 return function (fn, time) {
  27.                     var timer, func;
  28.                     func = function() {
  29.                         var args = [].slice.call(arguments, 0);
  30.                         window.clearTimeout(timer);
  31.                         timer = window.setTimeout(function () {
  32.                             window.requestAnimationFrame && window.requestAnimationFrame(function() {
  33.                                 fn.apply(null, args);
  34.                             }) || fn.apply(null, args);
  35.                         }, time)
  36.                     };
  37.                     return func;
  38.                 }
  39.             }());
  40.             self.convertImages($('body'));
  41.             $(window).on('resize', debounce(function() {
  42.                 self.convertImages($('body'));
  43.             }, 200));
  44.         }  
  45.     },
  46.     pageBlocking: function() {
  47.         if (s3LP.page_blocking) {
  48.             $('html, body').css({
  49.                 'overflow': 'hidden',
  50.                 'height': '100%'
  51.             });
  52.             $('<div />', {
  53.                 'class' : 'page-blocked'
  54.             }).appendTo($('body'));
  55.            
  56.             $('.page-blocked').css({
  57.                 'background': 'rgba(0,0,0,.8)',
  58.                 'position': 'absolute',
  59.                 'left': 0,
  60.                 'right': 0,
  61.                 'bottom': 0,
  62.                 'top': 0,
  63.                 'z-index': 100000,
  64.                 'color': '#fff',
  65.                 'font-size': '28px',
  66.                 'display': 'flex',
  67.                 'align-items': 'center',
  68.                 'flex-direction': 'column',
  69.                 'padding': '10px',
  70.                 'text-align': 'center',
  71.                 'line-height':'1.5',
  72.                 'align-items': 'center',
  73.                 'justify-content': 'center'
  74.             }).append('<b>Страница заблокирована</b><div style="font-size: 18px;">обратитесь в техническую поддержку</div>');
  75.         }
  76.     },
  77.     initForms: function(parent) {
  78.         //console.log(this.is_cms)
  79.        
  80.         var self = this;
  81.         if (!parent) parent = document;
  82.         if (!$(parent).is('[data-api-url][data-api-type=form]')) {
  83.             parent = $(parent).find('[data-api-url][data-api-type=form]');
  84.         }
  85.  
  86.         $(parent).each(function() {
  87.             var obj = $(this);
  88.             var form = obj.is("form") ? obj : obj.find("form");
  89.            
  90.             if (obj.data('s3form_inited')) {
  91.                 return;
  92.             }
  93.  
  94.             if (self.is_cms) {
  95.                 form.attr('title', JS_LP_FORM_NOTE).tooltip();
  96.                 form.submit(function() {
  97.                     return false;
  98.                 });
  99.             } else {
  100.                 form.submit(function() {
  101.                     $.post(obj.data('api-url'), form.serialize(), function(response) {
  102.                         if (response.result.success && response.result.redirect_url) {
  103.                             document.location = response.result.redirect_url;
  104.                         } else {
  105.                             if (response.result.html) {
  106.                                 var replacement = $(response.result.html.replace(/[\r\n]/g, '').replace(/<script[^>]*>.*?<\/script>/g, ''));
  107.                                 if (!$(replacement).is('[data-api-url][data-api-type=form]')) {
  108.                                     replacement = $(replacement).find('[data-api-url][data-api-type=form]');
  109.                                 }
  110.                                 obj.replaceWith(replacement);
  111.                                
  112.    
  113.                                 // Init form calendars
  114.                                 obj.find('.init-calendar').each(function(i){
  115.                                     new tcal({
  116.                                         'controlname':this.id,
  117.                                         'place':this.parentNode,
  118.                                         'lang':'ru'
  119.                                     });
  120.    
  121.                                 });
  122.    
  123.                                 // Init form calendar intervals
  124.                                 obj.find('.init-calendar-interval').each(function(i){
  125.                                     for(var j=0; j<2; ++j){
  126.                                         var e = f_getElement(this.id + '['+j+']');
  127.                                         new tcal({
  128.                                             'controlname':e.id,
  129.                                             'place':e.parentNode,
  130.                                             'lang':'ru',
  131.                                             'intervalpair':[
  132.                                                 this.id + '[0]',
  133.                                                 this.id + '[1]'
  134.                                             ],
  135.                                             'intervalupdatecont' : this.id
  136.                                         });
  137.                                     }
  138.                                 });
  139.                                
  140.                                 if (response.result && response.result.success && lpc_template){
  141.                                      replacement.closest(`.lpc-wrap`).find(`[class$=__title-wrap]`).remove();
  142.                                 }
  143.                                
  144.                                 var $captcha = replacement.find('input[name=_cn]');
  145.                                 if ($captcha.length) {
  146.                                     $.getScript('http://captcha.oml.ru/static/captcha.js?2', function() {
  147.                                         var $d = replacement.find("[id^=s3_captcha_cn]");
  148.                                         mgCaptcha.draw("/my/s3/captcha/get.php", ($d.length ? $d.get(0) : null));
  149.                                     });
  150.                                 }
  151.                                 self.initForms(replacement);
  152.                             }
  153.                         }
  154.                     });
  155.                     return false;
  156.                 });
  157.             }
  158.             obj.data('s3form_inited', true);
  159.         })
  160.     },
  161.  
  162.     convertImages: function ($container) {
  163.         var self = this;
  164.  
  165.         $container.find('._lp-image-container').each(function() {
  166.             var $img = $(this).find('img');
  167.  
  168.             if ($img.length) {
  169.                 var img_src = $img.attr('src');
  170.                 if (!window.img_convert_cache.hasOwnProperty(img_src)) window.img_convert_cache[img_src] = {};
  171.                 self.convertImg(window.img_convert_cache[img_src], $img);
  172.             }
  173.         });
  174.     },
  175.    
  176.  
  177.     popupForm: function() {
  178.         var $body = $('body'),
  179.             $html = $('html'),
  180.             self = this;
  181.  
  182.         $('<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);
  183.  
  184.         var $wrapper = $('.js-popup-wrapper'),
  185.             $newBlock,
  186.             $container = $wrapper.find('.js-popup-inner'),
  187.             $readyPopup = $body.find('[data-popup-type="ready"]'),
  188.             $finishPopup = $body.find('[data-popup-type="finish"]'),
  189.             $inactionPopup = $body.find('[data-popup-type="inaction"]'),
  190.             openedClass = '_opened',
  191.             $popupCookieTime = $body.find('[data-hide-time]').data('hide-time');
  192.            
  193.             var isFramed = false;
  194.             try {
  195.               isFramed = window != window.top || document != top.document || self.location != top.location;
  196.             } catch (e) {
  197.               isFramed = true;
  198.             }
  199.            
  200.         /*if($finishPopup.length) {
  201.             $finishPopup.each(function(){
  202.                 var $this = $(this);
  203.                
  204.                 if($this.parent('.lpc-popup-decor').length = 1){
  205.                     var $this = $this.closest('.lpc-popup-decor');
  206.                    
  207.                     $('html').one('mouseleave', function() {
  208.                         if(!self.is_cms){
  209.                             $newBlock = self.appendPopupForm($this, $container, $wrapper);
  210.                             if($this.parent('.lpc-popup-decor').length = 1){
  211.                                 document.dispatchEvent(new Event('lpcTriggerPopupInitDone', {bubbles: true}));
  212.                             }
  213.                         }
  214.                     });
  215.                 }
  216.             });
  217.         } */
  218.  
  219.         if ($readyPopup.length && document.location.search != "?no_panel=1") {
  220.  
  221.             $readyPopup.each(function() {
  222.                
  223.                 var $this = $(this);
  224.                
  225.                 console.log($this);
  226.                
  227.                 if($this.parent('.lpc-popup-decor').length = 1){
  228.                     var $this = $this.closest('.lpc-popup-decor');
  229.                 }
  230.                
  231.                 document.addEventListener("DOMContentLoaded", function() {
  232.                     console.log('js dom load');
  233.                 });
  234.  
  235.                
  236.                     setTimeout(function(){
  237.                         $newBlock = self.appendPopupForm($this, $container, $wrapper);
  238.                        
  239.                         if($this.parent('.lpc-popup-decor').length = 1){
  240.                             document.dispatchEvent(new Event('lpcTriggerPopupInitDone', {bubbles: true}));
  241.                         }
  242.                        
  243.                     }, +$this.data('popup-time'))
  244.                
  245.  
  246.                
  247.                
  248.                
  249.                
  250.                 /*setTimeout(function(){
  251.                     $newBlock = self.appendPopupForm($this, $container, $wrapper);
  252.                    
  253.                     if($this.parent('.lpc-popup-decor').length = 1){
  254.                         document.dispatchEvent(new Event('lpcTriggerPopupInitDone', {bubbles: true}));
  255.                     }
  256.                 }, +$this.data('popup-time'))*/
  257.             });
  258.         }
  259.        
  260.        
  261.         if ($inactionPopup.length) {
  262.             $inactionPopup.each(function() {
  263.                 var $this = $(this),
  264.                     thisTime = +$this.data('popup-time'),
  265.                     idleTimer = null,
  266.                     idleState = false;
  267.                
  268.                 if($this.parent('.lpc-popup-decor').length = 1){
  269.                     var $this = $this.closest('.lpc-popup-decor');
  270.                 }
  271.                
  272.                 $(document).on('keydown scroll', function(){
  273.                    
  274.                     clearTimeout(idleTimer); // отменяем прежний временной отрезок
  275.                
  276.                     if(idleState == true) return;
  277.                
  278.                     idleState = false;
  279.                    
  280.                     idleTimer = setTimeout(function(){
  281.                         $newBlock = self.appendPopupForm($this, $container, $wrapper);
  282.                         idleState = true;
  283.                         if($this.parent('.lpc-popup-decor').length = 1){
  284.                             document.dispatchEvent(new Event('lpcTriggerPopupInitDone', {bubbles: true}));
  285.                         }
  286.                     }, thisTime);
  287.                 });
  288.                
  289.                 $(document).trigger('mousemove');
  290.             });
  291.         }
  292.  
  293.         $body.on('click', 'a[href^="popup:"]', function(e){
  294.             e.preventDefault();
  295.            
  296.             if($(this).closest('.lp-popup-wrapper').length != 0) {
  297.                 $newBlock.appendTo($('body'));
  298.                 $container.html('');
  299.             }
  300.            
  301.             var $thisBlock = $('#' + this.href.replace(':', ''));
  302.            
  303.             if($thisBlock.length == 1) {
  304.                 $newBlock = self.appendPopupForm($thisBlock, $container, $wrapper);
  305.             }
  306.  
  307.            
  308.            
  309.         });
  310.        
  311.         $container.on('click', '.js-close-popup', function(e) {
  312.             e.preventDefault();
  313.            
  314.             if($newBlock.find('[data-popup-trigger-type]').length) {
  315.                 if($popupCookieTime == 30 || $popupCookieTime == 60) {
  316.                     var $new_minut = $popupCookieTime / 1440;
  317.                     createCookie("lpctrigger", "1", $new_minut);
  318.                 } else {
  319.                     createCookie("lpctrigger", "1", $popupCookieTime);
  320.                 }
  321.                 $newBlock.hide();
  322.             }
  323.            
  324.             $newBlock.appendTo($('body'));
  325.            
  326.             $container.html('');
  327.             $wrapper.removeClass(openedClass);
  328.            
  329.             $html.css({
  330.                 overflow: 'auto'
  331.             });
  332.            
  333.         });
  334.        
  335.         $(document).on('keyup', function(e){
  336.             if (e.keyCode != 27) return;
  337.             if($newBlock){
  338.            
  339.                 if($newBlock.find('[data-popup-trigger-type]').length) {
  340.                     if($popupCookieTime == 30 || $popupCookieTime == 60) {
  341.                         var $new_minut = $popupCookieTime / 1440;
  342.                         createCookie("lpctrigger", "1", $new_minut);
  343.                     } else {
  344.                         createCookie("lpctrigger", "1", $popupCookieTime);
  345.                     }
  346.                     $newBlock.hide();
  347.                 }
  348.                
  349.                 $newBlock.appendTo($('body'));
  350.             }
  351.             $container.html('');
  352.             $wrapper.removeClass(openedClass);
  353.            
  354.             $html.css({
  355.                 overflow: 'auto'
  356.             });
  357.         });
  358.     },
  359.  
  360.  
  361.     appendPopupForm: function($block, $container, $wrap) {
  362.         var $newBlock = $block.prependTo($container),
  363.             $html = $('html'),
  364.             openedClass = '_opened';
  365.            
  366.         if (!$wrap.find('.lp-form-step-popup-inner').length) {
  367.             var $uploads = $container.find('input[type="hidden"][id^="hidUploadField"]');
  368.  
  369.             if ($uploads.length) {
  370.                 $uploads.each(function(){
  371.                     var thisAttr = $(this).data('init-upload');
  372.                     newSWFU(void 0, thisAttr);
  373.                 });
  374.             }
  375.            
  376.         } else {
  377.             var $block = $wrap.find('.js-lp-steps-form');
  378.             $block.html('');
  379.             $block.formsteps();
  380.         }
  381.        
  382.         $html.css({
  383.             overflow: 'hidden'
  384.         });
  385.  
  386.         $wrap.addClass(openedClass);
  387.        
  388.         return $newBlock;
  389.     },
  390.  
  391.     convertImg : function (cache_img, $img) {
  392.         var self = this;
  393.         $img.css({"max-width": "100%", "max-height": "100%"});
  394.  
  395.         if (!$img.parent().hasClass('lp-img-contain')) {
  396.             var img_width,
  397.                 img_height;
  398.  
  399.             if (!cache_img.hasOwnProperty('width') || !cache_img.hasOwnProperty('height')) {
  400.                 if ($img.is('svg') || ($img.attr('src') && $img.attr('src').slice(-3) == 'svg')) {
  401.                     img_width = $img.parent().width();
  402.                     img_height = $img.parent().height();
  403.                 } else {
  404.                     img_width = $img[0].naturalWidth;
  405.                     img_height = $img[0].naturalHeight;
  406.                 }
  407.             } else {
  408.                 img_width = cache_img.width;
  409.                 img_height = cache_img.height;
  410.             }
  411.  
  412.             self.setImgStyles($img, img_width, img_height, null);
  413.         }
  414.     },
  415.  
  416.     setImgStyles: function ($img, img_width, img_height, svg) {
  417.         var $wrap = $img.parent();
  418.         var wrap_width = parseInt($wrap.width()),
  419.             wrap_height = parseInt($wrap.height()),
  420.             wrap_prop = wrap_width/wrap_height;
  421.  
  422.         var min_width = wrap_height/img_height * img_width;
  423.  
  424.         if(img_width && img_height) {
  425.             var img_prop = img_width/img_height;
  426.  
  427.             if (wrap_prop > img_prop) {
  428.                 $img.css({"max-width": "100%", "width": img_width > wrap_width ? wrap_width : img_width, "min-width": "0", "max-height": "none", "height": "auto"});
  429.             } else {
  430.                 $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});
  431.  
  432.                 if (svg) {
  433.                     $img.css('min-height', '100%');
  434.                 }
  435.             }
  436.         }
  437.     }
  438. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement