1jQuery(function ($) { 2 "use strict"; 3 $('form.checkout').on('change.wt_sc_payment_method_change', 'input[name="payment_method"]', function () { 4 5 var t = {updateTimer: !1, dirtyInput: !1, 6 reset_update_checkout_timer: function () { 7 clearTimeout(t.updateTimer) 8 }, trigger_update_checkout: function () { 9 t.reset_update_checkout_timer(), t.dirtyInput = !1, 10 $(document.body).trigger("update_checkout"); 11 } 12 }; 13 t.trigger_update_checkout(); 14 }); 15 16 $('document').ready(function(){ 17 18 $('input[name="wt_coupon_to_do"]').on('change',function() { 19 var val = $(this).val(); 20 if( val == 'gift_to_a_friend' ) { 21 $('.gift_to_friend_form').show() 22 } else { 23 $('.gift_to_friend_form').hide() 24 } 25 }); 26 27 /* After the coupon box click event was done */ 28 $(document).on("wt_sc_api_coupon_click_done", function(e){ 29 wt_unblock_node($( 'div.wt_coupon_wrapper')); 30 wt_unblock_node($("div.wt-mycoupons")); 31 wt_unblock_node($("div.wt_store_credit")); 32 }); 33 34 /** Handle keyboard Enter press on coupons */ 35 $( document ).on("keypress", '.wt-single-coupon.active-coupon', function(e){ 36 if( 13 === e.which ) { 37 $( this ).trigger( 'click' ); 38 } 39 } ); 40 41 $(document).on("click",'.wt-single-coupon.active-coupon', function(e){ 42 e.preventDefault(); 43 44 if(!$('.woocommerce-notices-wrapper').length){ 45 $('#main').prepend('<div class="woocommerce-notices-wrapper"></div>'); 46 } 47 48 const coupon_code = ( $(this).attr('data-code') === undefined ? $(this).find('code').text() : $(this).attr('data-code') ); 49 const coupon_id = $(this).attr('data-id'); 50 51 $('div.wt_coupon_wrapper, div.wt-mycoupons, .div.wt_store_credit').each(function(){ 52 if($(this).find('.wt-single-coupon').length) 53 { 54 wt_block_node($(this)); 55 } 56 }); 57 58 /* For checkout block compatibility */ 59 if( $('.wc-block-checkout, .wc-block-cart').length ) { 60 61 const coupon_click_event = new CustomEvent("wt_sc_api_coupon_clicked", { 62 detail:{ 'coupon_code' : coupon_code, 'coupon_id': coupon_id} 63 }); 64 document.dispatchEvent(coupon_click_event); 65 return false; 66 } 67 68 var data = { 69 'coupon_code' : coupon_code, 70 'coupon_id' : coupon_id, 71 '_wpnonce' : WTSmartCouponOBJ.nonces.apply_coupon 72 }; 73 74 $.ajax({ 75 type: "POST", 76 async: true, 77 url: WTSmartCouponOBJ.wc_ajax_url + 'apply_coupon_on_click', 78 data: data, 79 success: function (response) { 80 if ( $( '.woocommerce-cart-form' ).length != 0 ) { 81 update_cart(true); // need only for cart page 82 } 83 84 wt_unblock_node( $( 'div.wt_coupon_wrapper' ) ); 85 wt_unblock_node($("div.wt-mycoupons")); 86 wt_unblock_node($("div.wt_store_credit")); 87 88 $( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); 89 show_notice( response ); 90 $(document.body).trigger("update_checkout"); 91 $( document.body ).trigger( "applied_coupon", [ coupon_code ] ); 92 93 $('html, body').animate({ 94 scrollTop: $(".woocommerce").offset().top 95 }, 1000); 96 } 97 }); 98 }); 99 100 $('.wt_sc_credit_history').on('click',function( e ){ e.stopPropagation(); }) 101 102 103 /* For checkout block */ 104 if( $('.wc-block-checkout').length ) { 105 $( document ).on("click", '[name="radio-control-wc-payment-method-options"]', function(){ 106 WTSmartCouponOBJ.payment_method = $('[name="radio-control-wc-payment-method-options"]:checked').val(); 107 let parent_div = $('[name="radio-control-wc-payment-method-options"]').parents('.wc-block-components-radio-control'); 108 parent_div.find('.wc-block-components-radio-control__option').removeClass('wc-block-components-radio-control__option-checked'); 109 wbte_set_block_checkout_values(); 110 }); 111 112 setTimeout( wbte_set_block_checkout_values, 200); 113 } 114 115 }); 116 117 /** Update payment method on session, if coupons are changed update checkout */ 118 $( document.body ).on( 'payment_method_selected', 119 function() { 120 jQuery( document ).on( "updated_checkout", 121 function(){ 122 const selectedPaymentMethod = $( 'form.checkout' ).find( 'input[name="payment_method"]:checked' ).val(); 123 $.ajax({ 124 type: "POST", 125 url: WTSmartCouponOBJ.wc_ajax_url + 'wbte_sc_update_payment_method_on_session', 126 data: { 127 'payment_method': selectedPaymentMethod, 128 '_wpnonce': WTSmartCouponOBJ.nonces.public 129 }, 130 success: function( response ) { 131 if ( response ) { 132 $( 'form.checkout' ).trigger( 'update' ); 133 } 134 } 135 }); 136 } 137 ); 138 } 139 ); 140 141 var wbte_set_block_checkout_values = function() { 142 143 let payment_method = ''; 144 let shipping_method = {}; 145 146 if( $('[name="radio-control-wc-payment-method-options"]').length ) { 147 148 /* Prepare payment method from radio button */ 149 payment_method = $('[name="radio-control-wc-payment-method-options"]:checked').val(); 150 151 } 152 153 /* Prepare shipping method from radio button */ 154 if( $('.wc-block-components-shipping-rates-control input[type="radio"]').length ) { 155 $('.wc-block-components-shipping-rates-control input[type="radio"]:checked').each(function(index){ 156 shipping_method[index] = $(this).val(); 157 }); 158 } 159 160 /* Store the value to global variable to prevent future auto refresh blocking */ 161 WTSmartCouponOBJ.shipping_method = shipping_method; 162 WTSmartCouponOBJ.payment_method = payment_method; 163 164 165 /* Send ajax request to set the value */ 166 let order_summary_block = $('.wp-block-woocommerce-checkout-order-summary-block'); 167 wt_block_node( order_summary_block ); 168 169 $.ajax({ 170 type: "POST", 171 async: true, 172 url: WTSmartCouponOBJ.wc_ajax_url + 'wbte_sc_set_block_checkout_values', 173 data: { '_wpnonce': WTSmartCouponOBJ.nonces.public, 'payment_method': payment_method, 'shipping_method': shipping_method }, 174 dataType: 'json', 175 success:function( data ) { 176 wt_unblock_node( order_summary_block ); 177 }, 178 error:function() { 179 wt_unblock_node( order_summary_block ); 180 } 181 }); 182 183 /* Trigger checkout block refresh */ 184 setTimeout(function(){ 185 const checkout_value_updated_event = new CustomEvent("wbte_sc_checkout_value_updated", { 186 detail:{ 'payment_method' : payment_method, 'shipping_method': shipping_method } 187 }); 188 document.dispatchEvent(checkout_value_updated_event); 189 }, 1000); 190 191 } 192 193 194 195 var show_notice = function( html_element, $target ) { 196 if ( ! $target ) { 197 $target = $( '.woocommerce-notices-wrapper:first' ) || $( '.cart-empty' ).closest( '.woocommerce' ) || $( '.woocommerce-cart-form' ); 198 } 199 $target.prepend( html_element ); 200 }; 201 202 /** 203 * Function directly using from cart.js by woocommmerce 204 * @param {bool} preserve_notices 205 */ 206 var update_cart = function( preserve_notices ) { 207 var $form = $( '.woocommerce-cart-form' ); 208 wt_block_node( $form ); 209 wt_block_node( $( 'div.cart_totals' ) ); 210 211 212 213 // Make call to actual form post URL. 214 $.ajax( { 215 type: $form.attr( 'method' ), 216 url: $form.attr( 'action' ), 217 data: $form.serialize(), 218 dataType: 'html', 219 success: function( response ) { 220 update_wc_div( response, preserve_notices ); 221 }, 222 complete: function() { 223 wt_unblock_node( $form ); 224 wt_unblock_node( $( 'div.cart_totals' ) ); 225 } 226 } ); 227 } 228 229 /** 230 * function directley used from cart.js by wooocommerce 231 * @param { jQuery object }
231 node 232 */ 233 var wt_block_node = function( node ) { 234 node.addClass( 'processing' ); 235 236 if(typeof $.fn.block === 'function') 237 { 238 node.block({ 239 message: null, 240 overlayCSS: { 241 background: '#fff', 242 opacity: 0.6 243 } 244 }); 245 } 246 } 247 globalThis.wbte_sc_block_node = wt_block_node; 248 249 /** 250 * function directley used from cart.js by wooocommerce 251 * @param {jQuery object} $node 252 */ 253 var wt_unblock_node = function( node ) { 254 node.removeClass( 'processing' ); 255 256 if(typeof $.fn.unblock === 'function') 257 { 258 node.unblock(); 259 } 260 }; 261 globalThis.wbte_sc_unblock_node = wt_unblock_node; 262 263 /** 264 * 265 * @param {string} html_str 266 * @param {bool} preserve_notices 267 */ 268 var update_wc_div = function( html_str, preserve_notices ) { 269 var $html = $.parseHTML( html_str ); 270 var $new_form = $( '.woocommerce-cart-form', $html ); 271 var $new_totals = $( '.cart_totals', $html ); 272 var $notices = $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html ); 273 274 // No form, cannot do this. 275 if ( $( '.woocommerce-cart-form' ).length === 0 ) { 276 return; 277 } 278 279 // Remove errors 280 if ( ! preserve_notices ) { 281 $( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); 282 } 283 284 if ( $new_form.length === 0 ) { 285 // If the checkout is also displayed on this page, trigger reload instead. 286 if ( $( '.woocommerce-checkout' ).length ) { 287 return; 288 } 289 290 // No items to display now! Replace all cart content. 291 var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' ); 292 $( '.woocommerce-cart-form__contents' ).closest( '.woocommerce' ).replaceWith( $cart_html ); 293 294 // Display errors 295 if ( $notices.length > 0 ) { 296 show_notice( $notices ); 297 } 298 } else { 299 // If the checkout is also displayed on this page, trigger update event. 300 if ( $( '.woocommerce-checkout' ).length ) { 301 $( document.body ).trigger( 'update_checkout' ); 302 } 303 304 $( '.woocommerce-cart-form' ).replaceWith( $new_form ); 305 $( '.woocommerce-cart-form' ).find( ':input[name="update_cart"]' ).prop( 'disabled', true ); 306 307 if ( $notices.length > 0 ) { 308 show_notice( $notices ); 309 } 310 311 update_cart_totals_div( $new_totals ); 312 } 313 314 $( document.body ).trigger( 'updated_wc_div' ); 315 }; 316 /** 317 * Function directley using from woocmmerce cart.js 318 * @param {string} html_str 319 */ 320 var update_cart_totals_div = function( html_str ) { 321 $( '.cart_totals' ).replaceWith( html_str ); 322 $( document.body ).trigger( 'updated_cart_totals' ); 323 }; 324 325 326}); 327 328
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.