1"use strict"; 2var get_bot_type = cwginstock.get_bot_type; 3var recaptcha_enabled = cwginstock.enable_recaptcha; 4var is_v3_recaptcha = cwginstock.is_v3_recaptcha; 5var recaptcha_site_key = cwginstock.recaptcha_site_key; 6// turnstile 7var turnstile_enabled = cwginstock.enable_turnstile; 8var turnstile_site_key = cwginstock.turnstile_site_key; 9 10var gtoken = ''; 11 12if (typeof wc_bulk_variations_params !== 'undefined') { 13 document.addEventListener( 14 'click', 15 function (event) { 16 if (event.target.matches('.cwg_popup_submit')) { 17 console.log(event.target.dataset.product_id); 18 console.log('Captured click before stopPropagation!'); 19 var e = event.target; 20 jQuery.blockUI({ message: null }); 21 var product_id = e.dataset.product_id; 22 var variation_id = e.dataset.variation_id; 23 var quantity = e.dataset.quantity 24 var security = e.dataset.security 25 26 var data = { 27 action: 'cwg_trigger_popup_ajax', 28 product_id: product_id, 29 variation_id: variation_id, 30 quantity: quantity, 31 security: security 32 }; 33 if (get_bot_type == 'recaptcha' && recaptcha_enabled == '1' && is_v3_recaptcha == 'yes') { 34 popup_notifier.popup_generate_v3_response(this); 35 } else { 36 popup_notifier.perform_ajax(data); 37 } 38 return false; 39 } 40 }, 41 true // This enables the capturing phase 42 ); 43} 44 45var popup_notifier = { 46 init: function () { 47 jQuery(document).on( 48 'click', 49 '.cwg_popup_submit', 50 function () { 51 52 jQuery.blockUI({ message: null }); 53 var current = jQuery(this); 54 var product_id = current.attr('data-product_id'); 55 var variation_id = current.attr('data-variation_id'); 56 var quantity = current.attr('data-quantity'); 57 var security = current.attr('data-security'); 58 59 var data = { 60 action: 'cwg_trigger_popup_ajax', 61 product_id: product_id, 62 variation_id: variation_id, 63 quantity: quantity, 64 security: security 65 }; 66 if (get_bot_type == 'recaptcha' && recaptcha_enabled == '1' && is_v3_recaptcha == 'yes') { 67 popup_notifier.popup_generate_v3_response(this); 68 } else { 69 popup_notifier.perform_ajax(data); 70 } 71 return false; 72 } 73 ); 74 }, 75 popup_generate_v3_response: function (currentel) { 76 if (get_bot_type == 'recaptcha' && recaptcha_enabled == '1' && is_v3_recaptcha == 'yes') { 77 grecaptcha.ready( 78 function () { 79 grecaptcha.execute(recaptcha_site_key, { action: 'popup_form' }).then( 80 function (token) { 81 console.log(token); 82 83 var current = jQuery(currentel); 84 var product_id = current.attr('data-product_id'); 85 var variation_id = current.attr('data-variation_id'); 86 var quantity = current.attr('data-quantity'); 87 88 var data = { 89 action: 'cwg_trigger_popup_ajax', 90 product_id: product_id, 91 variation_id: variation_id, 92 quantity: quantity, 93 security: token 94 }; 95 popup_notifier.perform_ajax(data); 96 gtoken = token; 97 } 98 ); 99 } 100 ); 101 } 102 }, 103 /** 104 * Render the returned form inside a native modal (no SweetAlert). 105 * Used when a custom popup design is selected in settings. 106 * 107 * @since 7.4.0 108 */ 109 render_native_modal: function (html, design) { 110 // Remove any modal left over from a previous open. 111 jQuery('.cwg-modal-overlay').remove(); 112 113 var skin = 'cwg-modal-' + String(design).replace('modal_', ''); 114 var overlay = document.createElement('div'); 115 overlay.className = 'cwg-modal-overlay ' + skin; 116 overlay.setAttribute('role', 'dialog'); 117 overlay.setAttribute('aria-modal', 'true'); 118 119 var box = document.createElement('div'); 120 box.className = 'cwg-modal-box'; 121 122 var close = document.createElement('button'); 123 close.type = 'button'; 124 close.className = 'cwg-modal-close'; 125 close.innerHTML = '×'; 126 close.setAttribute('aria-label', (typeof cwginstock !== 'undefined' && cwginstock.popup_close_label) ? cwginstock.popup_close_label : 'Close'); 127 128 var content = document.createElement('div'); 129 content.className = 'cwg-modal-content'; 130 content.innerHTML = html; 131 132 box.appendChild(close); 133 box.appendChild(content); 134 overlay.appendChild(box); 135 document.body.appendChild(overlay); 136 137 function closeModal() { 138 overlay.classList.remove('cwg-modal-visible'); 139 jQuery(document).trigger('cwginstock_popup_close_callback'); 140 setTimeout(function () { jQuery(overlay).remove(); }, 250); 141 document.removeEventListener('keydown', onKey); 142 } 143 function onKey(e) { if (e.key === 'Escape') { closeModal(); } } 144 145 close.addEventListener('click', closeModal); 146 overlay.addEventListener('click', function (e) { if (e.target === overlay) { closeModal(); } }); 147 document.addEventListener('keydown', onKey); 148 149 // Render bot protection widgets inside the modal, same as the SweetAlert flow. 150 if ('recaptcha' == get_bot_type) { 151 if ('1' == recaptcha_enabled) { 152 jQuery(overlay).find('.g-recaptcha').before('<div id="cwg-google-recaptcha"></div>'); 153 jQuery(overlay).find('.g-recaptcha').remove(); 154 } 155 } else if ('1' == turnstile_enabled && typeof turnstile !== 'undefined') { 156 try { 157 turnstile.render( 158 jQuery(overlay).find('.cf-turnstile')[0], 159 { 160 sitekey: turnstile_site_key, 161 theme: 'light', 162 callback: function (token) { cwginstock_turnstile_callback(token); } 163 } 164 ); 165 } catch (e) { } 166 } 167 168 // Trigger the transition on the next frame so it animates in. 169 requestAnimationFrame(function () { overlay.classList.add('cwg-modal-visible'); }); 170 jQuery(document).trigger('cwginstock_popup_open_callback'); 171 }, 172 173 perform_ajax: function (data) { 174 jQuery.ajax( 175 { 176 type: "post", 177 url: cwginstock.default_ajax_url, 178 data: data, 179 success: function (msg) { 180 jQuery.unblockUI(); 181 var popup_design = (typeof cwginstock !== 'undefined' && cwginstock.popup_design) ? cwginstock.popup_design : 'sweetalert'; 182 if (popup_design !== 'sweetalert') { 183 popup_notifier.render_native_modal(msg, popup_design); 184 return; 185 } 186 Swal.fire( 187 { 188 html: msg, 189 showCloseButton: true,
190 showConfirmButton: false, 191 willOpen: function () { 192 if ('recaptcha' == get_bot_type) { 193 if ('1' == recaptcha_enabled) { 194 jQuery('.g-recaptcha').before('<div id="cwg-google-recaptcha"></div>'); 195 jQuery('.g-recaptcha').remove(); 196 } 197 } else { 198 if ('1' == turnstile_enabled) { 199 turnstile.render( 200 '.cf-turnstile', 201 { 202 sitekey: turnstile_site_key, 203 theme: 'light', 204 callback: function (token) { 205 cwginstock_turnstile_callback(token); 206 }, 207 } 208 ); 209 } 210 } 211 }, 212 didOpen: function () { 213 jQuery(document).trigger('cwginstock_popup_open_callback'); 214 }, 215 willClose: function () { 216 jQuery(document).trigger('cwginstock_popup_close_callback'); 217 }, 218 } 219 ); 220 221 }, 222 error: function (request, status, error) { 223 jQuery.unblockUI(); 224 } 225 } 226 ); 227 }, 228}; 229popup_notifier.init(); 230 231 232jQuery(document).on( 233 'cwginstock_popup_open_callback', 234 function () { 235 instock_notifier.onloadcallback(); 236 instock_notifier.initialize_phone(); 237 } 238); 239 240jQuery(document).on( 241 'cwginstock_popup_close_callback', 242 function () { 243 instock_notifier.resetcallback(); 244 } 245);
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.