PageSourceSearch

https://www.celes-perfume.com/wp-content/plugins/pw-gift-cards/assets/js/pw-gift-cards.js?ver=1.232

js celes-perfume.com collected 2026-10-03 22:25:34 UTC 16,399 bytes, 423 lines download raw bytes

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

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.