1jQuery(document).ready(function ($) { 2 'use strict'; 3 4 var options = wc_deposits_add_to_cart_options; 5 6 $.fn.initDepositController = function () { 7 var depositController = { 8 init: function (form, ajax_reload = false,selection = false) { 9 depositController.update_html_request = false; 10 11 var $cart = $(form); 12 var $form = $cart.find('.webtomizer_wcdp_single_deposit_form'); 13 depositController.$cart = $cart; 14 depositController.$form = $form; 15 $form.deposit = $form.find('.pay-deposit').get(0); 16 $form.full = $form.find('.pay-full-amount').get(0); 17 $form.msg = $form.find('.wc-deposits-notice'); 18 $form.amount = $form.find('.deposit-amount'); 19 $form.ajax_refreh = $form.data('ajax-refresh'); 20 21 $form.payment_plans_container = $form.find(('.wcdp-payment-plans')); 22 $cart.woocommerce_products_addons = $cart.find('#product-addons-total'); 23 24 if(typeof $.epoAPI !== 'undefined'){ 25 $.epoAPI.addFilter( 'tcAdjustFormattedFinalTotal', this.tmepo_price_change, 10, 2 ); 26 } 27 28 $cart.on('change', 'input, select', this.update_status); 29 if (!ajax_reload) { 30 31 //hide deposit form initially in variable product 32 var product_elem = $form.closest('.product'); 33 if (product_elem.hasClass('product-type-variable')) { 34 $form.slideUp(); 35 } 36 37 if ($cart.woocommerce_products_addons.length > 0) { 38 $cart.on('updated_addons', this.addons_updated); 39 } 40 41 $cart.on('show_variation', this.update_variation) 42 .on('click', '.reset_variations', function () { 43 $($form).slideUp(); 44 }); 45 $cart.on('hide_variation', this.hide); 46 47 } 48 49 $cart.on('change', 'input.option-input', this.update_payment_plans_container2); 50 51 if(selection){ 52 if(selection === 'deposit'){ 53 $(depositController.$form.deposit).attr('checked','checked'); 54 $(depositController.$form.full).removeAttr('checked'); 55 } else{ 56 $(depositController.$form.full).attr('checked','checked'); 57 $(depositController.$form.deposit).removeAttr('checked'); 58 } 59 } 60 this.update_status($form); 61 $form.on('update_html', this.update_html); 62 63 if ($($form.payment_plans_container).length > 0) { 64 this.update_payment_plans_container(); 65 } 66 67 68 }, 69 hide: function () { 70 depositController.$form.slideUp(); 71 72 }, 73 update_payment_plans_container: function () { 74 depositController.$form.payment_plans_container.find('a.wcdp-view-plan-details').click(function () { 75 var plan_id = $(this).data('id'); 76 var selector = '.plan-details-' + plan_id; 77 if ($(this).data('expanded') === 'no') { 78 var text = $(this).data('hide-text'); 79 $(this).text(text); 80 $(this).data('expanded', 'yes'); 81 depositController.$form.find(selector).slideDown(); 82 } else if ($(this).data('expanded') === 'yes') { 83 var text = $(this).data('view-text'); 84 $(this).text(text); 85 $(this).data('expanded', 'no'); 86 depositController.$form.find(selector).slideUp(); 87 } 88 89 }); 90 }, 91 update_payment_plans_container2: function (e) { 92 console.log(e); 93 console.log(e.target); 94 console.log($(this)); 95 var plan_id = $(this).data('id');
96 var selector = '.plan-details-' + plan_id; 97 $('.wcdp-view-plan-details').each(function () { 98 var thisDataId = $(this).data('id'); 99 if (thisDataId !== plan_id) { 100 var selectorOther = '.plan-details-' + thisDataId; 101 console.log(thisDataId); 102 103 var otherEx = $('.wcdp-view-plan-details[data-id='+thisDataId+']'); 104 if (otherEx.data('expanded') === 'yes') { 105 console.log('debug'); 106 var text = otherEx.data('view-text'); 107 otherEx.text(text); 108 otherEx.data('expanded', 'no'); 109 depositController.$form.find(selectorOther).slideUp(); 110 otherEx.css('visibility', 'hidden'); 111 } 112 } 113 }); 114 var rightEx = $('.wcdp-view-plan-details[data-id='+plan_id+']'); 115 if (rightEx.data('expanded') === 'no') { 116 console.log('jo'); 117 var text = rightEx.data('hide-text'); 118 rightEx.text(text); 119 rightEx.data('expanded', 'yes'); 120 depositController.$form.find(selector).slideDown(); 121 rightEx.css('visibility', 'visible'); 122 } else { 123 // console.log('jo2'); 124 // var text = rightEx.data('view-text'); 125 // rightEx.text(text); 126 // rightEx.data('expanded', 'no'); 127 // depositController.$form.find(selector).slideUp(); 128 } 129 }, 130 tmepo_price_change : function (formatted_final_total,args){ 131 132 var product_id = args.epo.product_id; 133 if($('.variation_id').length > 0 && $('.variation_id').val() != '0' ){ 134 product_id = $('.variation_id').val(); 135 } 136 var data = { 137 price: args.product_total_price / args.cartQty , 138 product_id: product_id, 139 trigger: 'woocommerce_tm_extra_product_options' 140 }; 141 depositController.$form.trigger('update_html', data); 142 return formatted_final_total; 143 }, 144 addons_updated: function () { 145 var addons_form = depositController.$cart.woocommerce_products_addons; 146 var data = { 147 price: 0, 148 product_id: $(addons_form).data('product-id'), 149 trigger: 'woocommerce_product_addons' 150 }; 151 data.price = $(addons_form).data('price'); 152 if (depositController.$cart.find('#wc-bookings-booking-form').length) { 153 //addons + bookings 154 if ($('.wc-bookings-booking-cost').length > 0) { 155 156 var booking_price = parseFloat($('.wc-bookings-booking-cost').attr('data-raw-price')); 157 if (!Number.isNaN(booking_price)) { 158 data.price = booking_price; 159 } 160 } else { 161 data.price = 0; 162 } 163 } 164 165 var addons_price = $(addons_form).data('price_data'); 166 $.each(addons_price, function (index, single_addon) { 167 data.price = data.price + single_addon.cost; 168 }); 169 if(typeof depositController.$cart.woocommerce_products_addons_price == 'undefined'){ 170 depositController.$cart.woocommerce_products_addons_price = 0; 171 } 172 var same_price = data.price === depositController.$cart.woocommerce_products_addons_price; 173 174 if (!same_price) { 175 depositController.$form.trigger('update_html', data); 176 } 177 178 179 }, 180 update_html: function (e, data) { 181 182 if (!data || depositController.$form.ajax_refreh === 'no') return; 183 if (Number.isNaN(data.price)) return; 184 if (!data.product_id) return; 185 if (depositController.$cart.woocommerce_products_addons.length && data.trigger !== 'woocommerce_product_addons') return; 186 if(data.trigger === 'woocommerce_product_addons'){ 187 depositController.$cart.woocommerce_products_addons_price = data.price; 188 189 } 190 if (depositController.update_html_request) { 191 depositController.update_html_request.abort(); 192 depositController.update_html_request = false;
193 } 194 195 depositController.$cart.block({ 196 message: null, 197 overlayCSS: { 198 background: "#fff", 199 backgroundSize: "16px 16px", opacity: .6 200 } 201 }); 202 203 var request_data = { 204 action: 'wc_deposits_update_deposit_container', 205 price: data.price, 206 product_id: data.product_id, 207 data: data //allow any other data to be included 208 }; 209 210 depositController.update_html_request = $.post(options.ajax_url, request_data).done(function (res) { 211 if (res.success) { 212 depositController.$form.replaceWith(res.data); 213 let selection = 'full'; 214 if($(depositController.$form.deposit).is(':checked')){ 215 selection = 'deposit'; 216 } 217 depositController.init(depositController.$cart, true,selection); 218 } 219 220 if(data.trigger === 'woocommerce_product_addons'){ 221 depositController.$cart.woocommerce_products_addons_price = data.price; 222 223 } 224 depositController.$cart.unblock(); 225 /*sm custom code */ 226 $(document).trigger('sm_custom_partial_payments_updated', [res]); 227 }).fail(function () { 228 // alert('Error occurred'); 229 230 }); 231 232 }, 233 update_status: function () { 234 235 if ($(depositController.$form.deposit).is(':checked')) { 236 if (depositController.$form.payment_plans_container.length > 0) { 237 depositController.$form.payment_plans_container.slideDown(); 238 } 239 240 $(depositController.$form.msg).html(options.message.deposit); 241 } else if ($(depositController.$form.full).is(':checked')) { 242 if (depositController.$form.payment_plans_container.length > 0) { 243 depositController.$form.payment_plans_container.slideUp(); 244 } 245 $(depositController.$form.msg).html(options.message.full); 246 } 247 }, 248 update_variation: function (event, variation) { 249 250 var id = variation.variation_id; 251 var data = { 252 product_id: id 253 }; 254 depositController.$form.trigger('update_html', data); 255 return; 256 257 } 258 }; 259 260 depositController.init(this); 261 262 }; 263 264 $('body').find('form.cart').each(function (index, elem) { 265 $(elem).initDepositController(); 266 }); 267 268}); 269
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.