1(function ($) { 2 3 var el_form = $('#form-new-post'), 4 el_form_submit = $('.submit', el_form); 5 6 // Fires when the form is submitted. 7 el_form.on('submit', function (e) { 8 e.preventDefault(); 9 10 el_form_submit.attr('disabled', 'disabled'); 11 //var donotsell_email= jQuery('input[name="donotsell_email"]').val(); 12 //console.log(isEmail(donotsell_email)); 13 new_post(); 14 }); 15 /* function isEmail(email) { 16 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; 17 return regex.test(email); 18 } */ 19 // Ajax request. 20 function new_post() { 21 $.ajax({ 22 url: localized_donot_sell_form.admin_donot_sell_ajax_url, 23 type: 'POST', 24 dataType: 'json', 25 data: { 26 action: 'donot_sell_save_post', // Set action without prefix 'wp_ajax_'. 27 form_data: el_form.serialize() 28 }, 29 cache: false 30 }).done(function (r) { 31 // Show a single, clearly styled status message. r.error is set both 32 // for real errors and for the "verification required" response 33 // (donot_sell_save_post()); anything else with a donotsellrequests 34 // payload is a success. 35 if (r && r.error !== undefined && r.error !== '') { 36 showMessage(r.error, false); 37 } else if (r && r.donotsellrequests) { 38 showMessage('Request has been submitted successfully!!', true); 39 } else { 40 showMessage('Something went wrong. Please try again.', false); 41 } 42 }).fail(function () { 43 showMessage('Something went wrong. Please try again.', false); 44 }).always(function () { 45 el_form_submit.removeAttr('disabled'); 46 }); 47 } 48 49 // Render a success/error message in the status area and make sure it is 50 // visible (the box is hidden again after a delay, and re-shown on the next 51 // submit). 52 function showMessage(text, isSuccess) { 53 var $msg = jQuery('#donotsellmsg'); 54 55 $msg.stop(true, true) 56 .toggleClass('donotsell-msg', isSuccess) 57 .toggleClass('donotsell-error-msg', !isSuccess) 58 .text(text) 59 .show(); 60 61 if ($msg.length && $msg[0].scrollIntoView) { 62 $msg[0].scrollIntoView({ behavior: 'smooth', block: 'center' }); 63 } 64 65 $msg.delay(10000).fadeOut(); 66 } 67 68 // Used to trigger/simulate post submission without user action. 69 function trigger_new_post() { 70 el_form.trigger('submit'); 71 } 72 73 // Sets interval so the post the can be updated automatically provided that it was already created. 74 /* setInterval(function () { 75 if (el_form_submit.attr('data-is-updated') === 'false') { 76 return false; 77 } 78 79 trigger_new_post(); 80 }, 5000); // Set to 5 seconds. */ 81 82})(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.