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 */ 32 33})( jQuery ); 34 35var foxpost_wc_shipping_public = {}; 36var MT = window.MT || {}; 37 38jQuery(document).ready(function($) { 39 40 foxpost_wc_shipping_public = { 41 init: function() { 42 //console.log('foxpost_wc_shipping_public::init'); 43 44 jQuery(window).on("message", function(e) { 45 var apt = JSON.parse(e.originalEvent.data); 46 47 foxpost_wc_shipping_public.select_parcel_box(apt.operator_id); 48 //Hide the modal window 49 MT.modalWindow.hide(); 50 return true; 51 }); 52 53 54 }, 55 show_modal: function() { 56 //console.log('foxpost_wc_shipping_public::show_modal'); 57 }, 58 hide_modal: function() { 59 //console.log('foxpost_wc_shipping_public::hide_modal'); 60 }, 61 select_parcel_box: function(apt) { 62 //console.log('foxpost_wc_shipping_public::select_parcel_box:'+apt); 63 64 65 var page = 'checkout'; 66 if( jQuery('body').hasClass('woocommerce-cart')) page = 'cart'; 67 var security = '' 68 var ajax_url = ''; 69 //Set based on page 70 if(page == 'checkout') { 71 security = wc_checkout_params.update_order_review_nonce; 72 ajax_url = wc_checkout_params.ajax_url; 73 } else { 74 security = wc_cart_params.update_shipping_method_nonce; 75 ajax_url = wc_cart_params.ajax_url; 76 } 77 78 79 //Create reuqest 80 var data = { 81 action: 'foxpost_wc_shipping_select', 82 security: security, 83 page: page, 84 apt: apt 85 }; 86 87 //Make ajax request 88 jQuery.post(ajax_url, data, function(response) { 89 90 //TODO handle error 91 if(response.success) { 92 93 // Refresh the review order section, so the selected point is visible automatically 94 jQuery('body').trigger('update_checkout'); 95 96 //Update cart 97 if( jQuery('.cart_totals input.shipping_method:checked').length) { 98 jQuery('.cart_totals input.shipping_method:checked').trigger( 'change' ); 99 } else { 100 jQuery('.cart_totals input.shipping_method').trigger( 'change' ); //This is when the only available option is the pont shipping one 101 } 102 103 } else { 104 105 } 106 107 }); 108 109 return true; 110 } 111 112 } 113 114 //if( jQuery('.foxpost-wc-shipping-modal').length ) { 115 //foxpost_wc_shipping_public.init(); 116 //} 117 118});
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.