PageSourceSearch

https://www.bps-software.de/wp-content/plugins/calculation-for-contact-form-7/assets/js/front.js?ver=2.0.0

js bps-software.de collected 2026-10-05 03:41:43 UTC 13,435 bytes, 373 lines download raw bytes

1jQuery(document).ready(function() {
2	const calculateDaysBetweenDates = (date1, date2) => {
3		let timeDiff;
4		if (date2 == 0 || date1 == 0) {
5		    return 0;
6		} else {
7		    timeDiff = date2 - date1; // Calculate the difference between the two dates
8		    return Math.ceil(timeDiff / (1000 * 3600 * 24)); // Convert milliseconds to days
9		}
10	    
11	};
12	
13	// Function to calculate months between two dates
14	const calculateMonthsBetweenDates = (date1, date2) => {
15		if (date2 == 0 || date1 == 0) return 0;
16
17		const startDate = new Date(Math.min(date1, date2));
18		const endDate = new Date(Math.max(date1, date2));
19
20		let months = (endDate.getFullYear() - startDate.getFullYear()) * 12;
21		months += endDate.getMonth() - startDate.getMonth();
22
23		if (endDate.getDate() < startDate.getDate()) {
24			months--;
25		}
26
27		return months;
28	};
29
30	// Function to calculate years between two dates
31	const calculateYearsBetweenDates = (date1, date2) => {
32	    if (date2 == 0 || date1 == 0) {
33	        return 0;
34	    } else {
35
36		    const startDate = new Date(Math.min(date1, date2));
37		    const endDate = new Date(Math.max(date1, date2));
38		    
39		    let years = endDate.getFullYear() - startDate.getFullYear();
40		    
41		    // Adjust if the end day is less than the start day or the month is less
42		    if (endDate.getMonth() < startDate.getMonth() || 
43		        (endDate.getMonth() === startDate.getMonth() && endDate.getDate() < startDate.getDate())) {
44		        years--;
45		    }
46		    
47		    return years;
48		}
49	};
50
51	/* Calculate value for select box and radio button */
52	function CALCULATIONCF7_custom_radio_button(){
53		jQuery("form.wpcf7-form select option").each(function (i) {
54	       	if(jQuery(this).attr("type") === undefined) {
55	       		var cal_selectval = jQuery(this).attr("value");
56	       		if(cal_selectval.indexOf("--") != -1){
57	       			jQuery(this).closest('.wpcf7-form-control-wrap').removeAttr('data-name');
58	       			jQuery(this).closest('.wpcf7-form-control').after("<p>Custom label select is valid in pro version of Calculation For Contact Form 7 <a href='https://www.plugin999.com/plugin/calculation-for-contact-form-7/' target='_blank'>Click here Get Pro Version</a></p>");
59					jQuery(this).closest('.wpcf7-form-control').remove();
60	       		}		
61	       	}
62       	})
63		jQuery("form.wpcf7-form input").each(function () { 
64       		if( jQuery(this).attr("type") == "radio" || jQuery(this).attr("type") == "checkbox" ) {
65
66       			var cal_inputval = jQuery(this).attr("value");
67
68       			if(cal_inputval.indexOf("--") != -1){
69
70       				jQuery(this).closest('.wpcf7-form-control-wrap').removeAttr('data-name');
71	       			jQuery(this).closest('.wpcf7-form-control').after("<p>Custom label "+jQuery(this).attr("type")+" is valid in pro version of Calculation For Contact Form 7 <a href='https://www.plugin999.com/plugin/calculation-for-contact-form-7/' target='_blank'>Click here Get Pro Version</a></p>");
72					jQuery(this).closest('.wpcf7-form-control').remove();
73
74       			}
75       		}
76       	})
77	}
78
79	/* check form length */
80	if ( jQuery( ".wpcf7-form" ).length ) {
81		CALCULATIONCF7_custom_radio_button();
82		CALCULATIONCF7_calculate_formulas();
83		/* select , check box , radio button change here*/
84		jQuery("body").on("change",".wpcf7 input,.wpcf7 select",function(e){
85			CALCULATIONCF7_calculate_formulas();
86		});
87		// jQuery("input[type='number']").bind('keyup', function () {
88		//   	CALCULATIONCF7_calculate_formulas();
89		// });
90		// jQuery("input[type='text']").bind('keyup', function () {
91		//   	CALCULATIONCF7_calculate_formulas();
92		// });
93		jQuery("body").on("keyup", ".wpcf7 input[type='number'], .wpcf7 input[type='text']", function () {
94			CALCULATIONCF7_calculate_formulas();
95		});
96	}
97
98	/*calculator formula setup */
99	function CALCULATIONCF7_calculate_formulas(){
100       	var match;
101       	var reg =[]; 
102	   	var total = 0;
103		var error = 0;
104
105      	jQuery("form.wpcf7-form input").each(function () { 
106       		if( jQuery(this).attr("type") == "checkbox" || jQuery(this).attr("type") == "radio"  ) {
107       			var name = jQuery(this).attr("name").replace("[]", "");
108       			reg.push(name);
109       			//alert($(this).attr("name"));
110       		}else{
111       			reg.push(jQuery(this).attr("name"));
112       		}
113       	})
114
115       	jQuery("form.wpcf7-form select").each(function () {
116       		var name_select = jQuery(this).attr("name").replace("[]", "");
117       		reg.push(name_select);
118       	})
119
120       	reg = calculationcf7s_duplicates_type(reg);
121       	reg.sort((a, b) => b.length - a.length);
122       	var all_tag = new RegExp( reg.join("|"));
123
124    	let $x = 1;
125       	jQuery( ".calculationcf7-total" ).each(function( index ) {
126       		if($x == 1){
127	       		var type = '';
128	       		var eq = jQuery(this).data('formulas');
129	       		var prefix_left = jQuery(this).attr("prefix_left");
130	       		var prefix_right = jQuery(this).attr("prefix_right");
131	       		var thousand_sep = jQuery(this).attr("thousand_sep");
132	       		var decimal_number = jQuery(this).attr("decimal_number");
133	       		var decimal_sep = jQuery(this).attr("decimal_sep");
134	       		
135	       		if(eq != '' || eq.length != 0){
136					while ( match = all_tag.exec( eq ) ){
137						var perfact_match = calculationcf7s_word_In_String(eq,match[0]);
138						if(perfact_match != false){
139							var type = jQuery("input[name="+match[0]+"]").attr("type");
140							if( type === undefined ) {
141								var type = jQuery("input[name='"+match[0]+"[]']").attr("type");
142							}
143							
144							if( type =="checkbox" ){
145								var vl = 0;
146								jQuery("input[name='"+match[0]+"[]']:checked").each(function () {
147									var attr = jQuery(this).attr('price');
148									
149									if (typeof attr !== typeof undefined && attr !== false) {
150										vl += new Number(attr);
151									} else {
152										vl += new Number(jQuery(this).val());
153									}
154								});
155							}else if( type == "radio"){
156								var attr = jQuery("input[name='"+match[0]+"']:checked").attr('price');
157								if (typeof attr !== typeof undefined && attr !== false) {
158									var vl = attr;
159								} else {
160									 var vl = jQuery("input[name='"+match[0]+"']:checked").val();
161								}
162							}else if( type == "date"){
163							  var datevale = jQuery("input[name="+match[0]+"]").val();	
164							  if(!isNaN(new Date(datevale).getTime())){
165							  	vl=new Date(datevale).getTime();
166							  }else{
167							  	vl=0;
168							  }
169							}else if( type === undefined ){
170								var check_select = jQuery("select[name="+match[0]+"]").val();
171								if(check_select === undefined){
172									var vl = 0;
173									jQuery("select[name='"+match[0]+"[]'] option:selected").each(function () {
174										var attr = jQuery(this).attr('price');
175										if (typeof attr !== typeof undefined && attr !== false) {
176											vl += new Number(attr);
177										} else {
178											vl += new Number(jQuery(this).val());
179										}
180									});
181								} else {
182									var vl = 0;
183									jQuery("select[name="+match[0]+"] option:selected").each(function () {
184										var attr = jQuery(this).attr('price');
185										if (typeof attr !== typeof undefined && attr !== false) {
186											vl += new Number(attr);
187										} else {
188											vl += new Number(jQuery(this).val());
189										}
190									});
191								}
192							}else{
193								var attr = jQuery("input[name="+match[0]+"]").attr('price');
194								if (typeof attr !== typeof undefined && attr !== false) {
195								    var vl = attr;
196								} else {
197									var vl = jQuery("input[name="+match[0]+"]").val();	
198								}
199							}
200							if(!jQuery.isNumeric(vl)){
201								vl = 0;
202							}
203						}else{
204						 	var error = 1;
205						}
206						eq = eq.replace( match[0], String(Number(vl)) );
207						var neqf = eq;
208					}
209	       		}else{
210	       			alert("Please Enter Formula in Calculator");
211	       			return false;
212	       		}
213	       		if(error == 1){
214	       			alert("Please Enter Valid Formula in Calculator");
215	       			return false;
216	       		}
217	       		var modified = '';
218	       		var total;
219				try{
220					
221					var fresult = ''; 
222
223					function safeEval(expr) {
224						if (!/^[\d\s\+\-\*\/\%\.\(\)]+$/.test(expr)) {
225							throw new Error("Invalid formula expression");
226						}
227						return Function('"use strict"; return (' + expr + ')')();
228					}
229
230					    neqf = neqf.replace(/CEIL\(([^)]+)\)/g, function(match, expression) {
231						    return Math.ceil(safeEval(expression)); // Apply ceil to the expression
232						});
233
234						neqf = neqf.replace(/ROUND\(([^)]+)\)/g, function(match, expression) {
235						    return Math.round(safeEval(expression));
236						});
237
238						neqf = neqf.replace(/FLOOR\(([^)]+)\)/g, function(match, expression) {
239						    return Math.floor(safeEval(expression));
240						});
241
242						neqf = neqf.replace(/MOD\(([^,]+),([^,]+)\)/gi, function(match, num1, num2) {
243							var divisor = Number(safeEval(num2));
244							if (divisor === 0) {
245								return 0;
246							}
247							return Number(safeEval(num1)) % divisor;
248						});
249
250						neqf = neqf.replace(/AVERAGE\(([^)]+)\)/gi, function(match, numbers) {
251						    var nums = numbers.split(",").map(Number);
252							if (nums.some(isNaN)) return 0;
253						    return nums.reduce((a, b) => a + b, 0) / nums.length;
254						});
255
256						neqf = neqf.replace(/MIN\(([^)]+)\)/gi, function(match, numbers) {
257						    var nums = numbers.split(",").map(Number);
258							if (nums.some(isNaN)) return 0;
259						    return Math.min(...nums);
260						});
261
262						neqf = neqf.replace(/MAX\(([^)]+)\)/gi, function(match, numbers) {
263						    var nums = numbers.split(",").map(Number);
264							if (nums.some(isNaN)) return 0;
265						    return Math.max(...nums);
266						});
267
268						neqf = neqf.replace(/ABS\(([^)]+)\)/gi, function(match, number) {
269						    return Math.abs(safeEval(number));
270						});
271
272						neqf = neqf.replace(/SQRT\(([^)]+)\)/gi, function(match, expression) {
273						    var val = safeEval(expression);
274    						return val < 0 ? 0 : Math.sqrt(val);
275						});
276
277						neqf = neqf.replace(/RANDOM\(([^,]+),([^,]+)\)/gi, function(match, start, end) {
278						    return Math.floor(Math.random() * (Number(end) - Number(start) + 1)) + Number(start);
279						});
280
281						neqf = neqf.replace(/POW\(([^,]+),([^,]+)\)/gi, function(match, base, exponent) {
282						    return Math.pow(safeEval(base), safeEval(exponent));
283						});
284
285						neqf = neqf.replace(/SIN\(([^)]+)\)/gi, function(match, angle) {
286						    return Math.sin(safeEval(angle));
287						});
288
289						neqf = neqf.replace(/COS\(([^)]+)\)/gi, function(match, angle) {
290						    return Math.cos(safeEval(angle));
291						});
292						neqf = neqf.replace(/DAYS\(([^,]+),([^,]+)\)/gi, function(match, date1, date2) {
293						    return calculateDaysBetweenDates(date1.trim(), date2.trim());
294						});
295						neqf = neqf.replace(/MONTHS\(([^,]+),([^,]+)\)/gi, function(match, date1, date2) {
296						    return calculateMonthsBetweenDates(date1.trim(), date2.trim());
297						});
298						neqf = neqf.replace(/YEARS\(([^,]+),([^,]+)\)/gi, function(match, date1, date2) {
299						    return calculateYearsBetweenDates(date1.trim(), date2.trim());
300						});
301
302				    // var r = eval( neqf ); 
303					var r = safeEval(neqf); // Evaluate the final equation
304				    total = r;
305
306				    if( decimal_number != undefined ) {
307				      	fresult = r.toFixed(decimal_number);
308					} else {
309						fresult = r;
310					}
311					if( decimal_sep != undefined ) {
312						decimal_sep = decimal_sep.replace('comma', ',');
313				      	fresult = fresult.replace('.', decimal_sep);
314					}
315
316					if( thousand_sep != undefined ) {
317						thousand_sep = thousand_sep.replace('comma', ',');
318				      	fresult=fresult.toString().replace(/\B(?=(\d{3})+(?!\d))/g, thousand_sep);
319					}
320					
321					if( prefix_left != undefined ) {
322						modified = prefix_left;
323					}
324					
325					fresult = (isNaN(fresult) || !isFinite(fresult)) ? 0 : fresult;
326					modified = modified+fresult;
327					
328					if( prefix_right != undefined ) {
329						modified = modified+prefix_right;
330					}
331
332				}
333				catch(e)
334				{
335					alert(e);
336					console.log(e);
337				}
338				
339				jQuery(this).attr("price", total);
340				jQuery(this).val(modified);
341			}else {
342	            jQuery(this).after("<p>Multiple Calculator is Valid in pro version of Calculation For Contact Form 7 <a href='https://www.plugin999.com/plugin/calculation-for-contact-form-7/' target='_blank'>Click here Get Pro Version</a></p>");
343				jQuery(this).remove();
344	        }
345      		$x++;
346		});
347	}
348
349	/*contact form 7 duplicator type  */
350	function calculationcf7s_duplicates_type(arr) {
351	    var ret_arr = [];
352	    var obj = {};
353	    for (var i = 0; i < arr.length; i++) {
354	        obj[arr[i]] = true;
355	    }
356
357	    for (var key in obj) {
358	    	if("_wpcf7" == key || "_wpcf7_version" == key  || "_wpcf7_locale" == key  || "_wpcf7_unit_tag" == key || "_wpnonce" == key || "undefined" == key  || "_wpcf7_container_post" == key || "_wpcf7_nonce" == key  ){
359
360	    	}else {
361	    		ret_arr.push(key);
362	    	}
363	    }
364	    return ret_arr;
365	}
366
367	/* calculator word In String */
368	function calculationcf7s_word_In_String(s, word){
369	  return new RegExp( '\\b' + word + '\\b', 'i').test(s);
370	}
371	
372	
373});

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.