1(function ($) { 2 'use strict'; 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 $(document).on('change', 'input[name="payment_method"]', function () { 32 $('body').trigger('update_checkout'); 33 }); 34 if ($('#billing_state').length) { 35 $(document).on('change', '#billing_state', function () { 36 $('body').trigger('update_checkout'); 37 }); 38 } 39 40 $(document).ready(function ($) { 41 42 /** 43 * Block Compatiblility 44 */ 45 init_tooltip(); 46 47 // Apply fee on change state of payment method selection 48 let previouslyChosenPaymentMethod = ''; 49 if ( typeof wp !== 'undefined' && wp.data && typeof wc !== 'undefined' && wc.wcBlocksData ) { 50 wp.data.subscribe( function () { 51 const chosenPaymentMethod = 52 wp.data.select( wc.wcBlocksData.PAYMENT_STORE_KEY ).getActivePaymentMethod(); 53 if ( chosenPaymentMethod !== previouslyChosenPaymentMethod ) { 54 previouslyChosenPaymentMethod = chosenPaymentMethod; 55 // addFeeDataInSession(); 56 } 57 }, wc.wcBlocksData.PAYMENT_STORE_KEY ); 58 } 59 60 // Tooltip toggle on click 61 $(document).on('click', '.wcpfc-fee-tooltip', function () { 62 $('.wcpfc-fee-tooltiptext').toggle(); 63 }); 64 65 // Function to update the fee label 66 updateFeeLabel(); 67 68 // Also run it whenever the DOM updates (e.g., when items are added/removed) 69 const observer = new MutationObserver(updateFeeLabel); 70 observer.observe(document.body, { childList: true, subtree: true }); 71 }); 72 73 function updateFeeLabel() { 74 $.each( wcpfc_public_vars.fee_tooltip_data, function( fee_slug, fee_html ){ 75 if( $('.wc-block-components-totals-fees__'+fee_slug).length > 0 ) { 76 var $valueElement = $('.wc-block-components-totals-fees__'+fee_slug).find('.wc-block-components-totals-item__value'); 77 if ($valueElement.length && $('.wcpfc-help-tip-'+fee_slug).length === 0) { 78 var $tooltip = $('<span class="wc-wcpfc-help-tip wc-block-components-tooltip wcpfc-help-tip-' + fee_slug + '" data-tip="' + fee_html + '"></span>'); 79 $valueElement.after($tooltip); 80 } 81 } 82 }); 83 init_tooltip(); 84 } 85 86 function init_tooltip() { 87 setTimeout( function(){ 88 $('.wc-wcpfc-help-tip').each(function () { 89 return $(this).tipTip({ 90 content: $(this).data('tip'), 91 keepAlive: true, 92 edgeOffset: 2 93 }); 94 }); 95 }, 1000 ); 96 } 97})(jQuery);
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.