1(function ($) { 2 'use strict'; 3 4 var overlay, modal; 5 6 function loadProduct(productId, callback) { 7 $.post(AvisameData.ajax_url, { 8 action: 'avisame_get_product', 9 nonce: AvisameData.nonce, 10 product_id: productId 11 }, function (res) { 12 callback(res.success ? res.data : { title: '', image: '' }); 13 }).fail(function () { 14 callback({ title: '', image: '' }); 15 }); 16 } 17 18 function openModal(productId) { 19 // Reset estado 20 $('#avisame-product-id').val(productId); 21 $('#avisame-email').val(''); 22 $('#avisame-privacy').prop('checked', false); 23 $('#avisame-form input').prop('disabled', false); 24 $('#avisame-submit').prop('disabled', false).text('AvÃsame'); 25 $('#avisame-message').text('').removeClass('success error'); 26 $('#avisame-img').attr('src', '').hide(); 27 $('#avisame-title').text(''); 28 29 loadProduct(productId, function (data) { 30 $('#avisame-title').text(data.title); 31 if (data.image) { 32 $('#avisame-img').attr('src', data.image).show(); 33 } 34 }); 35 36 overlay.attr('aria-hidden', 'false').addClass('is-open'); 37 $('body').addClass('avisame-no-scroll'); 38 setTimeout(function () { $('#avisame-email').focus(); }, 100); 39 } 40 41 function closeModal() { 42 overlay.attr('aria-hidden', 'true').removeClass('is-open'); 43 $('body').removeClass('avisame-no-scroll'); 44 } 45 46 function submitForm(e) { 47 e.preventDefault(); 48 49 var $msg = $('#avisame-message'); 50 var $btn = $('#avisame-submit'); 51 var email = $('#avisame-email').val().trim(); 52 var privacy = $('#avisame-privacy').is(':checked'); 53 var pid = $('#avisame-product-id').val(); 54 55 $msg.text('').removeClass('success error'); 56 57 if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { 58 $msg.addClass('error').text('Introduce un email válido.'); 59 return; 60 } 61 if (!privacy) { 62 $msg.addClass('error').text('Debes aceptar la polÃtica de privacidad.'); 63 return; 64 } 65 66 $btn.prop('disabled', true).text('Enviandoâ¦'); 67 68 $.post(AvisameData.ajax_url, { 69 action: 'avisame_save', 70 nonce: AvisameData.nonce, 71 product_id: pid, 72 email: email, 73 privacy: '1' 74 }, function (res) { 75 if (res.success) { 76 $msg.addClass('success').text(res.data.message); 77 $('#avisame-form input').prop('disabled', true); 78 $btn.text('¡Listo!'); 79 } else { 80 var msg = (res.data && res.data.message) ? res.data.message : 'Error al enviar.'; 81 $msg.addClass('error').text(msg); 82 $btn.prop('disabled', false).text('AvÃsame'); 83 } 84 }).fail(function () { 85 $msg.addClass('error').text('Error de conexión. Inténtalo de nuevo.'); 86 $btn.prop('disabled', false).text('AvÃsame'); 87 }); 88 } 89 90 $(function () { 91 overlay = $('#avisame-overlay'); 92 modal = overlay.find('.avisame-modal'); 93 94 $(document).on('click', '.avisame-btn', function () { 95 openModal($(this).data('product-id')); 96 }); 97 98 overlay.on('click', '.avisame-close', closeModal); 99 overlay.on('click', function (e) { 100 if ($(e.target).is(overlay)) closeModal(); 101 }); 102 $(document).on('keydown', function (e) { 103 if (e.key === 'Escape' && overlay.hasClass('is-open')) closeModal(); 104 }); 105 106 $('#avisame-form').on('submit', submitForm); 107 }); 108 109}(jQuery));
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.