PageSourceSearch

https://chiefgold.com/wp-content/plugins/cf7-cost-calculator-price…/js/cf7_calculator.js?ver=1790340486

js chiefgold.com collected 2026-09-25 12:51:14 UTC 29,056 bytes, 615 lines download raw bytes

1(function ($) {
2    "use strict";
3    $(document).ready(function () {
4        //show value 
5        $(".wpcf7-checkbox_custom input, .wpcf7-radio_custom input").each(function (index) {
6            var row_value = $(this).val();
7            var n = row_value.search(/\|/i);
8            if (n < 1) {
9                var new_value = $(this).val();
10                if (new_value == "") {
11                    new_value = $(this).attr("value");
12                }
13                var text_lb = $(this).closest("span").find(".wpcf7-list-item-label").text();
14                if (text_lb != "") {
15                    $(this).val(new_value + "|" + text_lb);
16                }
17            }
18        });
19        $(".wpcf7-select_custom option1").each(function (index) {
20            var row_value = $(this).val();
21            var row_lable = $(this).html();
22            var n = row_value.search(/\|/i);
23            if (n < 1) {
24                $(this).val(row_value + "|" + row_lable);
25            }
26        });
27        $("body").on("click", "input.number-format", function () {
28            $(this).autoNumeric();
29            var data = $(this).autoNumeric("get");
30            $(this).val(data);
31        })
32        $("body").on("change keyup", ".wpcf7 input,.wpcf7 select,.wpcf7 textarea", function (e) {
33            $.cf7_formulas();
34            if (typeof cf7_logic != 'undefined') {
35                $("input").trigger("cf7_logic");
36            }
37        })
38        $.cf7_formulas = function () {
39            var total = 0;
40            var max = 100;
41            var reg = [];
42            var match;
43            $("form.wpcf7-form input").each(function () {
44                if ($(this).attr("type") == "checkbox" || $(this).attr("type") == "radio") {
45                    var name = $(this).attr("name");
46                    if (name !== undefined) {
47                        name = $(this).attr("name").replace("[]", "");
48                        reg.push(name);
49                    }
50                } else {
51                    var name = $(this).attr("name");
52                    if (name !== undefined) {
53                        name = $(this).attr("name").replace("[]", "");
54                        reg.push(name);
55                    }
56                }
57            })
58            $("form.wpcf7-form select").each(function () {
59                reg.push($(this).attr("name"));
60            })
61            $("form.wpcf7-form textarea").each(function () {
62                reg.push($(this).attr("name"));
63            })
64            reg = $.remove_duplicates_ctf7(reg);
65            var field_regexp = new RegExp('(' + reg.join("|") + ')(?!\\()');
66            $(".ctf7-total").each(function (index) {
67                var eq = $(this).data('formulas');
68                var value_key_vl = false;
69                if (eq == "") {
70                    return;
71                }
72                eq = eq.replace(/ /g, '');
73                // Convert function names in formulas to lowercase to make them case-insensitive
74                eq = eq.replace(/(days?|months?|years?|age2?|hours|wordcount|max|min|sum|avg|switch|rounddown)\(/gi, function(match) {
75                    return match.toLowerCase();
76                });
77                while (match = field_regexp.exec(eq)) {
78                    var type = $("input[name=" + match[0] + "]").attr("type");
79                    if (type === undefined) {
80                        var type = $("input[name='" + match[0] + "[]']").attr("type");
81                    }
82                    if (type == "checkbox") {
83                        var vl = 0;
84                        $("input[name='" + match[0] + "[]']:checked").each(function () {
85                            var row_value = $(this).val();
86                            if (row_value == "") {
87                                row_value = $(this).attr("value");
88                            }
89                            var n = row_value.search(/\|/i);
90                            if (n > 0) {
91                                var vls = row_value.split("|");
92                                vl += new Number(vls[0]);
93                            } else {
94                                var new_value = $(this).val();
95                                if (new_value == "") {
96                                    new_value = $(this).attr("value");
97                                }
98                                vl += new Number(new_value);
99                            }
100                        });
101                        $("input[name='" + match[0] + "']:checked").each(function () {
102                            var row_value = $(this).val();
103                            if (row_value == "") {
104                                row_value = $(this).attr("value");
105                            }
106                            var n = row_value.search(/\|/i);
107                            if (n > 0) {
108                                var vls = row_value.split("|");
109                                vl += new Number(vls[0]);
110                            } else {
111                                var new_value = $(this).val();
112                                if (new_value == "") {
113                                    new_value = $(this).attr("value");
114                                }
115                                vl += new Number(new_value);
116                            }
117                        });
118                    } else if (type == "radio") {
119                        var vl = $("input[name='" + match[0] + "']:checked").val();
120                        if (vl == "") {
121                            vl = $("input[name='" + match[0] + "']:checked").attr("value");
122                        }
123                        if (vl === undefined) {
124                            vl = 0;
125                        }
126                        if (vl != 0) {
127                            var n = vl.search(/\|/i);
128                            if (n > 0) {
129                                var vls = vl.split("|");
130                                vl = new Number(vls[0]);
131                            }
132                        }
133                    }
134                    else if (type == "text") {
135                        var vl = $("input[name=" + match[0] + "]").val();
136                        if (vl == "") {
137                            vl = $("input[name=" + match[0] + "]").attr("value");
138                        }
139                    } else if (type == "date") {
140                        var vl = $("input[name=" + match[0] + "]").val();
141                        if (vl == "") {
142                            vl = $("input[name=" + match[0] + "]").attr("value");
143                        }
144                    }
145                    else if (type === undefined) {
146                        var type_textarea = $("textarea[name=" + match[0] + "]").val();
147                        if (type_textarea === undefined) {
148                            var vl = $("select[name=" + match[0] + "]").val();
149                            var n = vl.search(/\|/i);
150                            if (n > 0) {
151                                var vls = vl.split("|");
152                                vl = vls[0];
153                            }
154                        } else {
155                            vl = type_textarea;
156                        }
157                    } else {
158                        if ($("input[name=" + match[0] + "]").hasClass("ctf7-total")) {
159                            var vl = $("input[name=" + match[0] + "]").attr("data-number");
160                        } else {
161                            var vl = $("input[name=" + match[0] + "]").val();
162                            if (vl == "") {
163                                vl = $("input[name=" + match[0] + "]").attr("value");
164                            }
165                        }
166                    }
167                    if ($("input[name=" + match[0] + "]").hasClass("number-format")) {
168                        $("input[name=" + match[0] + "]").autoNumeric();
169                        vl = $("input[name=" + match[0] + "]").autoNumeric("get");
170                    } else {
171                    }
172                    if (vl == "") {
173                        vl = 0;
174                    }
175                    var reg_inner = new RegExp(match[0] + "(?!\\d)", "gm");
176                    eq = eq.replace(reg_inner, vl);
177                }
178                if (cf7_calculator.data == "ok") {
179                    // Pre-process date and string functions
180                    eq = $.cf7_fomulas_days(eq);
181                    eq = $.cf7_fomulas_months(eq);
182                    eq = $.cf7_fomulas_years(eq);
183                    eq = $.cf7_fomulas_age(eq);
184                    eq = $.cf7_fomulas_age_2(eq);
185                    eq = $.cf7_fomulas_hours(eq);
186                    eq = $.cf7_wordcount(eq);
187                    eq = $.cf7_fomulas_variadic_transpile(eq, "max");
188                    eq = $.cf7_fomulas_variadic_transpile(eq, "min");
189                    eq = $.cf7_fomulas_variadic_transpile(eq, "sum");
190                    eq = $.cf7_fomulas_variadic_transpile(eq, "avg");
191                    eq = $.cf7_fomulas_switch(eq);
192                    // Provide default 0 for rounddown missing argument
193                    eq = eq.replace(/rounddown\(([^,]+)\)/g, 'rounddown($1,0)');
194                    try {
195                        const mexp = new Mexp;
196                        mexp.addToken([
197                            { token: "round", show: "round", type: 0, value: Math.round },
198                            { token: "floor", show: "floor", type: 0, value: Math.floor },
199                            { token: "ceil", show: "ceil", type: 0, value: Math.ceil },
200                            { token: "sqrt", show: "sqrt", type: 0, value: Math.sqrt },
201                            { token: "log10", show: "log10", type: 0, value: function (x) { return Math.log10(x); } },
202                            { token: "round2", show: "round2", type: 0, value: function (x) { return parseFloat(parseFloat(x).toFixed(2)); } },
203                            { token: "floor2", show: "floor2", type: 0, value: function (x) { return Math.floor(x * 100) / 100; } },
204                            {
205                                token: "custom", show: "custom", type: 0, value: function (x) {
206                                    var sVal = x.toString();
207                                    var values = sVal.split(".");
208                                    var qk_c = parseInt(values[0] || 0);
209                                    if (values.length > 1) {
210                                        var qk_l = values[1].substring(0, 1);
211                                        if (qk_l != "0") {
212                                            if (parseInt(qk_l) < 6) qk_l = "5";
213                                            else { qk_l = "0"; qk_c++; }
214                                        }
215                                        return parseFloat(qk_c + "." + qk_l);
216                                    }
217                                    return parseFloat(sVal);
218                                }
219                            },
220                            { token: "mod", show: "mod", type: 8, value: function (a, b) { return a % b; }, numberOfArguments: 2 },
221                            { token: "random", show: "random", type: 8, value: function (a, b) { return Math.floor(Math.random() * parseInt(b)) + parseInt(a); }, numberOfArguments: 2 },
222                            {
223                                token: "rounddown", show: "rounddown", type: 8, value: function (a, b) {
224                                    const factor = Math.pow(10, b);
225                                    return a >
225= 0 ? Math.floor(a * factor) / factor : Math.ceil(a * factor) / factor;
226                                }, numberOfArguments: 2
227                            },
228                            { token: "rounded_multiple", show: "rounded_multiple", type: 8, value: function (a, b) { return Math.ceil(a / b) * b; }, numberOfArguments: 2 },
229                            { token: "if", show: "if", type: 8, value: function (cond, t, f) { return cond > 0 ? t : f; }, numberOfArguments: 3 },
230                            { token: "max", show: "max", type: 8, value: Math.max, numberOfArguments: 2 },
231                            { token: "min", show: "min", type: 8, value: Math.min, numberOfArguments: 2 },
232                            { token: "avg", show: "avg", type: 8, value: function (a, b) { return (a + b) / 2; }, numberOfArguments: 2 },
233                            { token: "<=", show: "<=", type: 9, value: function (a, b) { return a <= b ? 1 : 0; } },
234                            { token: ">=", show: ">=", type: 9, value: function (a, b) { return a >= b ? 1 : 0; } },
235                            { token: "==", show: "==", type: 9, value: function (a, b) { return a == b ? 1 : 0; } },
236                            { token: "!=", show: "!=", type: 9, value: function (a, b) { return a != b ? 1 : 0; } },
237                            { token: "<", show: "<", type: 9, value: function (a, b) { return a < b ? 1 : 0; } },
238                            { token: ">", show: ">", type: 9, value: function (a, b) { return a > b ? 1 : 0; } }
239                        ]);
240                        // Fix precedence of logic operators to ensure they evaluate AFTER arithmetic
241                        mexp.tokens.forEach(t => {
242                            if (['<', '>', '<=', '>=', '==', '!='].includes(t.token)) {
243                                t.precedence = 0.5;
244                            }
245                        });
246                        var r = mexp.eval(eq); // Evaluate the final equation
247                        total = r;
248                    }
249                    catch (e) {
250                        console.error("MEXP Error:", e);
251                        total = eq;
252                    }
253                } else {
254                    try {
255                        var r = eval(eq);
256                        total = r;
257                    }
258                    catch (e) {
259                        total = eq + " Upgrade to pro version";
260                    }
261                }
262                $(this).attr("data-number", total);
263                if ($(this).hasClass("number-format")) {
264                    $(this).autoNumeric();
265                    $(this).autoNumeric("set", total);
266                    $(this).parent().find('.cf7-calculated-name').autoNumeric();
267                    $(this).parent().find('.cf7-calculated-name').autoNumeric("set", total);
268                } else {
269                    $(this).attr("value", total);
270                    $(this).val(total);
271                    $(this).parent().find('.cf7-calculated-name').html(total);
272                }
273            });
274        }
275        $.remove_duplicates_ctf7 = function (arr) {
276            var obj = {};
277            var ret_arr = [];
278            for (var i = 0; i < arr.length; i++) {
279                obj[arr[i]] = true;
280            }
281            for (var key in obj) {
282                if ("_wpcf7" == key || "_wpcf7_version" == key || "_wpcf7_locale" == key || "_wpcf7_unit_tag" == key || "_wpnonce" == key || "undefined" == key || "_wpcf7_container_post" == key || "_wpcf7_nonce" == key) {
283                } else {
284                    if (key != "") {
285                        ret_arr.push(key + "(?!\\d)");
286                    }
287                }
288            }
289            return ret_arr;
290        }
291        $.cf7_split_args = function (str) {
292            var args = [];
293            var current = "";
294            var depth = 0;
295            for (var i = 0; i < str.length; i++) {
296                var char = str[i];
297                if (char === "," && depth === 0) {
298                    args.push(current);
299                    current = "";
300                } else {
301                    if (char === "(") depth++;
302                    if (char === ")") depth--;
303                    current += char;
304                }
305            }
306            args.push(current);
307            return args;
308        };
309        $.cf7_fomulas_age = function (x) {
310            var re = /age\(([^()]*)\)/gm;
311            x = x.replace(re, function (match, content) {
312                var dob = new Date(content.trim());
313                var today = new Date();
314                return Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));
315            });
316            if (x.match(re)) {
317                x = $.cf7_fomulas_age(x);
318            }
319            return x;
320        }
321        function yeekit_cf7_fomulas_rounddown(number, num_digits = 0) {
322            const factor = Math.pow(10, num_digits);
323            return number >= 0
324                ? Math.floor(number * factor) / factor
325                : Math.ceil(number * factor) / factor;
326        }
327        $.cf7_fomulas_age_2 = function (x) {
328            var re = /age2\(([^()]*)\)/gm;
329            x = x.replace(re, function (match, content) {
330                var datas = content.split(",");
331                var dob = new Date(datas[0].trim());
332                var today = new Date(datas[1].trim());
333                return Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000));
334            });
335            if (x.match(re)) {
336                x = $.cf7_fomulas_age_2(x);
337            }
338            return x;
339        }
340        $.cf7_fomulas_days = function (x) {
341            var re = /days?\(([^()]*)\)/gm;
342            x = x.replace(re, function (match, content) {
343                var datas = content.split(",");
344                var day_end1, day_start1;
345                if (datas[1].trim().toLowerCase() == "now") {
346                    var today = new Date();
347                    day_end1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
348                } else {
349                    day_end1 = datas[1].trim();
350                }
351                if (datas[0].trim().toLowerCase() == "now") {
352                    var today = new Date();
353                    day_start1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
354                } else {
355                    day_start1 = datas[0].trim();
356                }
357                var day_end = $.cf7_fomulas_parse_date(day_end1);
358                var day_start = $.cf7_fomulas_parse_date(day_start1);
359                if (isNaN(day_end) || isNaN(day_start)) {
360                    return 0;
361                } else {
362                    return $.cf7_fomulas_datediff(day_end, day_start);
363                }
364            });
365            if (x.match(re)) {
366                x = $.cf7_fomulas_days(x);
367            }
368            return x;
369        }
370        $.cf7_fomulas_months = function (x) {
371            var re = /months?\(([^()]*)\)/gm;
372            x = x.replace(re, function (match, content) {
373                var datas = content.split(",");
374                var day_end1, day_start1;
375                if (datas[1].trim().toLowerCase() == "now") {
376                    var today = new Date();
377                    day_end1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
378                } else {
379                    day_end1 = datas[1].trim();
380                }
381                var day_end = $.cf7_fomulas_parse_date(day_end1);
382                if (datas[0].trim().toLowerCase() == "now") {
383                    var today = new Date();
384                    day_start1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
385                } else {
386                    day_start1 = datas[0].trim();
387                }
388                var day_start = $.cf7_fomulas_parse_date(day_start1);
389                if (isNaN(day_end) || isNaN(day_start)) {
390                    return 0;
391                } else {
392                    return day_start.getMonth() - day_end.getMonth() + (12 * (day_start.getFullYear() - day_end.getFullYear()))
393                }
394            });
395            if (x.match(re)) {
396                x = $.cf7_fomulas_months(x);
397            }
398            return x;
399        }
400        $.cf7_fomulas_years = function (x) {
401            var re = /years?\(([^()]*)\)/gm;
402            x = x.replace(re, function (match, content) {
403                var datas = content.split(",");
404                var day_end1, day_start1;
405                if (datas[1].trim().toLowerCase() == "now") {
406                    var today = new Date();
407                    day_end1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
408                } else {
409                    day_end1 = datas[1].trim();
410                }
411                var day_end = $.cf7_fomulas_parse_date(day_end1);
412                if (datas[0].trim().toLowerCase() == "now") {
413                    var today = new Date();
414                    day_start1 = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
415                } else {
416                    day_start1 = datas[0].trim();
417                }
418                var day_start = $.cf7_fomulas_parse_date(day_start1);
419                if (isNaN(day_end) || isNaN(day_start)) {
420                    return 0;
421                } else {
422                    return day_start.getFullYear() - day_end.getFullYear();
423                }
424            });
425            if (x.match(re)) {
426                x = $.cf7_fomulas_years(x);
427            }
428            return x;
429        }
430        $.cf7_fomulas_variadic_transpile = function (eq, funcName) {
431            var tokenStr = funcName + "(";
432            if (typeof eq !== "string" || eq.indexOf(tokenStr) === -1) return eq;
433
434            var result = "";
435            var i = 0;
436            while (i < eq.length) {
437                var idx = eq.indexOf(tokenStr, i);
438                if (idx === -1) {
439                    result += eq.substring(i);
440                    break;
441                }
442
443                if (idx > 0 && /[a-zA-Z0-9_]/.test(eq[idx - 1])) {
444                    result += eq.substring(i, idx + tokenStr.length);
445                    i = idx + tokenStr.length;
446                    continue;
447                }
448
449                result += eq.substring(i, idx);
450                var depth = 0;
451                var start = idx + tokenStr.length;
452                var j = start;
453                while (j < eq.length) {
454                    if (eq[j] === '(') depth++;
455                    else if (eq[j] === ')') {
456                        if (depth === 0) break;
457                        depth--;
458                    }
459                    j++;
460                }
461                if (j === eq.length) {
462                    result += eq.substring(idx);
463                    break;
464                }
465                var innerArgs = eq.substring(start, j);
466                var argsStrList = $.cf7_split_args(innerArgs);
467                var validArgs = [];
468                for (var argIdx = 0; argIdx < argsStrList.length; argIdx++) {
469                    var trimmed = argsStrList[argIdx].trim();
470                    if (trimmed !== "") {
471                        validArgs.push($.cf7_fomulas_variadic_transpile(trimmed, funcName));
472                    }
473                }
474
475                var transformed = "";
476                if (funcName === "max" || funcName === "min") {
477                    if (validArgs.length === 0) {
478                        transformed = "0";
479                    } else if (validArgs.length === 1) {
480                        transformed = validArgs[0];
481                    } else {
482                        transformed = validArgs[validArgs.length - 1];
483                        for (var k = validArgs.length - 2; k >= 0; k--) {
484                            transformed = funcName + "(" + validArgs[k] + "," + transformed + ")";
485                        }
486                    }
487                } else if (funcName === "sum") {
488                    if (validArgs.length === 0) {
489                        transformed = "0";
490                    } else {
491                        transformed = "((" + validArgs.join(")+(") + "))";
492                    }
493                } else if (funcName === "avg") {
494                    if (validArgs.length === 0) {
495                        transformed = "0";
496                    } else {
497                        transformed = "(((" + validArgs.join(")+(") + "))/" + validArgs.length + ")";
498                    }
499                }
500
501                result += transformed;
502                i = j + 1;
503            }
504            return result;
505        };
506        $.cf7_wordcount = function (x) {
507            var re = /wordcount\(([^()]*)\)/gm;
508            x = x.replace(re, function (match, content) {
509                return content.trim().split(/\s+/).length;
510            });
511            if (x.match(re)) {
512                x = $.cf7_wordcount(x);
513            }
514            return x;
515        }
516        $.cf7_fomulas_switch = function (eq) {
517            if (typeof eq !== "string" || eq.indexOf("switch(") === -1) return eq;
518
519            var result = "";
520            var i = 0;
521            while (i < eq.length) {
522                var idx = eq.indexOf("switch(", i);
523                if (idx === -1) {
524                    result += eq.substring(i);
525                    break;
526                }
527                result += eq.substring(i, idx);
528                var depth = 0;
529                var start = idx + 7;
530                var j = start;
531                while (j < eq.length) {
532                    if (eq[j] === '(') depth++;
533                    else if (eq[j] === ')') {
534                        if (depth === 0) break;
535                        depth--;
536                    }
537                    j++;
538                }
539                if (j === eq.length) {
540                    result += eq.substring(idx);
541                    break;
542                }
543                var innerArgs = eq.substring(start, j);
544                var args = $.cf7_split_args(innerArgs);
545
546                var target = args[0] ? args[0].trim() : "0";
547                var defaultVal = "0";
548
549                if (args.length % 2 === 0) {
550                    defaultVal = args[args.length - 1].trim();
551                }
552
553                var transformed = defaultVal;
554                var limit = args.length % 2 === 0 ? args.length - 2 : args.length - 1;
555
556                for (var k = limit - 1; k >= 1; k -= 2) {
557                    var c = args[k].trim();
558                    var v = args[k + 1].trim();
559                    transformed = "if(" + target + "==" + c + "," + v + "," + transformed + ")";
560                }
561
562                result += $.cf7_fomulas_switch(transformed);
563                i = j + 1;
564            }
565            return result;
566        };
567        $.cf7_fomulas_hours = function (x) {
568            var re = /hours\(([^()]*)\)/gm;
569            x = x.replace(re, function (match, content) {
570                var datas = content.split(",");
571                var hour_start = datas[1].trim();
572                var hour_end = datas[0].trim();
573                var hour_start_m = hour_start.split(":");
574                var hour_end_m = hour_end.split(":");
575                var h_start_h = parseInt(hour_start_m[0]);
576                var h_end_h = parseInt(hour_end_m[0]);
577                if (h_start_h >= 22 && h_end_h <= 7) {
578                    return -1;
579                } else {
580                    return $.cf7_fomulas_hoursiff(hour_start, hour_end);
581                }
582            });
583            if (x.match(re)) {
584                x = $.cf7_fomulas_hours(x);
585            }
586            return x;
587        }
588        $.cf7_fomulas_parse_date = function (str) {
589            return new Date(str);
590        }
591        $.cf7_cover_date_format = function (str, id) {
592            var date = "";
593            var format = id.data("date-format");
594            if (format == "m/d/Y") {
595                var datas = str.split("/");
596                date = datas[2] + "-" + datas[0] + "-" + datas[1];
597            } else if (format == "d/m/Y") {
598                var datas = str.split("/");
599                date = datas[2] + "-" + datas[1] + "-" + datas[0];
600            } else if (format == "F j, Y") {
601                date = str;
602            }
603            return date;
604        }
605        $.cf7_fomulas_datediff = function (first, second) {
606            second = second.getTime();
607            first = first.getTime();
608            return Math.round((second - first) / (1000 * 60 * 60 * 24));
609        }
610        if ($(".wpcf7-form").length) {
611            $.cf7_formulas();
612            $(".cf7-hide").closest('p').css('display', 'none');
613        }
614    })
615})(jQuery);

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.