PageSourceSearch

https://casadamadeira.com.br/frontend/js/carrinho/index.js

js casadamadeira.com.br collected 2026-09-27 02:44:09 UTC 5,319 bytes, 199 lines download raw bytes

1function recaptchaSubmit() {
2	$('#PedidoAddForm').submit();
3}
4
5$(function () {
6	$.validator.addMethod('validatePhone', function (value, element) {
7		value = value.replace("(","");
8		value = value.replace(")", "");
9		value = value.replace(" ", "").trim();
10
11		let ddd = value.substr(0, 2);
12		let phone = value.substr(2);
13
14		const listDdds = ["11", "12", "13", "14", "15", "16", "17", "18", "19", "21", "22", "24", "27", "28", "31", "32", "33", "34", "35", "37", "38", "41", "42", "43", "44", "45", "46", "47", "48", "49", "51", "53", "54", "55", "61", "62", "63", "64", "65", "66", "67", "68", "69", "71", "73", "74", "75", "77", "79", "81", "82", "83", "84", "85", "86", "87", "88", "89", "91", "92", "93", "94", "95", "96", "97", "98", "99"];
15
16		if(listDdds.indexOf(ddd) == -1) {
17			return (this.optional(element) || false);
18		}
19
20		if (phone == '000000000' || phone == '00000000') {
21			return (this.optional(element) || false);
22		}
23
24		if (value.length < 10 || value.length > 11) {
25			return (this.optional(element) || false);
26		}
27
28		return (this.optional(element) || true);
29	}, 'Telefone inválido');
30
31	$.validator.addMethod('validateCpf', (value) => {
32		value = $.trim(value);
33		value = value.replace('.', '');
34		value = value.replace('.', '');
35		cpf = value.replace('-', '');
36		while (cpf.length < 11) cpf = "0" + cpf;
37		var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
38		var a = [];
39		var b = new Number;
40		var c = 11;
41		for (i = 0; i < 11; i++) {
42		  a[i] = cpf.charAt(i);
43		  if (i < 9) b += (a[i] * --c);
44		}
45		if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11 - x }
46		b = 0;
47		c = 11;
48		for (y = 0; y < 10; y++) b += (a[y] * c--);
49		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11 - x; }
50	
51		var retorno = true;
52		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]) || cpf.match(expReg)) retorno = false;
53	
54		return retorno;
55	  }, 'CPF inválido');
56	
57	$(document).keydown(function (e) {
58		if (e.which == 9) {
59			e.preventDefault();
60		}
61	});
62
63	App.init();
64
65	$('#PedidoAddForm').validate();
66
67	$(document).on('click', '.btn-cart-masterpass', function () {
68		var msg_wait = $.message.show('info', {
69			hideOnClick: false,
70			vars: {
71				'title': 'Aguarde ...',
72				'content': '<div class="loading"></div>',
73			}
74		});
75
76		$.ajax({
77			url: base_url + 'masterpass/getToken',
78			data: null,
79			type: 'POST',
80			dataType: 'json',
81			success: function (data) {
82				MasterPass.client.checkout({
83					"requestToken": data['requestToken'],
84					"callbackUrl": data['callbackUrl'],
85					"merchantCheckoutId": data['merchantCheckoutId'],
86					"allowedCardTypes": data['allowedCardTypes'],
87					"suppressShippingAddressEnable": false,
88					"loyaltyEnabled": false,
89					"requestBasicCheckout": "",
90					"version": data['version']
91				});
92
93				$.message.hide(msg_wait);
94			}
95		});
96	});
97
98	$(document).on('change', '#final-nascimento_ano', function () {
99		var value = $('#final-nascimento_ano option:selected').text();
100
101		$('#PedidoPlaceholder-ano').val(value);
102	});
103
104	$('#ClienteIndexForm').on('submit', function () {
105
106		var uriStore = $('link[rel="canonical"]').attr("href");
107		var uriBusca = uriStore.replace("/carrinho", "/busca");
108
109		$('#ClienteIndexForm').prop('action', uriBusca);
110		$('#ClienteIndexForm').submit();
111	});
112
113	$('#cart-final').on('blur', 'input[required]', function () {
114		var self = $(this),
115			alt = self.prop('alt'),
116			id = $(this).prop('id');
117
118		if (id == 'final-telefone') {
119			$('#final-telefone').rules('add', {
120				validatePhone: true
121			});
122		}
123
124		if (id == 'final-cnpj') {
125			$('#final-cnpj').rules('add', {
126				cnpj: true
127			});
128		}
129
130		if (alt == 'cpf') {
131			$('#final-cpf').rules('add', {
132				validateCpf: true
133			});
134
135			if (self.val().length < 14) {
136				self.valid();
137			}
138
139		} else {
140			self.valid();
141		}
142	});
143
144	// Clique no PASSO 2 e o container de endereco esta fechado, porem com cep preenchido
145	$(document).on('click', '#cart-ship-btn', function () {
146
147		if (!$('#cobranca-container').is(':visible') && $('#PedidoCobrancaCep').val().length == 9) {
148			$.ajax({
149				url: base_url + 'clientes/verificaPermissaoCEP',
150				data: {
151					cep: $('#PedidoCobrancaCep').val(),
152				},
153				type: 'POST'
154			}).done(function (data) {
155				data = JSON.parse(data);
156				if (data['success'] && data['response']) {
157					$('#cobranca-container').slideDown();
158				}
159			});
160		}
161	});
162
163	//Ao clicar nos proximos boxes, simula o clique no botao
164	$(document).on('click', '.final-inactive', function () {
165		$(this).parent().find('.final-active').each(function () {
166			$(this).find('.btn.btn-next-step').trigger('click');
167		});
168	});
169
170	$(document).on('blur', '#final-telefone', function (e) {
171
172		var elementoTelefone = $("#final-telefone");
173		var elementoEmail = $("#final-email");
174		var elementoNome = $("#final-nome");
175
176		if (validPhone(elementoTelefone.val())) {
177
178			$.ajax({
179				url: base_url + 'clientes/atualizaTelefone',
180				data: {
181					telefone: elementoTelefone.val(),
182					email: elementoEmail.val(),
183					nome: elementoNome.val()
184				},
185				type: 'POST',
186				async: true
187			}).done(function (data) {
188				//alert(data);
189			});
190		}
191	});
192
193	function validPhone(p) {
194		var phoneTelefone = /^[2-9]\d{2}[2-9]\d{2}\d{4}$/;
195		var phoneCelular = /^[2-9]\d{2}[2-9]\d{2}\d{5}$/;
196		var digits = p.replace(/\D/g, "");
197		return (phoneTelefone.test(digits) || phoneCelular.test(digits));
198	}
199});

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.