1/** 2 * Coupon Generator Module 3 * Handles the generation of discount coupon codes via AJAX 4 */ 5 6jQuery(document).ready(function($) { 7 const endpoints = { 8 generateCoupon: '/wp-admin/admin-ajax.php' 9 }; 10 11 const ajaxData = window.couponGeneratorAjax || { 12 ajaxurl: '/wp-admin/admin-ajax.php', 13 nonce: '' 14 }; 15 16 /** 17 * generateCoupon 18 * @param {string} type 19 * @param {string} amount 20 * @param {jQuery} buttonElement 21 */ 22 function generateCoupon(type, amount, buttonElement, note = '') { 23 buttonElement.css('opacity', '.4'); 24 25 jQuery.ajax({ 26 type: 'POST', 27 url: endpoints.generateCoupon, 28 data: { 29 action: 'generate_discount_coupon', 30 type: type, 31 amount: amount, 32 nonce: ajaxData.nonce, 33 note: note 34 }, 35 success: response => { 36 $(".coupon-code-display").text(response.data.discount_code); 37 }, 38 error: (xhr, status, error) => { 39 let message = error; 40 if (xhr.responseJSON && xhr.responseJSON.data && xhr.responseJSON.data.message) { 41 message = xhr.responseJSON.data.message; 42 } 43 44 $(".coupon-code-display").text('Unable to fetch code: ' + message); 45 }, 46 complete: () => { 47 buttonElement.css('opacity', '1'); 48 } 49 }); 50 } 51 52 $(".generate-cs-coupon").click(function(e) { 53 e.preventDefault(); 54 generateCoupon('cs', '10', $(this)); 55 }); 56 57 $(".generate-cs-coupon-12").click(function(e) { 58 e.preventDefault(); 59 generateCoupon('cs', '12', $(this)); 60 }); 61 62 $(".generate-cs-coupon-15").click(function(e) { 63 e.preventDefault(); 64 generateCoupon('cs', '15', $(this)); 65 }); 66 67 $(".generate-lmf-coupon").click(function(e) { 68 e.preventDefault(); 69 generateCoupon('lmf', '15', $(this)); 70 }); 71 72 $(".generate-gc-coupon-5").click(function(e) { 73 e.preventDefault(); 74 const note = $("#gs-coupon-note").val(); 75 76 generateCoupon('gc', '5', $(this), note); 77 }); 78});
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.