1var ajax_price_req; 2 3//See the gravity forms documentation for this function. 4function gform_product_total(formId, total) { 5 6 var product_id = jQuery("input[name=product_id]").val(); 7 8 if (wc_gravityforms_params.use_ajax[product_id]) { 9 return update_dynamic_price_ajax(total, formId); 10 } else { 11 return update_dynamic_price(total, formId); 12 } 13 14} 15 16function get_gravity_forms_price(formId) { 17 18 if (!_gformPriceFields[formId]) 19 return; 20 21 var price = 0; 22 23 _anyProductSelected = false; //Will be used by gformCalculateProductPrice(). 24 for (var i = 0; i < _gformPriceFields[formId].length; i++) { 25 price += gformCalculateProductPrice(formId, _gformPriceFields[formId][i]); 26 } 27 28 //add shipping price if a product has been selected 29 if (_anyProductSelected) { 30 //shipping price 31 var shipping = gformGetShippingPrice(formId) 32 price += shipping; 33 } 34 35 //gform_product_total filter. Allows uers to perform custom price calculation 36 if (window["gform_product_total"]) { 37 price = window["gform_product_total"](formId, price); 38 } 39 40 price = gform.applyFilters('gform_product_total', price, formId); 41 return price; 42} 43 44 45function update_dynamic_price(gform_total) { 46 47 // Function moved in delay so that variation prices are updated - Vidish - 16-10-2017 48 setTimeout(function () { 49 50 var product_id = jQuery("input[name=product_id]").val(); 51 var variation_id = jQuery("input[name=variation_id]").val(); 52 53 if (product_id || variation_id) { 54 var the_id = 0; 55 if (variation_id) { 56 the_id = variation_id; 57 } else { 58 the_id = product_id; 59 } 60 61 var base_price = wc_gravityforms_params.prices[the_id]; 62 jQuery('.formattedBasePrice').html(accounting.formatMoney(base_price, { 63 symbol: wc_gravityforms_params.currency_format_symbol, 64 decimal: wc_gravityforms_params.currency_format_decimal_sep, 65 thousand: wc_gravityforms_params.currency_format_thousand_sep, 66 precision: wc_gravityforms_params.currency_format_num_decimals, 67 format: wc_gravityforms_params.currency_format 68 } 69 )); 70 71 jQuery('.formattedVariationTotal').html(accounting.formatMoney(gform_total, { 72 symbol: wc_gravityforms_params.currency_format_symbol, 73 decimal: wc_gravityforms_params.currency_format_decimal_sep, 74 thousand: wc_gravityforms_params.currency_format_thousand_sep, 75 precision: wc_gravityforms_params.currency_format_num_decimals, 76 format: wc_gravityforms_params.currency_format 77 } 78 )); 79 80 jQuery('.formattedTotalPrice').html(accounting.formatMoney(parseFloat(base_price) + parseFloat(gform_total), { 81 symbol: wc_gravityforms_params.currency_format_symbol, 82 decimal: wc_gravityforms_params.currency_format_decimal_sep, 83 thousand: wc_gravityforms_params.currency_format_thousand_sep, 84 precision: wc_gravityforms_params.currency_format_num_decimals, 85 format: wc_gravityforms_params.currency_format 86 } 87 ) + wc_gravityforms_params.price_suffix[product_id] 88 ); 89 } 90 }, 1000); 91 92 93 return gform_total; 94} 95 96function update_dynamic_price_ajax(gform_total) { 97 jQuery('div.product_totals').block({ 98 message: null, 99 overlayCSS: { 100 background: '#fff', 101 opacity: 0.6 102 } 103 }); 104 105 var product_id = jQuery("input[name=product_id]").val(); 106 var variation_id = jQuery("input[name=variation_id]").val(); 107 108 var the_id = 0; 109 if (variation_id) { 110 the_id = variation_id; 111 } else { 112 the_id = product_id; 113 } 114 115 var base = wc_gravityforms_params.prices[the_id]; 116 117 if (ajax_price_req) { 118 ajax_price_req.abort(); 119 } 120 121 var opts = "product_id=" + product_id + "&variation_id=" + variation_id 122 opts += '&action=gforms_get_updated_price&gform_total=' + gform_total; 123 124 ajax_price_req = jQuery.ajax({ 125 type: "POST", 126 url: woocommerce_params.ajax_url, 127 data: opts, 128 dataType: 'json', 129 success: function (response) { 130 jQuery('.formattedBasePrice').html((response.formattedBasePrice)); 131 jQuery('.formattedVariationTotal').html(response.formattedVariationTotal); 132 jQuery('.formattedTotalPrice').html(response.formattedTotalPrice); 133 134 jQuery('div.product_totals').unblock(); 135 } 136 }); 137 return gform_total; 138} 139 140 141(function ($) { 142 $.fn.wc_gravity_form = function () { 143 var $form = this; 144 145 if (!$form.hasClass('cart')) { 146 return; 147 } 148 149 var form_id = $form.find("input[name=wc_gforms_form_id]").val(); 150 var product_type = $form.find("input[name=wc_gforms_product_type]").val(); 151 152 if (form_id) { 153 154 //Maybe jump to validation error: 155 156 if ($('.gform_validation_error', 'form.cart').length) { 157 if (!window.location.hash) { 158 window.location = window.location + '#gform_' + form_id; 159 } 160 } 161 162 163 var next_page = $form.find("input[name=wc_gforms_next_page]").val(); 164 var previous_page = $form.find("input[name=wc_gforms_previous_page]").val(); 165 166 if (product_type != 'external') { 167 $form.attr('action', ''); 168 } 169 170 $form.attr('id', 'gform_' + form_id); 171 172 $form.on('found_variation', function () { 173 try { 174 gf_apply_rules(form_id, ["0"]); 175 } catch (err) { 176 177 } 178 179 gformCalculateTotalPrice(form_id); 180 }); 181 182 183 $('button[type=submit]', $form).attr('id', 'gform_submit_button_' + form_id).addClass('button gform_button'); 184 185 if (next_page != 0) { 186 $('button[type=submit]', $form).remove(); 187 $('div.quantity', $form).remove(); 188 $('#wl-wrapper', $form).hide(); 189 } 190 191 $('.gform_next_button', $form).attr('onclick', ''); 192 193 $('.gform_next_button', $form).click(function (event) { 194 if (!window.location.hash) { 195 window.location.hash = '#_form_' + form_id; 196 } 197 198 $form.attr('action', window.location.hash); 199 $("#gform_target_page_number_" + form_id, $form).val(next_page); 200 $form.trigger("submit", [true]); 201 }); 202 203 $('.gform_previous_button', $form).click(function (event) { 204 $("#gform_target_page_number_" + form_id, $form).val(previous_page); 205 if (!window.location.hash) { 206 window.location.hash = '#_form_' + form_id; 207 } 208 209 $form.attr('action', window.location.hash); 210 $form.trigger("submit", [true]); 211 }); 212 213 214 $("form#gform_" + form_id + " .gform_fileupload_multifile").each(function () { 215 gfMultiFileUploader.setup(this); 216 }); 217 218 } 219 }; 220 221 $(document).on('wc_variation_form', function (e) { 222 var $form = $(this); 223 $form.wc_gravity_form(); 224 }); 225 226 $(document).ready(function (e) { 227 $('form.cart').each(function (index, form) { 228 var $form = $(form); 229 $form.wc_gravity_form(); 230 }); 231 }); 232 233 234 $(document).on('quick-view-displayed', function () { 235 console.log('quick view displayed'); 236 setTimeout(function () { 237 238 $.globalEval($('.quick-view-content').find('script').text()); 239 $('.quick-view-content').find('form').each(function (i, form) { 240 $(form).wc_gravity_form(); 241 }) 242 243 }, 0); 244 }); 245 246})(jQuery); 247 248 249 250 251 252
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.