Advertisement
sta-s2z

Untitled

Feb 9th, 2016
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($) {
  2.  
  3.     $(document).ready(function(){
  4.         $('.arrowup').hide();
  5.  
  6.         $('.arrowup').on('click', function(){
  7.             var scrolled = window.pageYOffset || document.documentElement.scrollTop;
  8.             if(scrolled >= 1000)
  9.                 $("html, body").stop().animate({ scrollTop: 0 }, "slow");
  10.         });
  11.  
  12.         if($('#label1').length > 0){
  13.             var label1 = $('#label1').offset().top;
  14.         }
  15.         if($('#label2').length > 0){
  16.             var label2 = $('#label2').offset().top;
  17.         }
  18.         if($('#label3').length > 0){
  19.             var label3 = $('#label3').offset().top;
  20.         }
  21.  
  22.         window.onscroll = function() {
  23.             var scrolled = window.pageYOffset || document.documentElement.scrollTop;
  24.             if(scrolled >= 1000)
  25.                 $('.arrowup').show();
  26.             else
  27.                 $('.arrowup').hide();
  28.  
  29.             if(scrolled < label1 && scrolled != 0){
  30.                 //$("html, body").stop().animate({ scrollTop: label1 }, "fast");
  31.             }
  32.  
  33.         }
  34.  
  35.  
  36.         //Inputmask
  37.         if($('.tel').length > 0)
  38.             $('.tel').inputmask();
  39.  
  40.  
  41.         if($("#inputzip").length > 0){
  42.             $("#inputzip").fileinput({language: 'ru', showCaption: true, showPreview: false, showRemove: false,
  43.                 showUpload: false,
  44.                 showClose: false,
  45.                 allowedFileExtensions: ['zip'],
  46.                 maxFileCount: 1
  47.             });
  48.         }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.         function checkField(type, field){
  55.             var pattern = '';
  56.             field = $.trim(field);
  57.  
  58.             switch(type){
  59.                 case 'text':
  60.                     //pattern = new RegExp(/^[а-яА-Яa-zA-Zё -]{1,10000}$/);
  61.                     if(field != '')
  62.                         return true;
  63.                     else
  64.                         return false;
  65.                     //return pattern.test(field);
  66.                     break;
  67.  
  68.                 case 'textand':
  69.                     //pattern = new RegExp(/^[а-яА-Яa-zA-Z" ё]{1,10000}$/);
  70.                     //return pattern.test(field);
  71.                     if(field != '')
  72.                         return true;
  73.                     else
  74.                         return false;
  75.  
  76.                     break;
  77.                 case 'textandspec':
  78.                     //pattern = new RegExp(/^[а-яА-Яa-zA-Z0-9ё" ,\(\).\/\-№;:!\n]{1,10000}$/);
  79.                     //return pattern.test(field);
  80.  
  81.                     if(field != '')
  82.                         return true;
  83.                     else
  84.                         return false;
  85.  
  86.                     break;
  87.  
  88.                 case 'digital':
  89.                     //pattern = new RegExp(/^[0-9 ]{1,10000}$/);
  90.                     //return pattern.test(field);
  91.                     if(field != '')
  92.                         return true;
  93.                     else
  94.                         return false;
  95.  
  96.                     break;
  97.  
  98.                 case 'digitaland':
  99.                     //pattern = new RegExp(/^[0-9\- \(\)]{1,10000}$/);
  100.                     //return pattern.test(field);
  101.                     if(field != '')
  102.                         return true;
  103.                     else
  104.                         return false;
  105.  
  106.                     break;
  107.  
  108.                 case 'tel':
  109.                     pattern = new RegExp(/^\+7\([0-9]{3}\)[0-9]{3}-[0-9]{2}-[0-9]{2}$/);
  110.                     return pattern.test(field);
  111.                     break;
  112.  
  113.                 case 'date':
  114.                     pattern = new RegExp(/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}$/);
  115.                     return pattern.test(field);
  116.                     break;
  117.  
  118.                 case 'url':
  119.                     pattern = new RegExp(/^(https?:\/\/)?([\da-zA-Zа-я\.-]+)\.([a-zа-я\.]{2,6})([\/\w \.-]*)*\/?$/);
  120.                     return pattern.test(field);
  121.                     break;
  122.  
  123.  
  124.                 case 'email':
  125.                     pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
  126.                     return pattern.test(field);
  127.                     break;
  128.  
  129.  
  130.  
  131. //              case 'onlyletter':
  132. //                  pattern = new RegExp(/^[а-яА-Яa-zA-Z ]{3,25}$/);
  133. //                  return pattern.test(field);
  134. //                  break;
  135. //
  136. //              case 'letternumber':
  137. //                  pattern = new RegExp(/^[а-яА-Яa-zA-Z0-9 ]{3,100}$/);
  138. //                  return pattern.test(field);
  139. //                  break;
  140. //
  141. //              case 'letternumber2':
  142. //                  pattern = new RegExp(/^[а-яА-Яa-zA-Z0-9 ,№]{3,100}$/);
  143. //                  return pattern.test(field);
  144. //                  break;
  145. //
  146. //              case 'login':
  147. //                  pattern = new RegExp(/^[a-zA-Z0-9]{3,25}$/);
  148. //                  return pattern.test(field);
  149. //                  break;
  150.  
  151.             }
  152.  
  153.         }
  154.  
  155.         function checkForm(){
  156.             $('[data-kivvalidation]').each(function(){
  157.  
  158.                 var type = $(this).data('kivtype');
  159.                 var res = '';
  160.  
  161.                 //debugger;
  162.                 switch(type){
  163.                     case 'text':
  164.                         res = checkField('text', $(this).val());
  165.  
  166.                         if(res){
  167.                             $(this).addClass('validfield');
  168.                             $(this).removeClass('invalidfield');
  169.                         }else{
  170.                             //empty and necessary? OR not empty and not necessary
  171.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  172.                                 $(this).addClass('invalidfield');
  173.                                 $(this).removeClass('validfield');
  174.                             }else{
  175.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  176.                                     $(this).addClass('validfield');
  177.                                     $(this).removeClass('invalidfield');
  178.                                 }
  179.                             }
  180.  
  181.                         }
  182.                         break;
  183.                     case 'textand':
  184.                         res = checkField('textand', $(this).val());
  185.                         if(res){
  186.                             $(this).addClass('validfield');
  187.                             $(this).removeClass('invalidfield');
  188.                         }else{
  189.                             //empty and necessary? OR not empty and not necessary
  190.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  191.                                 $(this).addClass('invalidfield');
  192.                                 $(this).removeClass('validfield');
  193.                             }else{
  194.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  195.                                     $(this).addClass('validfield');
  196.                                     $(this).removeClass('invalidfield');
  197.                                 }
  198.                             }
  199.                         }
  200.                         break;
  201.                     case 'textandspec':
  202.                         res = checkField('textandspec', $(this).val());
  203.                         if(res){
  204.                             $(this).addClass('validfield');
  205.                             $(this).removeClass('invalidfield');
  206.                         }else{
  207.                             //empty and necessary? OR not empty and not necessary
  208.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  209.                                 $(this).addClass('invalidfield');
  210.                                 $(this).removeClass('validfield');
  211.                             }else{
  212.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  213.                                     $(this).addClass('validfield');
  214.                                     $(this).removeClass('invalidfield');
  215.                                 }
  216.                             }
  217.  
  218.                         }
  219.                         break;
  220.  
  221.                     case 'digital':
  222.                         res = checkField('digital', $(this).val());
  223.                         if(res){
  224.                             $(this).addClass('validfield');
  225.                             $(this).removeClass('invalidfield');
  226.                         }else{
  227.                             //empty and necessary? OR not empty and not necessary
  228.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  229.                                 $(this).addClass('invalidfield');
  230.                                 $(this).removeClass('validfield');
  231.                             }else{
  232.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  233.                                     $(this).addClass('validfield');
  234.                                     $(this).removeClass('invalidfield');
  235.                                 }
  236.                             }
  237.  
  238.                         }
  239.                         break;
  240.                     case 'digitaland':
  241.                         res = checkField('digitaland', $(this).val());
  242.                         if(res){
  243.                             $(this).addClass('validfield');
  244.                             $(this).removeClass('invalidfield');
  245.                         }else{
  246.                             //empty and necessary? OR not empty and not necessary
  247.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  248.                                 $(this).addClass('invalidfield');
  249.                                 $(this).removeClass('validfield');
  250.                             }else{
  251.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  252.                                     $(this).addClass('validfield');
  253.                                     $(this).removeClass('invalidfield');
  254.                                 }
  255.                             }
  256.  
  257.                         }
  258.                         break;
  259.                     case 'email':
  260.                         res = checkField('email', $(this).val());
  261.                         if(res){
  262.                             $(this).addClass('validfield');
  263.                             $(this).removeClass('invalidfield');
  264.                         }else{
  265.                             //empty and necessary? OR not empty and not necessary
  266.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  267.                                 $(this).addClass('invalidfield');
  268.                                 $(this).removeClass('validfield');
  269.                             }else{
  270.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  271.                                     $(this).addClass('validfield');
  272.                                     $(this).removeClass('invalidfield');
  273.                                 }
  274.                             }
  275.  
  276.                         }
  277.                         break;
  278.                     case 'tel':
  279.                         res = checkField('tel', $(this).val());
  280.                         if(res){
  281.                             $(this).addClass('validfield');
  282.                             $(this).removeClass('invalidfield');
  283.                         }else{
  284.                             //empty and necessary? OR not empty and not necessary
  285.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  286.                                 $(this).addClass('invalidfield');
  287.                                 $(this).removeClass('validfield');
  288.                             }else{
  289.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  290.                                     $(this).addClass('validfield');
  291.                                     $(this).removeClass('invalidfield');
  292.                                 }
  293.                             }
  294.                         }
  295.                         break;
  296.                     case 'checked':
  297.                         if($(this).prop('checked') && $(this).data('kivmusthave') == true){
  298.                             $(this).addClass('validfield');
  299.                             $(this).removeClass('invalidfield');
  300.                         }else{
  301.                             if($(this).data('kivmusthave') == false){
  302.                                 $(this).addClass('validfield');
  303.                                 $(this).removeClass('invalidfield');
  304.                             }else{
  305.                                 $(this).addClass('invalidfield');
  306.                                 $(this).removeClass('validfield');
  307.                             }
  308.                         }
  309.                         break;
  310.  
  311.                     case 'file':
  312.                         //res = checkField('file', $(this).val());
  313.                         var layout = $(this).data('kivlayout');
  314.                         switch(layout) {
  315.                             case 'bootstrap-inputfile':
  316.                                 if($(this).val() != '' && $(this).data('kivmusthave') == true){
  317.  
  318.                                     $(this).addClass('validfield');
  319.                                     $(this).removeClass('invalidfield');
  320.                                 }else{
  321.                                     if($(this).data('kivmusthave') == false){
  322.                                         //console.log($(this).data('kivmusthave'));
  323.                                         $(this).addClass('validfield');
  324.                                         $(this).removeClass('invalidfield');
  325.                                     }else{
  326.  
  327.                                         //console.log('2'+$(this).data('kivmusthave'));
  328.                                         $(this).addClass('invalidfield');
  329.                                         $(this).removeClass('validfield');
  330.  
  331.                                     }
  332.                                 }
  333.                                 break;
  334.                             default:
  335.                             //as usual
  336.  
  337.                         }
  338.  
  339.  
  340.                         break;
  341.  
  342.                     case 'date':
  343.                         res = checkField('date', $(this).val());
  344.                         if(res){
  345.                             $(this).addClass('validfield');
  346.                             $(this).removeClass('invalidfield');
  347.                         }else{
  348.                             //empty and necessary? OR not empty and not necessary
  349.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  350.                                 $(this).addClass('invalidfield');
  351.                                 $(this).removeClass('validfield');
  352.                             }else{
  353.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  354.                                     $(this).addClass('validfield');
  355.                                     $(this).removeClass('invalidfield');
  356.                                 }
  357.                             }
  358.                         }
  359.                         break;
  360.  
  361.                     case'url':
  362.                         res = checkField('url', $(this).val());
  363.                         if(res){
  364.                             $(this).addClass('validfield');
  365.                             $(this).removeClass('invalidfield');
  366.                         }else{
  367.                             //empty and necessary? OR not empty and not necessary
  368.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  369.                                 $(this).addClass('invalidfield');
  370.                                 $(this).removeClass('validfield');
  371.                             }else{
  372.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  373.                                     $(this).addClass('validfield');
  374.                                     $(this).removeClass('invalidfield');
  375.                                 }
  376.                             }
  377.                         }
  378.                         break;
  379.  
  380.  
  381.                     case 'select':
  382.                         res = checkField('textandspec', $(this).val()); //digital
  383.  
  384.                         if(res){
  385.  
  386.                             $(this).addClass('validfield');
  387.                             $(this).removeClass('invalidfield');
  388.                         }else{
  389.                             //empty and necessary? OR not empty and not necessary
  390.                             if(($(this).val() != '' && $(this).data('kivmusthave') == true) || ($(this).val() == '' && $(this).data('kivmusthave') == true) || ($(this).val() != '' && $(this).data('kivmusthave') == false)){
  391.  
  392.                                 $(this).addClass('invalidfield');
  393.                                 $(this).removeClass('validfield');
  394.                             }else{
  395.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  396.                                     $(this).addClass('validfield');
  397.                                     $(this).removeClass('invalidfield');
  398.                                 }
  399.                             }
  400.                         }
  401.  
  402.  
  403. //                          var select = $('.cd-dropdown input');
  404. //                          if(select.val() != ''){
  405. //                              select.addClass('validfield');
  406. //                              select.removeClass('invalidfield');
  407. //                          }else{
  408. //                              select.addClass('invalidfield');
  409. //                              select.removeClass('validfield');
  410. //                          }
  411.  
  412.                         break;
  413.  
  414.  
  415.                     case 'notempty':
  416.  
  417.                         if($(this).val() != ''){
  418.                             $(this).addClass('validfield');
  419.                             $(this).removeClass('invalidfield');
  420.                         }else{
  421.                             //empty and necessary? OR not empty and not necessary
  422.                             if($(this).val() == '' && $(this).data('kivmusthave') == true){
  423.                                 $(this).addClass('invalidfield');
  424.                                 $(this).removeClass('validfield');
  425.                             }else{
  426.                                 if($(this).val() == '' && $(this).data('kivmusthave') == false){
  427.                                     $(this).addClass('validfield');
  428.                                     $(this).removeClass('invalidfield');
  429.                                 }
  430.                             }
  431.                         }
  432.                         break;
  433.                 }
  434.             });
  435.  
  436.  
  437. //          if($('.kv-fileinput-error').length > 0){
  438. //              var inpt = $('.kv-fileinput-error');
  439. //              inpt.each(function(){
  440. //                  if($(this).html() != ''){
  441. //
  442. //                  }
  443. //              });
  444. //          }
  445.         }
  446.  
  447.  
  448.         //Подсветить ошибки
  449.         function lightError(form){
  450.             form.find('.lighterror').removeClass('lighterror');
  451.             var invfield = form.find('.invalidfield');
  452.             invfield.addClass('lighterror');
  453.             //выбор файла
  454.  
  455.             if(form.find('.file-input').find('.invalidfield').length > 0){
  456.                 form.find('.file-input').find('.invalidfield').each(function(){
  457.                     //$('.file-input').addClass('lighterror');
  458.                     //debugger;
  459.                     $(this).parents('.file-input').addClass('lighterror');
  460.                 })
  461.  
  462.             }
  463.  
  464.             if(form.find('.checkbox').hasClass('invalidfield'))
  465.                 form.find('.checkbox.invalidfield').parent().addClass('lighterror');
  466.  
  467.  
  468.             if($('#eduoffice_title').val() == '' && $('#other_work_place').val() == ''){
  469.                 $('#s2id_eduoffice').addClass('lighterror');
  470.                 $('#other_work_place').addClass('lighterror');
  471.             }else{
  472.                 $('#s2id_eduoffice').removeClass('lighterror');
  473.                 $('#other_work_place').removeClass('lighterror');
  474.             }
  475.  
  476. //          if(form.find('#eduoffice_title').hasClass('invalidfield')){
  477. //              form.find('#s2id_eduoffice').addClass('lighterror');
  478. //          }
  479.  
  480.             if(form.find('#work_okrug_title').hasClass('invalidfield')){
  481.                 form.find('#s2id_work_okrug').addClass('lighterror');
  482.             }
  483.  
  484.             if(form.find('.cd-dropdown input').hasClass('invalidfield')){
  485.                 form.find('.cd-dropdown input').parent().addClass('lighterror');
  486.             }
  487.  
  488.  
  489.             if(form.find('#school_name_hidden').hasClass('invalidfield')){
  490.                 form.find('.select2-container.rsform-input-box').addClass('lighterror');
  491.             }
  492.  
  493.         }
  494.  
  495.  
  496.  
  497.         var formvalidation = $('[data-kivvalidationform]');
  498.         if(formvalidation.length > 0){
  499.             btnsbmt = formvalidation.find("[data-kivbuttonsubmit]");
  500.  
  501.             btnsbmt.on('click', function(event){
  502.                 if($(this).hasClass('disabled')){
  503.                     // подсвечиваем незаполненные поля и форму не отправляем, если есть незаполненные поля
  504.                     //clearErrorLabel();
  505.                     lightError(formvalidation);
  506.                     //event.preventDefault();
  507.                     return false;
  508.                 }
  509.                 else{
  510.                     // Все хорошо, все заполнено, отправляем форму
  511.                     formvalidation.submit();
  512.                     $(this).hide();
  513.                 }
  514.             });
  515.  
  516.  
  517.  
  518.  
  519.  
  520.             setInterval(function(){
  521.                 // Запускаем функцию проверки полей на заполненность
  522.                 checkForm();
  523.  
  524.                 // Считаем к-во полей требующих проверки и успешно проверенных полей
  525.                 var countFiled = formvalidation.find('[data-kivvalidation]').length;
  526.                 var countTrueCheckedField = formvalidation.find('[data-kivvalidation].validfield').length;
  527.  
  528. console.log(countFiled);
  529. console.log(countTrueCheckedField);
  530.  
  531.                 // Вешаем условие-тригер на кнопку отправки формы
  532.                 if(countFiled != countTrueCheckedField){
  533.                     if(btnsbmt.hasClass('disabled')){
  534.                         return false
  535.                     } else {
  536.                         btnsbmt.addClass('disabled')
  537.                     }
  538.                 } else {
  539.                     console.log('undisable');
  540.                     btnsbmt.removeClass('disabled')
  541.                 }
  542.             }, 200);
  543.         }
  544.  
  545.  
  546.  
  547.         $('.idvideo').click(function(){
  548.             var youtubeid = $(this).data("youtube");
  549.             $("#modalvideo iframe").attr('src','//www.youtube.com/embed/'+youtubeid);
  550.         });
  551.  
  552.  
  553.         $('#modalvideo .lio_mod_close').on('click', function(){
  554.             //var num = jQuery(this).data('fid');
  555.             var video = $("#modalvideo iframe").attr("src");
  556.             $('#modalvideo iframe').attr("src","");
  557.             $('#modalvideo iframe').attr("src",video);
  558.  
  559.         });
  560.  
  561.         $('#ModalVideo').on('hidden.bs.modal', function (e) {
  562.             var video = $("#modalvideo iframe").attr("src");
  563.             $('#modalvideo iframe').attr("src","");
  564.             $('#modalvideo iframe').attr("src",video);
  565.         });
  566.  
  567.  
  568.  
  569.         $('#modalslides .lio_mod_close').on('click', function(){
  570.             //var num = jQuery(this).data('fid');
  571.  
  572.             $('#modalslides iframe').contents().find('video').each(function ()
  573.             {
  574.                 this.currentTime = 0;
  575.                 this.pause();
  576.             });
  577. //          var video = $("#modalslides iframe").attr("src");
  578. //          $('#modalslides iframe').attr("src","");
  579. //          $('#modalslides iframe').attr("src",video);
  580.  
  581.         });
  582.  
  583.         $('#ModalSlides').on('hidden.bs.modal', function (e) {
  584.             $('#modalslides iframe').contents().find('video').each(function ()
  585.             {
  586.                 this.currentTime = 0;
  587.                 this.pause();
  588.             });
  589. //          var video = $("#modalslides iframe").attr("src");
  590. //          $('#modalslides iframe').attr("src","");
  591. //          $('#modalslides iframe').attr("src",video);
  592.         });
  593.  
  594.  
  595.  
  596.  
  597.  
  598. //      $('.idslides').click(function(){
  599. //          var idslides = $(this).data("id");
  600. //          $("#modalslides").find('[data-id='+idslides+']').show();
  601. //      });
  602. //
  603. //      $('#modalslides .lio_mod_close').click(function(){
  604. //          $("#modalslides .modal-presentation").hide();
  605. //          debugger;
  606. //      });
  607. //
  608. //
  609. //      $('#ModalSlides').on('hidden.bs.modal', function (e) {
  610. //          $("#modalslides .modal-presentation").hide();
  611. //          debugger;
  612. //      });
  613.  
  614.  
  615.         $('.idimages').click(function(){
  616.             var idimages = $(this).data("id");
  617.             $("#modalimages").find('[data-id='+idimages+']').show();
  618.         });
  619.  
  620.         $('#modalimages .lio_mod_close').on('click', function(){
  621.             $("#modalimages .modal-images").hide();
  622.  
  623.         });
  624.  
  625.         $('#ModalImages').on('hidden.bs.modal', function (e) {
  626.             $("#modaliamges .modal-images").hide();
  627.         });
  628.  
  629.  
  630.  
  631.         $('#modalimages .carousel').carousel({'interval': 0});
  632.  
  633.         $('#modalimages .carousel').each(function(){
  634.             if($(this).find('.carousel-inner .item').length == 1){
  635.                 $(this).find('.carousel-control').hide();
  636.             }
  637.         });
  638.  
  639.  
  640.         $('#vfs .carousel').carousel({'interval': 0});
  641.  
  642.         $('#vfs .carousel').each(function(){
  643.             if($(this).find('.carousel-inner .item').length == 1){
  644.                 $(this).find('.carousel-control').hide();
  645.             }
  646.         });
  647.  
  648.  
  649.  
  650. //      $('.right').on('click', function(){
  651. //          console.log('right');
  652. //          $(this).carousel('next');
  653. //      });
  654. //
  655. //      $('.left').on('click', function(){
  656. //          console.log('left');
  657. //          $(this).carousel('prev');
  658. //      });
  659.  
  660.  
  661.         $('.reset').click(function(){
  662.  
  663.             $('.filt_name').val('');
  664.             $('.filt_nam').val('');
  665.             $('.filt_dist').val('');
  666.  
  667.             $('.cd-dropdown input').val('');
  668.         });
  669.  
  670.  
  671. //      $('.modal-presentation').each(function(){
  672. //          var src = $(this).data('url');
  673. //          var item = $(this);
  674. //
  675. //          if(src != ''){
  676. //              $.ajax({
  677. //                  type: "GET",
  678. //                  url: 'https://www.slideshare.net/api/oembed/2?url='+src,
  679. //                  dataType: 'jsonp',
  680. //                  success: function (data) {
  681. //                      //debugger;
  682. //                      console.log(data);
  683. //                      item.html(data.html);
  684. //                  }
  685. //              });
  686. //          }
  687. //
  688. //
  689. //      });
  690.  
  691.  
  692.  
  693.         if($('.vote-for-us').length > 0){
  694.  
  695.  
  696.  
  697.             function endOfScroll(){
  698.                 var $pdf = $('#pdf_iframe');
  699.                 var iframe = document.getElementById('pdf_iframe');
  700.                 setTimeout( function() {
  701.                     var heightOfIframe = $pdf.height();
  702.                     var heightOfPDF = $pdf.contents().height();
  703.  
  704.                     if(heightOfIframe > heightOfPDF - 20){
  705.                         voteVisible();
  706.                     }
  707.                     else {
  708.                         $pdf.contents().scroll(function () {
  709.                             var scrollHeight = $pdf.contents().scrollTop();
  710.                             if (scrollHeight + heightOfIframe > heightOfPDF - 20) {
  711.                                 $pdf.contents().off('scroll');
  712.                                 voteVisible();
  713.                             }
  714.                         })
  715.                     }
  716.                 }, 1000)
  717.             }
  718.  
  719.  
  720.             function voteVisible(){
  721.                 $('.send-vote').removeClass('disabled');
  722.                 grecaptchablock.show();
  723.                 $('.attention').hide();
  724.                 $('.btn.send-vote').attr('title', '');
  725.             }
  726.  
  727.  
  728.             $('.btn.disabled.send-vote').tooltip();
  729.  
  730.  
  731.             var grecaptchablock = $('.g-recaptcha');
  732.  
  733.             $('.vote-for-us').on('click', function(){
  734. //              $('#vfs').modal('show');
  735. //              $('#vfs').find('.userid').val($(this).data('id'));
  736. //              $('.send-vote').show();
  737. //              $('.message').hide();
  738. //              $('.message').html('');
  739.  
  740.  
  741.  
  742.                 $('#vfs').modal('show');
  743.                 $('#vfs').find('.userid').val($(this).data('id'));
  744.                 $('.attention').show();
  745.                 var timerTime = 0;
  746.  
  747.                 $('.btn.send-vote').attr('title', 'Работа просмотрена не до конца');
  748.  
  749.                 $('.info-block').html('<div style="margin-bottom: 10px; padding-left: 15px; padding-right: 15px;">Конкурсная работа <b>'+$(this).data('title')+'</b>, автор <b>'+$(this).data('fio')+'</b></div>');
  750.  
  751.                 //debugger;
  752.  
  753.                 grecaptchablock.hide();
  754.  
  755.                 if($(this).data('youtube') != ''){
  756.  
  757.                     $('.video-frame iframe').attr('src', '//www.youtube.com/embed/'+$(this).data('youtube')+'?autoplay=1');
  758.                     $('.video-frame').show();
  759.  
  760.                     $.ajax({
  761.                         method: 'GET',
  762.                         url: "https://www.googleapis.com/youtube/v3/videos?id="+$(this).data('youtube')+"&key=AIzaSyDTj0c5bDFaEKUqRGtvWXowwDJ9dJ8TFAk&part=contentDetails"
  763.  
  764.                     }).then(function (data){
  765.                         var r = $.makeArray(data.items);
  766.                         var time = r[0].contentDetails.duration;
  767.                         var matchtext = '';
  768.                         var h = '';
  769.                         var m = '';
  770.                         var s = '';
  771.                         var regexH = /(\d+)H/;
  772.                         var regexM = /(\d+)M/;
  773.                         var regexS = /(\d+)S/;
  774.  
  775.                         matchtext = time.match(regexH);
  776.                         if( typeof matchtext !== "undefined" && matchtext)  h = matchtext[1];   else h = 0;
  777.  
  778.                         matchtext = time.match(regexM);
  779.                         if( typeof matchtext !== "undefined" && matchtext) m = matchtext[1]; else m = 0;
  780.  
  781.                         matchtext = time.match(regexS);
  782.                         if( typeof matchtext !== "undefined" && matchtext) s = matchtext[1]; else s = 0;
  783.  
  784.                         timerTime = parseInt(s)+ parseInt(m)*60+ parseInt(h)*60*60;
  785.  
  786.  
  787.                         var now = new Date();
  788.  
  789.                         if(timerTime != 0){
  790.                             now = now.setMinutes(now.getMinutes() + parseInt((timerTime-timerTime*0.25)/60), now.getSeconds() + parseInt((timerTime)%60*0.25));
  791.                         }
  792.  
  793.                         //now = now.setMinutes(now.getMinutes(), now.getSeconds() + 10);
  794.  
  795.                         $('#CDT').countdown(now, function(event) {
  796.                             //$(this).html(event.strftime('%H:%M:%S'));
  797.                             $(this).html(event.strftime('%M:%S'));
  798.                         });
  799.                     });
  800.                 }
  801.  
  802.                 //debugger;
  803.                 if($(this).data('youtube') == '' && $(this).data('pdfsrc') != ''){
  804.                     var ee = $(this).data('pdfsrc');
  805.                     //debugger;
  806.                     setTimeout(function(){
  807.                         //debugger;
  808.                         $('#pdf_iframe').attr('src', $('#pdf_iframe').attr('src')+'?pdfsrc='+ee+'&width='+$('#vfs .modal-content').width())-30;
  809.                     }, 200, ee);
  810.  
  811.  
  812.                     $('#vfs .modal-dialog').css('width', '1000px');
  813.                     $('.pdf-frame').show();
  814.  
  815.                     endOfScroll();
  816.                 }
  817.  
  818.  
  819.  
  820.  
  821.                 if($(this).data('youtube') == '' && $(this).data('pdfsrc') == ''
  822.                     && $('#vfs #carousel-example-generic-1-'+$(this).data('id')).length > 0){
  823.  
  824.                     $('#vfs .modal-images').show();
  825.                     $('#vfs #carousel-example-generic-1-'+$(this).data('id')).show();
  826.                     var now = new Date();
  827.                     now = now.setMinutes(now.getMinutes()+1);
  828.  
  829.                     $('#CDT').countdown(now, function(event) {
  830.                         //$(this).html(event.strftime('%H:%M:%S'));
  831.                         $(this).html(event.strftime('%M:%S'));
  832.                     });
  833.                 }
  834.  
  835.  
  836.  
  837.                 $('.send-vote').show();
  838.                 $('.send-vote').addClass('disabled');
  839.                 $('.message').hide();
  840.                 $('.message').html('');
  841.  
  842.  
  843.  
  844.             });
  845.  
  846.  
  847.             $('#CDT').on('finish.countdown', function(){
  848.                 voteVisible();
  849.             });
  850.  
  851.  
  852.  
  853.             $('#vfs').on('hide.bs.modal', function(e){
  854.                 //$('#vfs').find('.userid').val('');
  855.                 //grecaptcha.reset();
  856.                 $('#vfs').find('.userid').val('');
  857.                 grecaptcha.reset();
  858.                 $('.video-frame iframe').attr('src','');
  859.                 $('.video-frame').hide();
  860.                 if($('#CDT').html() != '')
  861.                     $('#CDT').countdown('stop');
  862.                 $('#CDT').html('');
  863.                 $('.pdf-frame').hide();
  864.                 $('#vfs .slide').hide();
  865.                 $('#vfs .modal-images').hide();
  866.                 $('#pdf_iframe').attr('src', '/templates/bootstrap/build/js/pdfjs/pdfjs.php');
  867.                 $('#pdf_iframe').contents().off('scroll');
  868.                 $('#vfs .modal-dialog').css('width', 'auto');
  869.                 $('.info-block').html('');
  870.             });
  871.  
  872.             $('#vfs').on('shown.bs.modal', function(e){
  873. //              if($('.carousel').length > 0){
  874. //                  $('.carousel').carousel({'interval': 0});
  875.                     //debugger;
  876. //              }
  877.  
  878.             });
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.             $('.send-vote').on('click', function(){
  887.                 var resp = grecaptcha.getResponse();
  888.  
  889. //              $.ajax({
  890. //                  method: 'POST',
  891. //                  url: "/index.php?option=com_partisipants&task=kiv.check",
  892. //                  data: 'checkid='+resp
  893. //
  894. //              }).then(function (data){
  895. //                  var d = JSON.parse(data);
  896. //
  897. //                  if(d['checkresult'] == true){
  898.                         //Can we vote for partisipant?
  899.                         $.ajax({
  900.                             method: 'POST',
  901.                             url: "/index.php?option=com_partisipants&task=kiv.voting",
  902.                             data: 'id='+$('#vfs .userid').val()+'&checkid='+resp
  903.  
  904.                         }).then(function (data){
  905.                             var d2 = JSON.parse(data);
  906.                             grecaptcha.reset();
  907.                             if(d2['result'] == 0){
  908.                                 //Already voted
  909.                                 $('.message').html('<div class="alert alert-danger">Вы уже голосовали за данного кандидата!</div>');
  910.                             }
  911.                             if(d2['result'] == 1){
  912.                                 //Success
  913.                                 $('.message').html('<div class="alert alert-success">Спасибо! Ваш голос учтен!</div>');
  914.  
  915.                                 setTimeout(function(){location.reload();}, 1500);
  916.                             }
  917.  
  918.                             if(d2['result'] == 0 || d2['result'] == 1){
  919.                                 $('.message').show();
  920.                                 $('.send-vote').hide();
  921.  
  922.                             }
  923.  
  924.                         });
  925.  
  926.  
  927. //                  }
  928. //              });
  929.  
  930.  
  931.  
  932.             });
  933.  
  934.  
  935.         }
  936.  
  937.  
  938.  
  939.     });
  940.  
  941. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement