Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {
  2.  
  3.     if( jQuery('#slick-slider-home-especialidades').length > 0 ){
  4.         jQuery('#slick-slider-home-especialidades').slick({
  5.             dots: false,
  6.             infinite: true,
  7.             slidesToShow: 3,
  8.             slidesPerRow: 1,
  9.             slidesToScroll: 1,
  10.             arrows : true,
  11.             prevArrow : '<a class="slick-prev"><i class="fa fa-chevron-left"></i></a>',
  12.             nextArrow : '<a class="slick-next"><i class="fa fa-chevron-right"></i></a>',
  13.             responsive: [
  14.                 {
  15.                   breakpoint: 600,
  16.                   settings: {
  17.                     slidesToShow: 2,
  18.                     slidesToScroll: 2,
  19.                     infinite: true,
  20.                     dots: false
  21.                   }
  22.                 },
  23.                 {
  24.                   breakpoint: 480,
  25.                   settings: {
  26.                     slidesToShow: 1,
  27.                     slidesToScroll: 1,
  28.                     infinite: true,
  29.                     dots: false
  30.                   }
  31.                 }
  32.             ]
  33.         });
  34.     }
  35.  
  36.  
  37.     if( jQuery('.slide-marcas-especialidad-movil').length > 0 ){
  38.         jQuery('.slide-marcas-especialidad-movil').slick({
  39.             //slide : '.contenedor-marca',
  40.             dots: false,
  41.             infinite: true,
  42.             slidesToShow: 1,
  43.             slidesPerRow: 1,
  44.             slidesToScroll: 1,
  45.             arrows : true,
  46.             prevArrow : '<a class="slick-prev"><i class="fa fa-chevron-left"></i></a>',
  47.             nextArrow : '<a class="slick-next"><i class="fa fa-chevron-right"></i></a>'
  48.         });
  49.     }
  50.  
  51.     if( jQuery('.slider-especialidades-movil').length > 0 ){
  52.         jQuery('.slider-especialidades-movil').slick({
  53.             //slide : '.contenedor-marca',
  54.             dots: false,
  55.             infinite: true,
  56.             slidesToShow: 2,
  57.             slidesPerRow: 1,
  58.             slidesToScroll: 1,
  59.             arrows : true,
  60.             prevArrow : '<a class="especialidades-slick-prev"><i class="fa fa-chevron-left"></i></a>',
  61.             nextArrow : '<a class="especialidades-slick-next"><i class="fa fa-chevron-right"></i></a>'
  62.         });
  63.     }
  64.  
  65.     jQuery(document).scroll(function () {
  66.         var $nav = jQuery("nav.navbar");
  67.         $nav.toggleClass('scrolled', jQuery(this).scrollTop() > $nav.height());
  68.     });
  69.  
  70.  
  71.  
  72.     if( location.search ){
  73.         jQuery(".product-categories").find('li a').each(function(index, el) {
  74.             jQuery( el ).prop('href', jQuery( el ).prop('href') + location.search );
  75.         });
  76.  
  77.         jQuery("#main-menu").find('li.activa-filtros a').each(function(index, el) {
  78.             jQuery( el ).prop('href', jQuery( el ).prop('href') + location.search );
  79.         });
  80.  
  81.         jQuery("select.pwb-dropdown-widget").find('option').each(function(index, el) {
  82.             jQuery( el ).val( jQuery( el ).val() + location.search );
  83.         });
  84.     }
  85.  
  86.     jQuery('.woocommerce').on('click', "a.button.btn-quote-only", function(event) {
  87.         event.preventDefault();
  88.         jQuery('#modal-cotizacion').modal('show');
  89.         jQuery('#equipo-cotizacion').val( jQuery(this).data('product-name') );
  90.     });
  91.  
  92.     jQuery('.solo_numeros').keyup(function(e){
  93.         if (/\D/g.test(this.value)){this.value = this.value.replace(/\D/g, '');}
  94.     });
  95.  
  96.     jQuery.validator.methods.matches = function( value, element, params ) {
  97.         var re = new RegExp(params);
  98.         return this.optional( element ) || re.test( value );
  99.     }
  100.  
  101.  
  102.     jQuery('#form-contacto').validate({
  103.         rules: {
  104.             "firstname" : { required : true },
  105.             "lastname" : { required : true },
  106.             "email" : { required : true, email : true },
  107.             "companyname" : { required : true },
  108.             "homephone" : { required : true },
  109.             "pais" : { required : true },
  110.             "mobilephone" : { required : true },
  111.             "state" : { required : true },
  112.             "city" : { required : true },
  113.             "custentity8" : { required : true },
  114.             "selectProduct" : { required : true },
  115.             "custentity9" : { required : true },
  116.             "comments" : { required : true }
  117.         },
  118.         erroClass: "error",
  119.         submitHandler: function(form) {
  120.             var urlForm = $(form).attr('action');
  121.  
  122.             $.ajax({
  123.                 url: medrent_ajax.ajax_url,
  124.                 type: 'POST',
  125.                 data: new FormData( $(form)[0] ),
  126.                 processData: false,
  127.                 contentType: false,
  128.                 beforeSend: function(){
  129.                     $(form).find('.cargando').removeClass('d-none');
  130.                     $(form).find('button[type="submit"]').addClass('disabled');
  131.                 },
  132.                 error: function(){
  133.                     $(form).find('.cargando').addClass('d-none');
  134.                     $(form).find('.exitoso').addClass('d-none');
  135.                     $(form).find('button[type="submit"]').removeClass('disabled');
  136.                     $(form)[0].reset();
  137.                 },
  138.                 success: function(response){
  139.                     $(form).find('.cargando').addClass('d-none');
  140.                     $(form).find('.exitoso').removeClass('d-none');
  141.                     $(form).find('button[type="submit"]').removeClass('disabled');
  142.                     $(form)[0].reset();
  143.                 }
  144.             });
  145.         }
  146.     });
  147.  
  148.     jQuery('#newsletter-form, #newsletter-form-eventos').validate({
  149.         rules: {
  150.             'correo-electronico' : { required : true, email : true }
  151.         },
  152.         erroClass: "error",
  153.         submitHandler: function(form) {
  154.             var formulario = jQuery(form);
  155.             var data = formulario.serialize();
  156.             jQuery.ajax({
  157.                 type : "POST",
  158.                 dataType : "json",
  159.                 url: medrent_ajax.ajax_url,
  160.                 data : { action: "newsletter_submit", data },
  161.                 success: function(json) {
  162.                     if( json.result ){
  163.                         jQuery('#newsletter-form').html('<p>Muchas gracias por enviar tu información.</p>');
  164.                     }
  165.                 }
  166.             });
  167.         }
  168.     });
  169.  
  170.     jQuery('#newsletter-form-promociones').validate({
  171.         rules: {
  172.             'correo-electronico' : { required : true, email : true }
  173.         },
  174.         erroClass: "error",
  175.         submitHandler: function(form) {
  176.             var formulario = jQuery(form);
  177.             var data = formulario.serialize();
  178.             jQuery.ajax({
  179.                 type : "POST",
  180.                 dataType : "json",
  181.                 url: medrent_ajax.ajax_url,
  182.                 data : { action: "newsletter_submit", data },
  183.                 success: function(json) {
  184.                     if( json.result ){
  185.                         jQuery('#newsletter-form-promociones').html('<p>Muchas gracias por enviar tu información.</p>');
  186.                     }
  187.                 }
  188.             });
  189.         }
  190.     });
  191.  
  192.     jQuery( "#form-cotizar" ).validate( {
  193.         rules: {
  194.             'nombre-completo' : { required : true },
  195.             'correo-electronico' : { required : true, email : true },
  196.             'telefono' : { required : true, digits : true, matches: "[0-9]+", minlength:10, maxlength:10 }
  197.         },
  198.         erroClass: "error",
  199.         success: function ( label, element ) {
  200.  
  201.         },
  202.         submitHandler: function(form) {
  203.             var formulario = jQuery(form);
  204.             var data = formulario.serialize();
  205.             jQuery.ajax({
  206.                 type : "POST",
  207.                 dataType : "json",
  208.                 url: medrent_ajax.ajax_url,
  209.                 data : { action: "cotizacion_submit", data },
  210.                 beforeSend: function(){
  211.                     $(form).find('button[type="submit"]').addClass('disabled').hide();
  212.                 },
  213.                 success: function(json) {
  214.                     var response = $.parseJSON( json );
  215.                     console.log(response);
  216.                     if( response.result ){
  217.                         jQuery('#modal-cotizacion').modal('hide');
  218.                     }
  219.  
  220.                     $(form).find('button[type="submit"]').removeClass('disabled').show();
  221.                 }
  222.             });
  223.         }
  224.     });
  225.  
  226.     $('#modal-cotizacion').on('show.bs.modal', function (e) {
  227.       $('#form-cotizar').find('button[type="submit"]').removeClass('disabled').show();
  228.     })
  229.  
  230.     jQuery.extend(jQuery.validator.messages, {
  231.         required: "Es requerido",
  232.         email: "Debe ser un email válido",
  233.         digits: "Inserta solo dígitos",
  234.         lettersonly: "Inserta solo caracteres",
  235.         minlength: "Ingresa mínimo 10 caracteres",
  236.         maxlength: "Ingresa máximo 10 caracteres"
  237.     });
  238.  
  239.  
  240.     // get the country data from the plugin
  241.     var countryData = window.intlTelInputGlobals.getCountryData(),
  242.       input = document.querySelector("#telefono"),
  243.       addressDropdown = document.querySelector("#pais");
  244.  
  245.     // init plugin
  246.     var iti = window.intlTelInput(input, {
  247.         //separateDialCode: true,
  248.         initialCountry: "auto",
  249.         geoIpLookup: function(callback) {
  250.             $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
  251.                 var countryCode = (resp && resp.country) ? resp.country : "";
  252.                 callback(countryCode);
  253.             });
  254.         },
  255.         utilsScript: "https://med-rent.com/wp-content/themes/medrent-beta/node_modules/intl-tel-input/build/js/utils.js?1549804213570" // just for formatting/placeholders etc
  256.     });
  257.  
  258.     // populate the country dropdown
  259.     for (var i = 0; i < countryData.length; i++) {
  260.       var country = countryData[i];
  261.       var optionNode = document.createElement("option");
  262.       optionNode.value = country.iso2;
  263.       var textNode = document.createTextNode(country.name);
  264.       optionNode.appendChild(textNode);
  265.       addressDropdown.appendChild(optionNode);
  266.     }
  267.     // set it's initial value
  268.     addressDropdown.value = iti.getSelectedCountryData().iso2;
  269.  
  270.     // listen to the telephone input for changes
  271.     input.addEventListener('countrychange', function(e) {
  272.       addressDropdown.value = iti.getSelectedCountryData().iso2;
  273.     });
  274.  
  275.     // listen to the address dropdown for changes
  276.     addressDropdown.addEventListener('change', function() {
  277.       iti.setCountry(this.value);
  278.     });
  279.  
  280.     jQuery('#input-search').on('keyup', function(event) {
  281.         event.preventDefault();
  282.         var term = jQuery(this).val();
  283.         var marca = jQuery(this).data('marca');
  284.         if( term == "" ){
  285.             jQuery('div.productos').show();
  286.             jQuery('div.resultados').html("");
  287.         }else{
  288.             if( term.length >= 3 ){
  289.                 jQuery.ajax({
  290.                     type : "POST",
  291.                     dataType : "json",
  292.                     url: medrent_ajax.ajax_url,
  293.                     data : { action: "buscar_producto_por_marca", "term" : term, "marca" : marca  },
  294.                     success: function(json) {
  295.                         if( json.result ){
  296.                             jQuery('div.productos').hide();
  297.                             jQuery('div.resultados').html( json.html );
  298.                         }
  299.                     }
  300.                 });
  301.             }
  302.         }
  303.     });
  304.  
  305.     if( jQuery('select#marca').length > 0 ){
  306.         jQuery.ajax({
  307.             type : "POST",
  308.             dataType : "json",
  309.             url: medrent_ajax.ajax_url,
  310.             data : { action: "combo_marcas" },
  311.             success: function(json) {
  312.                 if( json.result ){
  313.                     jQuery('select#marca option').each(function(index, el) {
  314.                         if( jQuery( el ).val() != "" ){
  315.                             jQuery(el).remove();
  316.                         }
  317.                     });
  318.                     jQuery('select#marca').append( json.brands );
  319.                 }
  320.             }
  321.         });
  322.  
  323.         jQuery('select#marca').on('change', function(event) {
  324.             event.preventDefault();
  325.             var slug = jQuery(this).val();
  326.             jQuery.ajax({
  327.                 type : "POST",
  328.                 dataType : "json",
  329.                 url: medrent_ajax.ajax_url,
  330.                 data : { action: "combo_productos", "slug" : slug },
  331.                 success: function(json) {
  332.                     if( json.result ){
  333.                         jQuery('select#modelo option').each(function(index, el) {
  334.                             if( jQuery( el ).val() != "" ){
  335.                                 jQuery(el).remove();
  336.                             }
  337.                         });
  338.                         jQuery('select#modelo').append( json.products );
  339.                     }
  340.                 }
  341.             });
  342.         });
  343.     }
  344.  
  345.     jQuery('#input-search-especialidad').on('keyup', function(event) {
  346.         event.preventDefault();
  347.         var term = jQuery(this).val();
  348.         var especialidad = jQuery(this).data('especialidad');
  349.         if( term == "" ){
  350.             jQuery('div.productos').show();
  351.             jQuery('div.resultados').html("");
  352.         }else{
  353.             if( term.length >= 3 ){
  354.                 jQuery.ajax({
  355.                     type : "POST",
  356.                     dataType : "json",
  357.                     url: medrent_ajax.ajax_url,
  358.                     data : { action: "buscar_producto_por_especialidad", "term" : term, "especialidad" : especialidad  },
  359.                     success: function(json) {
  360.                         if( json.result ){
  361.                             jQuery('div.productos').hide();
  362.                             jQuery('div.resultados').html( json.html );
  363.                         }
  364.                     }
  365.                 });
  366.             }
  367.         }
  368.     });
  369.  
  370.     jQuery('.checkbox-filter').on('click', 'input[type="checkbox"]', function(event) {
  371.  
  372.         var estudios = [];
  373.         jQuery('.checkbox-filter input:checked').each(function(index, el) {
  374.             estudios.push( jQuery( el ).val() );
  375.         });
  376.  
  377.         if( estudios.length > 0 ){
  378.             jQuery('.woocommerce-product').each(function(index, el) {
  379.                 jQuery( el ).hide();
  380.                 for ( var i = 0; i < estudios.length; i++ ){
  381.                     if ( jQuery( el ).hasClass( estudios[i] ) ) {
  382.                         jQuery( el ).show();
  383.                         break;
  384.                     }
  385.                 }
  386.             });
  387.         }else{
  388.             jQuery('.woocommerce-product').show();
  389.         }
  390.  
  391.  
  392.  
  393.  
  394.     });
  395.  
  396.     if( jQuery('#calendario-eventos').length > 0 ){
  397.  
  398.         function myDateFunction(id, fromModal) {
  399.             var date = $("#" + id).data("date");
  400.             jQuery.ajax({
  401.                 type : "POST",
  402.                 dataType : "json",
  403.                 url: medrent_ajax.ajax_url,
  404.                 data : { action: "data_eventos_fecha", date: date },
  405.                 success: function(json) {
  406.                     if( json.result ){
  407.                         jQuery('.resultados').html( json.html );
  408.                     }
  409.                 }
  410.             });
  411.         }
  412.  
  413.         jQuery.ajax({
  414.             type : "POST",
  415.             dataType : "json",
  416.             url: medrent_ajax.ajax_url,
  417.             data : { action: "data_eventos" },
  418.             success: function(json) {
  419.                 if( json.result ){
  420.  
  421.                     var eventData = json.eventos;
  422.  
  423.                     jQuery("#calendario-eventos").zabuto_calendar({
  424.                         language: "es",
  425.                         nav_icon: {
  426.                           prev: '<i class="fa fa-chevron-circle-left"></i>',
  427.                           next: '<i class="fa fa-chevron-circle-right"></i>'
  428.                         },
  429.                         cell_border: true,
  430.                         today: true,
  431.                         data: eventData,
  432.                         action: function () {
  433.                             console.log( this.id );
  434.                             return myDateFunction(this.id, false);
  435.                         },
  436.                     });
  437.                 }
  438.             }
  439.         });
  440.  
  441.  
  442.     }
  443.  
  444.     $('#form-financiamiento').validate({
  445.         rules: {
  446.             nombre: {
  447.                 required: true
  448.             },
  449.             apellidos: {
  450.                 required: true
  451.             },
  452.             tel: {
  453.                 digits: true,
  454.                 minlength: 8
  455.             },
  456.             ciudad: {
  457.                 required: true
  458.             },
  459.             cp: {
  460.                 digits: true,
  461.                 maxlength: 5,
  462.                 minlength: 5
  463.             }
  464.         },
  465.         messages: {
  466.             aviso: {
  467.                 required: 'Acepta los términos'
  468.             },
  469.             cp: {
  470.                 maxlength: 'Ingresa un código postal válido',
  471.                 minlength: 'Ingresa un código postal válido'
  472.             }
  473.         },
  474.         success: 'valid',
  475.         submitHandler: function(form){
  476.             var valores = $(form).serialize();
  477.  
  478.             $.ajax({
  479.                 url: medrent_ajax.ajax_url,
  480.                 type: 'POST',
  481.                 data: new FormData( jQuery(form)[0] ),
  482.                 processData: false,
  483.                 contentType: false,
  484.                 beforeSend: function(){
  485.                     $(form).find('.cargando').removeClass('hidden-xs-up');
  486.                     $(form).find('.exitoso').addClass('hidden-xs-up');
  487.                     $(form).find('button[type="submit"]').addClass('disabled');
  488.                 },
  489.                 error: function(){
  490.  
  491.                 },
  492.                 success: function(response){
  493.                     $(form).find('.cargando').addClass('hidden-xs-up');
  494.                     $(form).find('.exitoso').removeClass('hidden-xs-up');
  495.                     $(form).find('button[type="submit"]').removeClass('disabled');
  496.                     $(form)[0].reset();
  497.                 }
  498.             });
  499.         }
  500.     });
  501.  
  502.     $('#form-servicio').validate({
  503.         rules: {
  504.             nombre: {
  505.                 required : true
  506.             },
  507.             apellidos: {
  508.                 required : true
  509.             },
  510.             tel: {
  511.                 digits: true,
  512.                 minlength: 8
  513.             },
  514.             ciudad: {
  515.                 required : true
  516.             },
  517.             cp: {
  518.                 digits: true,
  519.                 maxlength: 5,
  520.                 minlength: 5
  521.             }
  522.         },
  523.         messages: {
  524.             aviso: {
  525.                 required: 'Acepta los términos'
  526.             },
  527.             cp: {
  528.                 maxlength: 'Ingresa un código postal válido',
  529.                 minlength: 'Ingresa un código postal válido'
  530.             }
  531.         },
  532.         success: 'valid',
  533.         submitHandler: function(form){
  534.             var valores = $(form).serialize();
  535.  
  536.             $.ajax({
  537.                 url: medrent_ajax.ajax_url,
  538.                 type: 'POST',
  539.                 data: new FormData( jQuery(form)[0] ),
  540.                 processData: false,
  541.                 contentType: false,
  542.                 beforeSend: function(){
  543.                     $(form).find('.cargando').removeClass('d-none');
  544.                     $(form).find('button[type="submit"]').addClass('disabled');
  545.                 },
  546.                 error: function(){
  547.  
  548.                 },
  549.                 success: function(response){
  550.                     $(form).find('.cargando').addClass('d-none');
  551.                     $(form).find('.exitoso').removeClass('d-none');
  552.                     $(form).find('button[type="submit"]').removeClass('disabled');
  553.                     $(form)[0].reset();
  554.                 }
  555.             });
  556.         }
  557.     });
  558.  
  559.     jQuery('#form-contacto').on('change', '#tipo_mensaje', function(event) {
  560.         event.preventDefault();
  561.         var tipo = jQuery(this).val();
  562.         console.log( tipo );
  563.  
  564.         jQuery('.secciones-flotantes').addClass('d-none');
  565.  
  566.         if( tipo == "soporte-tecnico" ){
  567.             jQuery('#contenedor-form-soporte').removeClass('d-none');
  568.         }else if( tipo == "financiamiento" ){
  569.             jQuery('#contenedor-form-financiamiento').removeClass('d-none');
  570.         }else{
  571.             jQuery('.secciones-flotantes').addClass('d-none');
  572.         }
  573.  
  574.     });
  575.  
  576. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement