https://www.peaksflyfishing.com/wp-content/plugins/pw-gift-cards/assets/js/pw-gift-cards.js?ver=3.94
1function pwgc_sanitize_amount(amount) { 2 if (!amount) { 3 return amount; 4 } 5 6 amount = String(amount); 7 8 if (pwgc.decimal_separator && amount.indexOf(pwgc.decimal_separator) !== -1) { 9 if (pwgc.thousand_separator) { 10 amount = amount.split(pwgc.thousand_separator).join(''); 11 } 12 amount = amount.split(pwgc.decimal_separator).join('.'); 13 } else { 14 var stripThousands = true; 15 16 // Query strings often use international decimal notation (e.g. 50.50). 17 if (pwgc.thousand_separator === '.' && pwgc.decimal_separator === ',' && amount.split('.').length === 2) { 18 var decimals = pwgc.decimal_places || 2; 19 var decimalPattern = new RegExp('\\.\\d{1,' + Math.max(1, decimals) + '}$'); 20 if (decimalPattern.test(amount)) { 21 stripThousands = false; 22 } 23 } 24 25 if (stripThousands && pwgc.thousand_separator) { 26 amount = amount.split(pwgc.thousand_separator).join(''); 27 } 28 } 29 30 return amount.replace(/[^0-9.]/g, ''); 31} 32 33function pwgc_init() { 34 var checkBalanceForm = jQuery('#pwgc-balance-form'); 35 if ( checkBalanceForm.length ) { 36 checkBalanceForm.on('submit', function(e) { 37 jQuery('#pwgc-balance-message').html(''); 38 pwgc_check_balance(); 39 40 e.preventDefault(); 41 return false; 42 }); 43 pwgc_check_balance(); 44 } 45 46 jQuery('#pwgc-balance-reload').off('click.pwgc').on('click.pwgc', function(e) { 47 var cardNumber = jQuery(this).attr('data-card-number'); 48 var productUrl = jQuery(this).attr('data-url'); 49 if (cardNumber) { 50 var separator = '?'; 51 if (productUrl.includes('?')) { 52 separator = '&'; 53 } 54 55 location.href = productUrl + separator + pwgc.reload_key + '=' + cardNumber; 56 } 57 e.preventDefault(); 58 return false; 59 }); 60 61 jQuery('#pwgc-manual-debit').off('click.pwgc').on('click.pwgc', function(e) { 62 jQuery(this).prop('disabled', true); 63 var errorMessage = jQuery('#pwgc-balance-error'); 64 errorMessage.text(''); 65 66 var cardNumber = jQuery(this).attr('data-card-number'); 67 var remainingBalance = jQuery(this).attr('data-card-remaining-balance'); 68 if (cardNumber && remainingBalance) { 69 var amount = prompt( pwgc.i18n.debit_amount_prompt, remainingBalance ); 70 if (amount) { 71 var note = prompt( pwgc.i18n.debit_note_prompt ); 72 if (note !== null) { 73 var balance = jQuery('#pwgc-balance-amount'); 74 var balanceMessage = jQuery('#pwgc-balance-message'); 75 76 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-debit', 'card_number': cardNumber, 'amount': amount, 'note': note, 'security': pwgc.nonces.debit_balance}, function(result) { 77 balance.html(result.balance); 78 balanceMessage.html(result.message); 79 pwgc_check_balance(); 80 }).fail(function(xhr, textStatus, errorThrown) { 81 if (errorThrown) { 82 errorMessage.text(errorThrown); 83 } else { 84 errorMessage.text('Unknown ajax error'); 85 } 86 }); 87 } 88 } 89 } 90 jQuery(this).prop('disabled', false); 91 e.preventDefault(); 92 return false; 93 }); 94 95 jQuery(document.body).on('updated_wc_div', pwgc_bind_redeem_form); 96 jQuery(document.body).on('updated_shipping_method', pwgc_bind_redeem_form); 97 pwgc_bind_redeem_form(); 98 99 jQuery(document.body).on('updated_wc_div', pwgc_bind_remove_link); 100 jQuery(document.body).on('updated_checkout', pwgc_bind_remove_link); 101 jQuery(document.body).on('updated_shipping_method', pwgc_bind_remove_link); 102 pwgc_bind_remove_link(); 103 104 jQuery('#pwgc-message').on('input propertychange', function() { 105 pwgc_message_characters_remaining(); 106 }); 107 pwgc_message_characters_remaining(); 108 109 var giftCardVariationForm = jQuery('form.variations_form:has(#pwgc-purchase-container)'); 110 111 giftCardVariationForm.on('show_variation', function() { 112 jQuery(this).find('#pwgc-purchase-container').show(); 113 pwgc_toggle_quantity(this); 114 pwgc_toggle_custom_amount_visibility(); 115 }); 116 117 giftCardVariationForm.on('hide_variation', function() { 118 jQuery(this).find('#pwgc-purchase-container').hide(); 119 pwgc_toggle_quantity(this); 120 pwgc_toggle_custom_amount_visibility(); 121 }); 122 123 if (jQuery('#pwgc-purchase-container').length) { 124 var attributeSelector = jQuery(document.getElementById(pwgc.denomination_attribute_slug)); 125 if (attributeSelector.length == 0) { 126 attributeSelector = jQuery(document.getElementsByName('attribute_' + pwgc.denomination_attribute_slug)); 127 } 128 129 if (attributeSelector.val()) { 130 jQuery('#pwgc-purchase-container').show(); 131 } else { 132 jQuery('#pwgc-purchase-container').hide(); 133 } 134 135 pwgc_toggle_custom_amount_visibility(); 136 } 137 138 jQuery('#pwgc-custom-amount').on('blur', function() { 139 jQuery('#pwgc-custom-amount-error').text(''); 140 141 var amount = pwgc_sanitize_amount(jQuery(this).val()); 142 if (amount) { 143 var floatAmount = parseFloat(amount); 144 var container = jQuery('#pwgc-purchase-container'); 145 var minAmount = parseFloat(container.attr('data-min-amount')); 146 var maxAmount = parseFloat(container.attr('data-max-amount')); 147 148 if (floatAmount < minAmount) { 149 jQuery('#pwgc-custom-amount-error').html(pwgc.i18n.min_amount_error + minAmount.toFixed(pwgc.decimal_places).replace('.', pwgc.decimal_separator)); 150 } else if (floatAmount > maxAmount) { 151 jQuery('#pwgc-custom-amount-error').html(pwgc.i18n.max_amount_error + maxAmount.toFixed(pwgc.decimal_places).replace('.', pwgc.decimal_separator)); 152 } else { 153 jQuery(this).val(floatAmount.toFixed(pwgc.decimal_places).replace('.', pwgc.decimal_separator).replace(/\B(?=(\d{3})+(?!\d))/g, pwgc.thousand_separator)); 154 } 155 } else { 156 jQuery('#pwgc-custom-amount-error').html(pwgc.i18n.custom_amount_required_error); 157 } 158 }); 159 160 jQuery('#pwgc-to').on('blur', function() { 161 var recipients = jQuery(this).val(); 162 if (recipients) { 163 // For clarity, ensure we do a comma followed by a space. 164 // Babel translation of this line: 165 // jQuery(this).val(recipients.trim().split(/[ ,]+/).map(item=>item.trim()).join(', ')); 166 167 // This is compatible with IE11 168 169 recipients = recipients.trim().split(/[ ,]+/).map(function (item) { 170 return item.trim(); 171 }); 172 173 if (pwgc.allow_multiple_recipients != 'yes' && recipients.length > 1) { 174 recipients = [recipients[0]]; 175 } 176 177 jQuery(this).val(recipients.join(', ')); 178 } 179 180 pwgc_toggle_quantity(); 181 }); 182 183 giftCardVariationForm.on( 'found_variation.wc-variation-form', function() { 184 pwgc_toggle_quantity(this); 185 }); 186 187 giftCardVariationForm.on( 'reset_data', function() { 188 pwgc_toggle_quantity(this); 189 }); 190 191 giftCardVariationForm.on( 'submit', function(e) { 192 var pwgcTo = jQuery(this).find('#pwgc-to'); 193 if (!pwgcTo.length) { 194 return; 195 } 196 197 var recipients = pwgcTo.val().split(/[ ,]+/); 198 var badRecipients = []; 199 200 for (var i = 0; i < recipients.length; i++) { 201 if (!pwgc_is_email(recipients[i])) { 202 badRecipients.push(recipients[i]); 203 } 204 } 205 206 if (badRecipients.length) { 207 alert(pwgc.i18n.invalid_recipient_error + '\n\n' + badRecipients.join('\n')); 208 e.preventDefault(); 209 return false;
210 } 211 }); 212 213 jQuery('.show-pw-gift-card').off('click.pwgc').on('click.pwgc', function(e) { 214 jQuery('.checkout_pw_gift_card').slideToggle(400, function() { 215 jQuery('.checkout_pw_gift_card').find(':input:eq(0)').focus(); 216 }); 217 218 e.preventDefault(); 219 return false; 220 }); 221 222 jQuery('#pwgc-apply-gift-card-checkout').off('click.pwgc').on('click.pwgc', function(e) { 223 pwgc_checkout_redeem_gift_card(jQuery(this)); 224 e.preventDefault(); 225 return false; 226 }); 227 228 jQuery('#pwgc-redeem-gift-card-number').off('keypress.pwgc').on('keypress.pwgc', function(e) { 229 if (e.keyCode == 13) { 230 pwgc_checkout_redeem_gift_card(jQuery('#pwgc-apply-gift-card-checkout')); 231 232 e.preventDefault(); 233 return false; 234 } 235 }); 236 237 var deliveryDateField = document.getElementById('pwgc-delivery-date'); 238 if (deliveryDateField) { 239 var today = new Date(); 240 today.setDate(today.getDate()); 241 242 var nextYear = new Date(); 243 nextYear.setDate(nextYear.getDate() + 365); 244 245 var picker = new Pikaday({ 246 field: deliveryDateField, 247 minDate: today, 248 maxDate: nextYear, 249 format: pwgc.pikaday.format, 250 firstDay: pwgc.pikaday.firstDay, 251 i18n: { 252 previousMonth : pwgc.i18n.previousMonth, 253 nextMonth : pwgc.i18n.nextMonth, 254 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], 255 weekdays : [pwgc.i18n.sunday, pwgc.i18n.monday, pwgc.i18n.tuesday, pwgc.i18n.wednesday, pwgc.i18n.thursday, pwgc.i18n.friday, pwgc.i18n.saturday], 256 weekdaysShort : [pwgc.i18n.sun, pwgc.i18n.mon, pwgc.i18n.tue, pwgc.i18n.wed, pwgc.i18n.thu, pwgc.i18n.fri, pwgc.i18n.sat] 257 }, 258 }); 259 } 260 261 jQuery('#pwgc-email-preview-container').off('load.pwgc').on('load.pwgc', function() { 262 jQuery('#pwgc-email-preview-container').hide(); 263 264 var iFrameBody = jQuery(this).contents().find('body'); 265 if (iFrameBody.length) { 266 jQuery('#pwgc-email-preview-container').show(); 267 268 // Set the iFrame to the height of the content, plus a little extra. 269 jQuery(this).css('height', ( parseInt( pwgc.preview_padding ) + iFrameBody.prop('scrollHeight') ) + "px" ); 270 271 // Disable the Redeem button. 272 iFrameBody.find('#pwgc-email-redeem-button a').off('click.pwgc').on('click.pwgc', function(e) { 273 e.preventDefault(); 274 }); 275 } 276 jQuery('#pwgc-email-preview-button').prop( 'disabled', false ); 277 }); 278 279 jQuery('#pwgc-email-preview-button').off('click.pwgc').on('click.pwgc', function(e) { 280 pwgc_show_email_preview(); 281 e.preventDefault(); 282 }); 283 284 jQuery('#pwgc-email-design-id').off('change.pwgc').on('change.pwgc', function(e) { 285 pwgc_show_email_preview(); 286 }); 287} 288 289function pwgc_show_email_preview() { 290 var forms = document.getElementsByClassName('variations_form'); 291 if (forms.length > 0 && !forms[0].reportValidity()) { 292 return; 293 } 294 295 jQuery('#pwgc-email-preview-button').prop( 'disabled', true ); 296 jQuery('#pwgc-email-preview-container').contents().find('body').html('...'); 297 jQuery('#pwgc-email-preview-container').show(); 298 299 var previewUrl = pwgc.preview_email_url; 300 301 // Send the formatted value as entered; the preview endpoint sanitizes once (see sanitize_amount). 302 var amount = jQuery('#pwgc-custom-amount').val(); 303 304 previewUrl += '&pwgc_number=' + pwgc.example_gift_card_number; 305 previewUrl += '&variation_id=' + jQuery('.variation_id').val(); 306 previewUrl += '&design_id=' + jQuery('#pwgc-email-design-id').val(); 307 previewUrl += '&to=' + encodeURIComponent(jQuery('#pwgc-to').val()); 308 previewUrl += '&from=' + encodeURIComponent(jQuery('#pwgc-from').val()); 309 previewUrl += '&message=' + encodeURIComponent(jQuery('#pwgc-message').val()); 310 previewUrl += '&other_amount=' + encodeURIComponent(amount); 311 previewUrl += '&pdf=' + pwgc.preview_email_pdf; 312 313 if (jQuery('#pwgc-recipient-name').length) { 314 previewUrl += '&recipient_name=' + encodeURIComponent(jQuery('#pwgc-recipient-name').val()); 315 } 316 317 jQuery('#pwgc-email-preview-container').attr('src', previewUrl); 318} 319 320function pwgc_pad(n, width, z) { 321 z = z || '0'; 322 n = n + ''; 323 return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; 324} 325 326function pwgc_is_email(email) { 327 var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; 328 return regex.test(email); 329} 330 331function pwgc_toggle_quantity(form) { 332 var giftCardForm = form ? jQuery(form) : jQuery('form.variations_form:has(#pwgc-purchase-container)').first(); 333 var pwgcTo = giftCardForm.find('#pwgc-to'); 334 335 if (!pwgcTo.length) { 336 return; 337 } 338 339 var recipients = pwgcTo.val().split(/[ ,]+/); 340 if (recipients.length > 1) { 341 jQuery('#pwgc-recipient-count').text(recipients.length); 342 jQuery('#pwgc-quantity-one-per-recipient').show(); 343 giftCardForm.find('input.qty').val('1'); 344 giftCardForm.find('.quantity').hide(); 345 } else { 346 jQuery('#pwgc-quantity-one-per-recipient').hide(); 347 giftCardForm.find('.quantity').show(); 348 } 349} 350 351function pwgc_toggle_custom_amount_visibility() { 352 var showOtherAmount = false;
353 var attributeSelector = jQuery(document.getElementById(pwgc.denomination_attribute_slug)); 354 if (attributeSelector.length != 0) { 355 showOtherAmount = (attributeSelector.val() == pwgc.other_amount_prompt); 356 } else { 357 var selectedRadioButton = jQuery("input[type='radio'][name='attribute_" + pwgc.denomination_attribute_slug + "']:checked"); 358 if (selectedRadioButton.length > 0) { 359 showOtherAmount = (selectedRadioButton.val() == pwgc.other_amount_prompt); 360 } else { 361 attributeSelector = jQuery(document.getElementsByName('attribute_' + pwgc.denomination_attribute_slug)); 362 showOtherAmount = (attributeSelector.val() == pwgc.other_amount_prompt); 363 } 364 } 365 366 if (showOtherAmount) { 367 jQuery('#pwgc-custom-amount-form').show(); 368 if (pwgc.auto_focus_other_amount) { 369 jQuery('#pwgc-custom-amount').focus(); 370 } 371 } else { 372 jQuery('#pwgc-custom-amount').val(''); 373 jQuery('#pwgc-custom-amount-form').hide(); 374 } 375} 376 377function pwgc_check_balance() { 378 var cardNumber = jQuery('#pwgc-balance-number'); 379 if (!cardNumber.val()) { return; } 380 381 jQuery('#pwgc-balance-error').text(''); 382 jQuery('#pwgc-balance-activity,#pwgc-balance-expiration-date-container,#pwgc-balance-reload,#pwgc-manual-debit').hide(); 383 jQuery('#pwgc-balance-amount').html(pwgc.balance_check_icon); 384 385 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-balance', 'card_number': cardNumber.val(), 'security': pwgc.nonces.check_balance}, function( result ) { 386 if (result.success) { 387 388 jQuery('#pwgc-balance-amount').html(result.data.balance); 389 390 if (result.data.expiration_date) { 391 jQuery('#pwgc-balance-expiration-date').html(result.data.expiration_date); 392 jQuery('#pwgc-balance-expiration-date-container').show(); 393 } 394 395 jQuery('#pwgc-balance-activity').html(result.data.activity).show(); 396 jQuery('#pwgc-balance-reload,#pwgc-manual-debit').attr('data-card-number', result.data.card_number).attr('data-url', result.data.url).show(); 397 jQuery('#pwgc-manual-debit').attr('data-card-remaining-balance', result.data.remaining_balance).show(); 398 } else { 399 jQuery('#pwgc-balance-error').text(result.data.message); 400 jQuery('#pwgc-balance-amount').text(''); 401 jQuery('#pwgc-balance-activity,#pwgc-balance-expiration-date-container,#pwgc-balance-reload,#pwgc-manual-debit').hide(); 402 } 403 cardNumber.focus(); 404 405 }).fail(function(xhr, textStatus, errorThrown) { 406 if (errorThrown) { 407 jQuery('#pwgc-balance-error').text(errorThrown); 408 } else { 409 jQuery('#pwgc-balance-error').text('Unknown Error'); 410 } 411 jQuery('#pwgc-balance-amount').text(''); 412 jQuery('#pwgc-balance-reload,#pwgc-manual-debit').hide(); 413 cardNumber.focus(); 414 }); 415} 416 417function pwgc_bind_remove_link() { 418 jQuery('.pwgc-remove-card').off('click.pwgc').on('click.pwgc', function(e) { 419 var cardNumber = jQuery(this).attr('data-card-number'); 420 var checkoutContainer = jQuery(this).parents( '.woocommerce-checkout-review-order' ); 421 422 if (checkoutContainer.length) { 423 checkoutContainer.addClass( 'processing' ).block({ 424 message: null, 425 overlayCSS: { 426 background: '#fff', 427 opacity: 0.6 428 } 429 }); 430 } 431 432 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-remove', 'card_number': cardNumber, 'security': pwgc.nonces.remove_card}, function( result ) { 433 if (checkoutContainer.length) { 434 jQuery( '.woocommerce-error, .woocommerce-message' ).remove(); 435 checkoutContainer.removeClass( 'processing' ).unblock(); 436 jQuery( document.body ).trigger( 'update_checkout', { update_shipping_method: false } ); 437 } else { 438 jQuery( document.body ).trigger( 'wc_update_cart' ); 439 } 440 }).fail(function(xhr, textStatus, errorThrown) { 441 if (errorThrown) { 442 alert(errorThrown); 443 } else { 444 alert('Unknown Error'); 445 } 446 }); 447 448 e.preventDefault(); 449 return false;
450 }); 451} 452 453function pwgc_bind_redeem_form() { 454 jQuery('#pwgc-redeem-form').off('submit.pwgc').on('submit.pwgc', function(e) { 455 var redeemButton = jQuery('#pwgc-redeem-button'); 456 457 pwgc_redeem_gift_card(redeemButton); 458 459 e.preventDefault(); 460 return false; 461 }); 462 463 jQuery('#pwgc-apply-gift-card,#pwgc-redeem-button').off('click.pwgc').on('click.pwgc', function(e) { 464 pwgc_redeem_gift_card(jQuery(this)); 465 466 e.preventDefault(); 467 return false; 468 }); 469 470 jQuery('#pwgc-redeem-gift-card-number').off('keypress.pwgc').on('keypress.pwgc', function(e) { 471 if (e.keyCode == 13) { 472 pwgc_redeem_gift_card(jQuery('#pwgc-apply-gift-card')); 473 474 e.preventDefault(); 475 return false; 476 } 477 }); 478} 479 480function pwgc_redeem_gift_card(redeemButton) { 481 var cardNumber = jQuery('#pwgc-redeem-gift-card-number'); 482 var errorContainer = jQuery('#pwgc-redeem-error'); 483 484 errorContainer.text(''); 485 redeemButton.attr('data-apply-text', redeemButton.attr('value')).attr('value', redeemButton.attr('data-wait-text')).prop('disabled', true); 486 487 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-redeem', 'card_number': cardNumber.val(), 'security': pwgc.nonces.apply_gift_card}, function( result ) { 488 if (result.success) { 489 jQuery( document.body ).trigger( 'wc_update_cart' ); 490 } else { 491 errorContainer.text(result.data.message); 492 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 493 cardNumber.focus(); 494 } 495 }).fail(function(xhr, textStatus, errorThrown) { 496 if (errorThrown) { 497 errorContainer.text(errorThrown); 498 } else { 499 errorContainer.text('Unknown Error'); 500 } 501 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 502 cardNumber.focus(); 503 }); 504} 505 506function pwgc_message_characters_remaining() { 507 var charsRemaining = pwgc.max_message_characters; 508 509 var messageElement = jQuery('#pwgc-message').val(); 510 if (messageElement) { 511 charsRemaining -= messageElement.length; 512 } 513 514 jQuery('#pwgc-message-characters-remaining').text(charsRemaining); 515} 516 517function pwgc_checkout_redeem_gift_card(redeemButton) { 518 var errorContainer = jQuery('#pwgc-redeem-error'); 519 var cardNumber = jQuery('#pwgc-redeem-gift-card-number'); 520 521 errorContainer.text(''); 522 redeemButton.attr('data-apply-text', redeemButton.attr('value')).attr('value', redeemButton.attr('data-wait-text')).prop('disabled', true); 523 524 jQuery.post(pwgc.ajaxurl, {'action': 'pw-gift-cards-redeem', 'card_number': cardNumber.val(), 'security': pwgc.nonces.apply_gift_card}, function( result ) { 525 var form = jQuery('.checkout_pw_gift_card'); 526 if (result.success) { 527 form.slideUp(); 528 cardNumber.val(''); 529 jQuery( document.body ).trigger( 'update_checkout', { update_shipping_method: false } ); 530 } else { 531 errorContainer.text(result.data.message); 532 cardNumber.focus(); 533 } 534 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 535 }).fail(function(xhr, textStatus, errorThrown) { 536 if (errorThrown) { 537 errorContainer.text(errorThrown); 538 } else { 539 errorContainer.text('Unknown Error'); 540 } 541 redeemButton.attr('value', redeemButton.attr('data-apply-text')).prop('disabled', false); 542 cardNumber.focus(); 543 }); 544} 545 546if ( document.readyState !== 'loading' ) { 547 pwgc_init(); 548} else { 549 document.addEventListener('DOMContentLoaded', function () { 550 pwgc_init(); 551 }); 552}
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.