1document.addEventListener("DOMContentLoaded", function(event) { 2 var checkBalanceForm = jQuery('#pwgc-balance-form'); 3 if ( checkBalanceForm.length ) { 4 checkBalanceForm.on('submit', function(e) { 5 pwgc_check_balance(); 6 7 e.preventDefault(); 8 return false; 9 }); 10 pwgc_check_balance(); 11 } 12 13 jQuery('#pwgc-balance-reload').off('click.pwgc').on('click.pwgc', function(e) { 14 var cardNumber = jQuery(this).attr('data-card-number'); 15 var productUrl = jQuery(this).attr('data-url'); 16 if (cardNumber) { 17 var separator = '?'; 18 if (productUrl.includes('?')) { 19 separator = '&'; 20 } 21 22 location.href = productUrl + separator + pwgc.reload_key + '=' + cardNumber; 23 } 24 e.preventDefault(); 25 return false; 26 }); 27 28 jQuery('#pwgc-manual-debit').off('click.pwgc').on('click.pwgc', function(e) { 29 jQuery(this).prop('disabled', true); 30 var errorMessage = jQuery('#pwgc-balance-error'); 31 errorMessage.text(''); 32 33 var cardNumber = jQuery(this).attr('data-card-number'); 34 if (cardNumber) { 35 var amount = prompt( pwgc.i18n.debit_amount_prompt ); 36 if (amount) { 37 var note = prompt( pwgc.i18n.debit_note_prompt ); 38 if (note !== null) { 39 var balance = jQuery('#pwgc-balance-amount'); 40 var balanceMessage = jQuery('#pwgc-balance-message'); 41 42 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-debit', 'card_number': cardNumber, 'amount': amount, 'note': note, 'security': pwgc.nonces.debit_balance}, function(result) { 43 balance.html(result.balance); 44 balanceMessage.html(result.message); 45 }).fail(function(xhr, textStatus, errorThrown) { 46 if (errorThrown) { 47 errorMessage.text(errorThrown); 48 } else { 49 errorMessage.text('Unknown ajax error'); 50 } 51 }); 52 } 53 } 54 } 55 jQuery(this).prop('disabled', false); 56 e.preventDefault(); 57 return false; 58 }); 59 60 jQuery(document.body).on('updated_wc_div', pwgc_bind_redeem_form); 61 pwgc_bind_redeem_form(); 62 63 jQuery(document.body).on('updated_wc_div', pwgc_bind_remove_link); 64 jQuery(document.body).on('updated_checkout', pwgc_bind_remove_link); 65 pwgc_bind_remove_link(); 66 67 jQuery('#pwgc-message').on('input propertychange', function() { 68 pwgc_message_characters_remaining(); 69 }); 70 pwgc_message_characters_remaining(); 71 72 jQuery('form.variations_form').on('show_variation', function() { 73 jQuery('#pwgc-purchase-container').show(); 74 pwgc_toggle_custom_amount_visibility(); 75 }); 76 77 jQuery('form.variations_form').on('hide_variation', function() { 78 jQuery('#pwgc-purchase-container').hide(); 79 pwgc_toggle_custom_amount_visibility(); 80 }); 81 82 var attributeSelector = jQuery(document.getElementById(pwgc.denomination_attribute_slug)); 83 if (attributeSelector.length == 0) { 84 attributeSelector = jQuery(document.getElementsByName('attribute_' + pwgc.denomination_attribute_slug)); 85 } 86 87 if (attributeSelector.val()) { 88 jQuery('#pwgc-purchase-container').show(); 89 } else { 90 jQuery('#pwgc-purchase-container').hide(); 91 } 92 93 pwgc_toggle_custom_amount_visibility(); 94 95 jQuery('#pwgc-custom-amount').on('blur', function() { 96 jQuery('#pwgc-custom-amount-error').text(''); 97 98 var amount = jQuery(this).val(); 99 100 amount = amount.replace(pwgc.thousand_separator, ''); 101 amount = amount.replace(pwgc.decimal_separator, '.'); 102 amount = amount.replace(/[^0-9.]/g,''); 103 if (amount) { 104 var floatAmount = parseFloat(amount); 105 var container = jQuery('#pwgc-purchase-container'); 106 var minAmount = parseFloat(container.attr('data-min-amount')); 107 var maxAmount = parseFloat(container.attr('data-max-amount')); 108 109 if (floatAmount < minAmount) { 110 jQuery('#pwgc-custom-amount-error').html(pwgc.i18n.min_amount_error + minAmount.toFixed(pwgc.decimal_places).replace('.', pwgc.decimal_separator)); 111 } else if (floatAmount > maxAmount) { 112 jQuery('#pwgc-custom-amount-error').html(pwgc.i18n.max_amount_error + maxAmount.toFixed(pwgc.decimal_places).replace('.', pwgc.decimal_separator)); 113 } else { 114 jQuery(this).val(floatAmount.toFixed(pwgc.decimal_places).replace('.', pwgc.decimal_separator).replace(/\B(?=(\d{3})+(?!\d))/g, pwgc.thousand_separator)); 115 } 116 } else { 117 jQuery('#pwgc-custom-amount-error').html(pwgc.i18n.custom_amount_required_error); 118 } 119 }); 120 121 jQuery('#pwgc-to').on('blur', function() { 122 var recipients = jQuery(this).val(); 123 if (recipients) { 124 // For clarity, ensure we do a comma followed by a space. 125 // Babel translation of this line: 126 // jQuery(this).val(recipients.trim().split(/[ ,]+/).map(item=>item.trim()).join(', ')); 127 128 // This is compatible with IE11 129 130 recipients = recipients.trim().split(/[ ,]+/).map(function (item) { 131 return item.trim(); 132 }); 133 134 if (pwgc.allow_multiple_recipients != 'yes' && recipients.length > 1) { 135 recipients = [recipients[0]]; 136 } 137 138 jQuery(this).val(recipients.join(', ')); 139 } 140 141 pwgc_toggle_quantity(); 142 }); 143 144 jQuery('.variations_form').on( 'found_variation.wc-variation-form', function() { 145 pwgc_toggle_quantity(); 146 }); 147 148 jQuery('.variations_form').on( 'reset_data', function() { 149 pwgc_toggle_quantity(); 150 }); 151 152 jQuery('.variations_form').on( 'submit', function(e) { 153 if (jQuery('#pwgc-to').length) { 154 var recipients = jQuery('#pwgc-to').val().split(/[ ,]+/); 155 var badRecipients = []; 156 157 for (var i = 0; i < recipients.length; i++) { 158 if (!pwgc_is_email(recipients[i])) { 159 badRecipients.push(recipients[i]); 160 } 161 } 162 163 if (badRecipients.length) { 164 alert(pwgc.i18n.invalid_recipient_error + '\n\n' + badRecipients.join('\n')); 165 e.preventDefault(); 166 return false;
167 } 168 } 169 }); 170 171 jQuery('.show-pw-gift-card').off('click.pwgc').on('click.pwgc', function(e) { 172 jQuery('.checkout_pw_gift_card').slideToggle(400, function() { 173 jQuery('.checkout_pw_gift_card').find(':input:eq(0)').focus(); 174 }); 175 176 e.preventDefault(); 177 return false; 178 }); 179 180 jQuery('#pwgc-apply-gift-card-checkout').off('click.pwgc').on('click.pwgc', function(e) { 181 pwgc_checkout_redeem_gift_card(jQuery(this)); 182 e.preventDefault(); 183 return false; 184 }); 185 186 jQuery('#pwgc-redeem-gift-card-number').off('keypress.pwgc').on('keypress.pwgc', function(e) { 187 if (e.keyCode == 13) { 188 pwgc_checkout_redeem_gift_card(jQuery('#pwgc-apply-gift-card-checkout')); 189 190 e.preventDefault(); 191 return false; 192 } 193 }); 194 195 var deliveryDateField = document.getElementById('pwgc-delivery-date'); 196 if (deliveryDateField) { 197 var today = new Date(); 198 today.setDate(today.getDate()); 199 200 var nextYear = new Date(); 201 nextYear.setDate(nextYear.getDate() + 365); 202 203 var picker = new Pikaday({ 204 field: deliveryDateField, 205 minDate: today, 206 maxDate: nextYear, 207 format: pwgc.pikaday.format, 208 firstDay: pwgc.pikaday.firstDay, 209 i18n: { 210 previousMonth : pwgc.i18n.previousMonth, 211 nextMonth : pwgc.i18n.nextMonth, 212 months : [pwgc.i18n.jan, pwgc.i18n.feb, pwgc.i18n.mar, pwgc.i18n.apr, pwgc.i18n.may, pwgc.i18n.jun, pwgc.i18n.jul, pwgc.i18n.aug, pwgc.i18n.sep, pwgc.i18n.oct, pwgc.i18n.nov, pwgc.i18n.dec], 213 weekdays : [pwgc.i18n.sunday, pwgc.i18n.monday, pwgc.i18n.tuesday, pwgc.i18n.wednesday, pwgc.i18n.thursday, pwgc.i18n.friday, pwgc.i18n.saturday], 214 weekdaysShort : [pwgc.i18n.sun, pwgc.i18n.mon, pwgc.i18n.tue, pwgc.i18n.wed, pwgc.i18n.thu, pwgc.i18n.fri, pwgc.i18n.sat] 215 }, 216 }); 217 } 218}); 219 220function pwgc_pad(n, width, z) { 221 z = z || '0'; 222 n = n + ''; 223 return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; 224} 225 226function pwgc_is_email(email) { 227 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; 228 return regex.test(email); 229} 230 231function pwgc_toggle_quantity() { 232 if (jQuery('#pwgc-to').length) { 233 var recipients = jQuery('#pwgc-to').val().split(/[ ,]+/); 234 if (recipients.length > 1) { 235 jQuery('#pwgc-recipient-count').text(recipients.length); 236 jQuery('#pwgc-quantity-one-per-recipient').show(); 237 jQuery('input.qty').val('1'); 238 jQuery('.quantity').hide(); 239 } else { 240 jQuery('#pwgc-quantity-one-per-recipient').hide(); 241 jQuery('.quantity').show(); 242 } 243 } 244} 245 246function pwgc_toggle_custom_amount_visibility() { 247 var showOtherAmount = false; 248 var attributeSelector = jQuery(document.getElementById(pwgc.denomination_attribute_slug)); 249 if (attributeSelector.length != 0) { 250 showOtherAmount = (attributeSelector.val() == pwgc.other_amount_prompt); 251 } else { 252 var selectedRadioButton = jQuery("input[type='radio'][name='attribute_" + pwgc.denomination_attribute_slug + "']:checked"); 253 if (selectedRadioButton.length > 0) { 254 showOtherAmount = (selectedRadioButton.val() == pwgc.other_amount_prompt); 255 } else { 256 attributeSelector = jQuery(document.getElementsByName('attribute_' + pwgc.denomination_attribute_slug)); 257 showOtherAmount = (attributeSelector.val() == pwgc.other_amount_prompt); 258 } 259 } 260 261 if (showOtherAmount) { 262 jQuery('#pwgc-custom-amount-form').show(); 263 jQuery('#pwgc-custom-amount').focus(); 264 } else { 265 jQuery('#pwgc-custom-amount-form').hide(); 266 } 267} 268 269function pwgc_check_balance() { 270 var cardNumber = jQuery('#pwgc-balance-number'); 271 if (!cardNumber.val()) { return; } 272 273 jQuery('#pwgc-balance-error').text(''); 274 jQuery('#pwgc-balance-activity,#pwgc-balance-expiration-date-container,#pwgc-balance-reload,#pwgc-manual-debit').hide(); 275 jQuery('#pwgc-balance-amount').html(pwgc.balance_check_icon); 276 277 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-balance', 'card_number': cardNumber.val(), 'security': pwgc.nonces.check_balance}, function( result ) { 278 if (result.success) { 279 280 jQuery('#pwgc-balance-amount').html(result.data.balance); 281 282 if (result.data.expiration_date) { 283 jQuery('#pwgc-balance-expiration-date').html(result.data.expiration_date); 284 jQuery('#pwgc-balance-expiration-date-container').show(); 285 } 286 287 jQuery('#pwgc-balance-activity').html(result.data.activity).show(); 288 jQuery('#pwgc-balance-reload,#pwgc-manual-debit').attr('data-card-number', result.data.card_number).show(); 289 290 } else { 291 jQuery('#pwgc-balance-error').text(result.data.message); 292 jQuery('#pwgc-balance-amount').text(''); 293 jQuery('#pwgc-balance-activity,#pwgc-balance-expiration-date-container,#pwgc-balance-reload,#pwgc-manual-debit').hide(); 294 } 295 cardNumber.focus(); 296 297 }).fail(function(xhr, textStatus, errorThrown) { 298 if (errorThrown) { 299 jQuery('#pwgc-balance-error').text(errorThrown); 300 } else { 301 jQuery('#pwgc-balance-error').text('Unknown Error'); 302 } 303 jQuery('#pwgc-balance-amount').text(''); 304 jQuery('#pwgc-balance-reload,#pwgc-manual-debit').hide(); 305 cardNumber.focus(); 306 }); 307} 308 309function pwgc_bind_remove_link() { 310 jQuery('.pwgc-remove-card').off('click.pwgc').on('click.pwgc', function(e) { 311 var cardNumber = jQuery(this).attr('data-card-number'); 312 var checkoutContainer = jQuery(this).parents( '.woocommerce-checkout-review-order' ); 313 314 if (checkoutContainer.length) { 315 checkoutContainer.addClass( 'processing' ).block({ 316 message: null, 317 overlayCSS: { 318 background: '#fff', 319 opacity: 0.6 320 } 321 }); 322 } 323 324 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-remove', 'card_number': cardNumber, 'security': pwgc.nonces.remove_card}, function( result ) { 325 if (checkoutContainer.length) { 326 jQuery( '.woocommerce-error, .woocommerce-message' ).remove(); 327 checkoutContainer.removeClass( 'processing' ).unblock(); 328 jQuery( document.body ).trigger( 'update_checkout', { update_shipping_method: false } ); 329 } else { 330 jQuery( document.body ).trigger( 'wc_update_cart' ); 331 } 332 }).fail(function(xhr, textStatus, errorThrown) { 333 if (errorThrown) { 334 console.log(errorThrown); 335 } else { 336 console.log('Unknown Error'); 337 } 338 }); 339 340 e.preventDefault(); 341 return false;
342 }); 343} 344 345function pwgc_bind_redeem_form() { 346 jQuery('#pwgc-redeem-form').off('submit.pwgc').on('submit.pwgc', function(e) { 347 var redeemButton = jQuery('#pwgc-redeem-button'); 348 349 pwgc_redeem_gift_card(redeemButton); 350 351 e.preventDefault(); 352 return false; 353 }); 354 355 jQuery('#pwgc-apply-gift-card,#pwgc-redeem-button').off('click.pwgc').on('click.pwgc', function(e) { 356 pwgc_redeem_gift_card(jQuery(this)); 357 358 e.preventDefault(); 359 return false; 360 }); 361 362 jQuery('#pwgc-redeem-gift-card-number').off('keypress.pwgc').on('keypress.pwgc', function(e) { 363 if (e.keyCode == 13) { 364 pwgc_redeem_gift_card(jQuery('#pwgc-apply-gift-card')); 365 366 e.preventDefault(); 367 return false; 368 } 369 }); 370} 371 372function pwgc_redeem_gift_card(redeemButton) { 373 var cardNumber = jQuery('#pwgc-redeem-gift-card-number'); 374 var errorContainer = jQuery('#pwgc-redeem-error'); 375 376 errorContainer.text(''); 377 redeemButton.attr('data-apply-text', redeemButton.attr('value')).attr('value', redeemButton.attr('data-wait-text')).prop('disabled', true); 378 379 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-redeem', 'card_number': cardNumber.val(), 'security': pwgc.nonces.apply_gift_card}, function( result ) { 380 if (result.success) { 381 jQuery( document.body ).trigger( 'wc_update_cart' ); 382 } else { 383 errorContainer.text(result.data.message); 384 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 385 cardNumber.focus(); 386 } 387 }).fail(function(xhr, textStatus, errorThrown) { 388 if (errorThrown) { 389 errorContainer.text(errorThrown); 390 } else { 391 errorContainer.text('Unknown Error'); 392 } 393 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 394 cardNumber.focus(); 395 }); 396} 397 398function pwgc_message_characters_remaining() { 399 var charsRemaining = pwgc.max_message_characters; 400 401 var messageElement = jQuery('#pwgc-message').val(); 402 if (messageElement) { 403 charsRemaining -= messageElement.length; 404 } 405 406 jQuery('#pwgc-message-characters-remaining').text(charsRemaining); 407} 408 409function pwgc_checkout_redeem_gift_card(redeemButton) { 410 var errorContainer = jQuery('#pwgc-redeem-error'); 411 var cardNumber = jQuery('#pwgc-redeem-gift-card-number'); 412 413 errorContainer.text(''); 414 redeemButton.attr('data-apply-text', redeemButton.attr('value')).attr('value', redeemButton.attr('data-wait-text')).prop('disabled', true); 415 416 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-redeem', 'card_number': cardNumber.val(), 'security': pwgc.nonces.apply_gift_card}, function( result ) { 417 var form = jQuery('.checkout_pw_gift_card'); 418 if (result.success) { 419 form.slideUp(); 420 cardNumber.val(''); 421 jQuery( document.body ).trigger( 'update_checkout', { update_shipping_method: false } ); 422 } else { 423 errorContainer.text(result.data.message); 424 cardNumber.focus(); 425 } 426 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 427 }).fail(function(xhr, textStatus, errorThrown) { 428 if (errorThrown) { 429 errorContainer.text(errorThrown); 430 } else { 431 errorContainer.text('Unknown Error'); 432 } 433 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 434 cardNumber.focus(); 435 }); 436}
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.