PageSourceSearch

https://mcdonaldschampselysees.fr/wp-content/plugins/wpcafe-pro//c…/modules/product-addons/assets/js/addons.js

js mcdonaldschampselysees.fr collected 2026-10-08 08:00:58 UTC 5,333 bytes, 157 lines download raw bytes

1 
2jQuery(function ($) {
3	"use strict";
4
5	// addon price calculate
6	const classNameTotal = $('.wpc-grand-total');
7
8	getCalculatedPrice($, classNameTotal, true);
9	getCalculatedPrice($, classNameTotal);
10	getVeriationPrice($, classNameTotal);
11
12	validateRequiredBlock($);
13});
14
15// calculation price
16function totalCalc($) {
17	let decimal_number_points 	= $('.wpc-product-totals').data('decimal-number-points');
18
19	let price_1 = $('.wpc-product-totals').find('.wpc-options-total').text(),
20		price_2 = $('.wpc-product-totals').find('.wpc-product-total').text();
21
22	return ( ( Number(price_1) + Number(price_2) ).toFixed(decimal_number_points) );
23}
24
25// calculation of total option selection value and total price value
26function calculateOptionsTotalPrice($,classNameTotal) {
27	let optionPrice = 0;
28	$('.wpc-addon-field:checked, .wpc-addon-field :selected, .wpc-addon-text').each(function(){
29		var current_this = $(this);
30
31		if (current_this.is("textarea") && $.trim(current_this.val()).length == 0) {
32			return;
33		}
34
35		var fieldPrice = Number(current_this.attr('data-price'));
36		optionPrice += fieldPrice;
37	});
38
39	var discount_product 		= parseInt( $('.wpc-product-totals').data('discount-product') );
40	var discount_percentage 	= parseInt( $('.wpc-product-totals').data('discount-percentage') );
41	var discount_applicable_to 	= $('.wpc-product-totals').data('discount-applicable-to');
42	var decimal_number_points 	= $('.wpc-product-totals').data('decimal-number-points');
43
44	option_total_price = optionPrice;
45	if(discount_product && discount_applicable_to == 'options_total' && optionPrice > 0) {
46		price_after_discount = (discount_percentage / 100) * optionPrice;
47		option_total_price   = optionPrice - price_after_discount;
48	}
49
50	$('.wpc-product-totals').find('.wpc-options-total').text(option_total_price.toFixed(decimal_number_points));
51	classNameTotal.text(totalCalc($));
52}
53
54// get price on initial time or change item
55function getCalculatedPrice($, classNameTotal, initialSituation = false){
56	$(".wpc-inner-addon-container").each(function(){
57		if(initialSituation) {
58			calculateOptionsTotalPrice($, classNameTotal);
59		} else {
60			$(this).on('change', function(){
61				calculateOptionsTotalPrice($, classNameTotal);
62			});
63		}
64	});
65}
66
67// get veriation price on change variable item
68function getVeriationPrice($, classNameTotal){
69	$( '.variations_form' ).each( function() {
70		$(this).on( 'found_variation', function( event, variation ) {
71			var variationPrice = variation.display_price;
72			$('.wpc-product-totals').find('.wpc-product-total').text(variationPrice);
73			classNameTotal.text(totalCalc($))
74		});
75	});
76}
77
78// validate required block for each block and during add to cart click time
79function validateRequiredBlock($){
80	// on change checkbox, radio, select validate required
81	$('.wpc-addons-container').find('.wpc-addon-required-block').each(function () {
82		var current_block = this;
83		var field_type    = $(current_block).data('field_type');
84
85		$(this).find('.wpc-addon-field').on('change keyup', function () {
86
87			if(field_type == 'dropdown' || field_type == 'text') {
88				if ($.trim($(this).val()).length == 0) {
89					$(current_block).parent().addClass('wpc-addon-field-error');
90				} else {
91					$(current_block).parent().removeClass('wpc-addon-field-error');
92				}
93			} else {
94				if ($(current_block).find('input:checked').length == 0) {
95					$(current_block).parent().addClass('wpc-addon-field-error');
96
97					// add required attribute to each item
98					$(current_block).find('input').each(function () {
99						$(this).attr('required', true);
100					});
101				} else {
102					$(current_block).parent().removeClass('wpc-addon-field-error');
103					$(current_block).find('input').each(function () {
104						$(this).attr('required', false);
105					});
106				}
107			}
108		});
109	});
110
111	// on add to cart validate required
112	$('.single_add_to_cart_button').on('click', function (e) {
113		var proceed_cart_action = true;
114
115		$('.wpc-addons-container').find('.wpc-addon-required-block').each(function () {
116			var current_block = this;
117			var field_type    = $(current_block).data('field_type');
118
119			if(field_type == 'dropdown') {
120				if ($(current_block).find('option:selected').val() == '') {
121					proceed_cart_action = false;
122					$(current_block).parent().addClass('wpc-addon-field-error');
123				} else {
124					$(current_block).parent().removeClass('wpc-addon-field-error');
125				}
126			} else if(field_type == 'text') {
127				if ($.trim($(current_block).find('input[type=text]').val()).length == 0) {
128					$(current_block).parent().addClass('wpc-addon-field-error');
129				} else {
130					$(current_block).parent().removeClass('wpc-addon-field-error');
131				}
132			} else {
133				if ($(current_block).find('input:checked').length == 0) {
134					proceed_cart_action = false;
135					$(current_block).parent().addClass('wpc-addon-field-error');
136
137					// add required attribute to each item
138					$(current_block).find('input').each(function () {
139						$(this).attr('required', true);
140					});
141				} else {
142					$(current_block).parent().removeClass('wpc-addon-field-error');
143					$(current_block).find('input').each(function () {
144						$(this).attr('required', false);
145					});
146				}
147			}
148		});
149
150		if(!proceed_cart_action) {
151			e.preventDefault();
152			window.scrollTo({top: jQuery('.wpc-inner-addon-container.wpc-addon-field-error').offset().top - 50
153			, behavior: 'smooth'});
154		}
155
156	});
157}

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.