PageSourceSearch

https://www.mingasporelmar.org/wp-content/plugins/woocommerce-grav…/gravityforms-product-addons.js?ver=3.2.4

js mingasporelmar.org collected 2026-10-04 16:43:10 UTC 8,536 bytes, 260 lines download raw bytes

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

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.