1jQuery( function( $ ) { 2 3 // wc_add_to_cart_params is required to continue, ensure the object exists 4 if ( typeof wc_add_to_cart_params === 'undefined' ) 5 return false; 6 7 // Ajax add to cart 8 $( document ).on( 'click', '.add_to_cart_button', function(e) { 9 10 // AJAX add to cart request 11 var $thisbutton = $( this ); 12 13 if ( $thisbutton.is( '.product_type_simple' ) ) { 14 15 if ( ! $thisbutton.attr( 'data-product_id' ) ) 16 return true; 17 18 $thisbutton.removeClass( 'added' ); 19 $thisbutton.addClass( 'loading' ); 20 21 var data = { 22 action: 'uni_bridallist_add_to_cart', 23 }; 24 25 $.each( $thisbutton.data(), function( key, value ) { 26 data[key] = value; 27 }); 28 29 if ( $("input[name=uni_bridallist_item_for_user]").length > 0 ) { 30 data["uni_bridallist_item_for_user"] = $("input[name=uni_bridallist_item_for_user]").val(); 31 } 32 33 // Trigger event 34 $( 'body' ).trigger( 'adding_to_cart', [ $thisbutton, data ] ); 35 36 // Ajax action 37 $.post( wc_add_to_cart_params.ajax_url, data, function( response ) { 38 39 if ( ! response ) 40 return; 41 42 var this_page = window.location.toString(); 43 44 this_page = this_page.replace( 'add-to-cart', 'added-to-cart' ); 45 46 if ( response.error && response.product_url ) { 47 window.location = response.product_url; 48 return; 49 } 50 51 // Redirect to cart option 52 if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) { 53 54 window.location = wc_add_to_cart_params.cart_url; 55 return; 56 57 } else { 58 59 $thisbutton.removeClass( 'loading' ); 60 61 fragments = response.fragments; 62 cart_hash = response.cart_hash; 63 64 // Block fragments class 65 if ( fragments ) { 66 $.each( fragments, function( key, value ) { 67 $( key ).addClass( 'updating' ); 68 }); 69 } 70 71 // Block widgets and fragments 72 $( '.shop_table.cart, .updating, .cart_totals' ).fadeTo( '400', '0.6' ).block({ 73 message: null, 74 overlayCSS: { 75 opacity: 0.6 76 } 77 }); 78 79 // Changes button classes 80 $thisbutton.addClass( 'added' ); 81 82 // View cart text 83 if ( ! wc_add_to_cart_params.is_cart && $thisbutton.parent().find( '.added_to_cart' ).size() === 0 ) { 84 $thisbutton.after( ' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' + 85 wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>' ); 86 } 87 88 // Replace fragments 89 if ( fragments ) { 90 $.each( fragments, function( key, value ) { 91 $( key ).replaceWith( value ); 92 }); 93 } 94 95 // Unblock 96 $( '.widget_shopping_cart, .updating' ).stop( true ).css( 'opacity', '1' ).unblock(); 97 98 // Cart page elements 99 $( '.shop_table.cart' ).load( this_page + ' .shop_table.cart:eq(0) > *', function() { 100 101 $( '.shop_table.cart' ).stop( true ).css( 'opacity', '1' ).unblock(); 102 103 $( 'body' ).trigger( 'cart_page_refreshed' ); 104 }); 105 106 $( '.cart_totals' ).load( this_page + ' .cart_totals:eq(0) > *', function() { 107 $( '.cart_totals' ).stop( true ).css( 'opacity', '1' ).unblock(); 108 }); 109 110 // Trigger event so themes can refresh other areas 111 $( 'body' ).trigger( 'added_to_cart', [ fragments, cart_hash, $thisbutton ] ); 112 } 113 }); 114 115 return false; 116 117 } 118 119 return true; 120 }); 121 122});
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.