1jQuery(document).ready(function($){ 2 $(document).on( 'change', '.woocommerce_subscription_gifting_checkbox[type="checkbox"]',function( e, eventContext ) { 3 if ($(this).is(':checked')) { 4 $(this).closest( 'fieldset' ).find( '.wcsg_add_recipient_fields' ).slideDown( 250, function() { 5 if ( 'undefined' === typeof( eventContext ) || 'pageload' != eventContext ) { 6 $( this ).find( '.recipient_email' ).trigger( 'focus' ); 7 } 8 } ); 9 } else { 10 $(this).closest( 'fieldset' ).find( '.wcsg_add_recipient_fields' ).slideUp( 250 ); 11 12 var recipient_email_element = $(this).closest( 'fieldset' ).find( '.recipient_email' ); 13 recipient_email_element.val(''); 14 15 if ( $( 'form.checkout' ).length !== 0 ) { 16 // Trigger the event to update the checkout after the recipient field has been cleared 17 update_checkout(); 18 } 19 } 20 }); 21 22 /** 23 * Handles recipient e-mail inputs on the cart page. 24 */ 25 var cart = { 26 init: function() { 27 $( document ).on( 'submit', 'div.woocommerce > form', this.set_update_cart_as_clicked ); 28 29 // We need to make sure our callback is hooked before WC's. 30 var handlers = $._data( document, "events" ); 31 if ( 'undefined' !== typeof handlers['submit'] ) { 32 handlers['submit'].unshift( handlers['submit'].pop() ); 33 } 34 }, 35 36 set_update_cart_as_clicked: function( evt ) { 37 var $form = $( evt.target ); 38 var $submit = $( document.activeElement ); 39 40 // If we're not on the cart page exit. 41 if ( 0 === $form.find( 'table.shop_table.cart' ).length ) { 42 return; 43 } 44 45 // If the recipient email element is the active element, the clicked button is the update cart button. 46 if ( $submit.is( 'input.recipient_email' ) ) { 47 $( ':input[type="submit"][name="update_cart"]' ).attr( 'clicked', 'true' ); 48 } 49 } 50 }; 51 cart.init(); 52 53 /******************************************* 54 * Update checkout on input changed events * 55 *******************************************/ 56 var update_timer; 57 58 $(document).on( 'change', '.recipient_email', function() { 59 60 if ( $( 'form.checkout' ).length === 0 ) { 61 return; 62 } 63 64 // Update the checkout so recurring carts are updated 65 if ( $( this ).hasClass( 'wcsg_needs_update' ) ) { 66 update_checkout(); 67 } 68 }); 69 70 $(document).on( 'keyup', '.recipient_email', function( e ) { 71 var code = e.keyCode || e.which || 0; 72 73 if ( $( 'form.checkout' ).length === 0 || code === 9 ) { 74 return true; 75 } 76 77 var current_recipient = $( this ).val(); 78 var original_recipient = $( this ).attr( 'data-recipient' ); 79 reset_checkout_update_timer(); 80 81 // If the recipient has changed since last load, mark the element as needing an update 82 if ( current_recipient !== original_recipient ) { 83 $( this ).addClass( 'wcsg_needs_update' ); 84 update_timer = setTimeout( update_checkout, '1500' ); 85 } else { 86 $( this ).removeClass( 'wcsg_needs_update' ); 87 } 88 }); 89 90 function update_checkout() { 91 reset_checkout_update_timer(); 92 $( '.recipient_email' ).removeClass( 'wcsg_needs_update' ); 93 $( document.body ).trigger( 'update_checkout' ); 94 } 95 96 function reset_checkout_update_timer() { 97 clearTimeout( update_timer ); 98 } 99 100 // Triggers 101 $( '.woocommerce_subscription_gifting_checkbox[type="checkbox"]' ).trigger( 'change', 'pageload' ); 102});
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.