Custom Code.
CACHE / LOCALSTORAGE:
Depois do 1º envio, grava "calcAbrasivosLeadLiberado" no navegador
e NÃO abre mais o modal nesse aparelho.
Para retestar o modal:
1) Abra: https://calculadoradeabrasivos.com/?resetCalcGate=1
ou
2) No console do navegador (F12):
localStorage.removeItem('calcAbrasivosLeadLiberado'); location.reload();
-->
#calcGateOverlay {
display: none;
position: fixed;
inset: 0;
z-index: 2147483646;
background: rgba(3, 39, 68, 0.72);
align-items: center;
justify-content: center;
padding: 16px;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
}
#calcGateOverlay.is-open {
display: flex !important;
}
#calcGateOverlay .form-wrapper {
max-width: 480px;
width: 100%;
margin: 0 auto;
padding: 30px 25px;
background-color: #cbced1;
border-radius: 12px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
color: #032744;
max-height: 90vh;
overflow-y: auto;
}
#calcGateOverlay .form-wrapper h2 {
color: #032744;
font-size: 22px;
margin: 0 0 20px;
text-align: center;
font-weight: 600;
line-height: 1.35;
}
#calcGateOverlay label {
display: block;
margin-bottom: 6px;
color: #032744;
font-weight: 500;
font-size: 14px;
}
#calcGateOverlay input {
width: 100%;
padding: 12px 14px;
margin-bottom: 16px;
border: 1px solid #032744;
border-radius: 8px;
background-color: #fff;
color: #333;
font-size: 14px;
transition: border-color 0.3s;
box-sizing: border-box;
font-family: 'Montserrat', sans-serif;
}
#calcGateOverlay input:focus {
border-color: #2c3e50;
outline: none;
}
#calcGateOverlay button[type="submit"] {
width: 100%;
padding: 14px 0;
background-color: #2c3e50;
color: #ffffff;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s;
font-family: 'Montserrat', sans-serif;
}
#calcGateOverlay button[type="submit"]:hover {
background-color: #1e2e3d;
}
#calcGateOverlay button[type="submit"]:disabled {
opacity: 0.7;
cursor: wait;
}
#calcGateErro {
display: none;
color: #c0392b;
font-size: 13px;
margin: -8px 0 12px;
text-align: center;
}
#calcGateErro.is-visible {
display: block;
}
#calcGateSucesso {
display: none;
text-align: center;
font-weight: 600;
color: #1e7a3a;
margin-top: 12px;
font-size: 14px;
}
#calcGateSucesso.is-visible {
display: block;
}
#calcGateFrame {
display: none !important;
width: 0;
height: 0;
border: 0;
position: absolute;
}
(function () {
// Evita rodar 2x se o Elementor recarregar o widget
if (window.__calcGateInit) return;
window.__calcGateInit = true;
var STORAGE_KEY = 'calcAbrasivosLeadLiberado';
var SELECTOR_CAMPOS =
'#valor1, #qtd1, #garantia1, #valor2, #qtd2, #garantia2,' +
'#valor2-1, #massa2-1, #valor2-2, #massa2-2';
var SELECTOR_BOTOES =
'button[onclick*="calcularCusto"], button[onclick*="comparar"]';
function ready(fn) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fn);
} else {
fn();
}
}
function limparLiberacao() {
try {
localStorage.removeItem(STORAGE_KEY);
} catch (e) {}
window.__calcGateLiberado = false;
}
function isLiberado() {
try {
return localStorage.getItem(STORAGE_KEY) === '1';
} catch (e) {
return window.__calcGateLiberado === true;
}
}
function setLiberado() {
try {
localStorage.setItem(STORAGE_KEY, '1');
} catch (e) {
window.__calcGateLiberado = true;
}
}
// Permite reset pelo console: resetCalcGate()
window.resetCalcGate = function () {
limparLiberacao();
window.__calcGateInit = false;
location.reload();
};
// Reset via URL: ?resetCalcGate=1
try {
var params = new URLSearchParams(window.location.search);
if (params.get('resetCalcGate') === '1') {
limparLiberacao();
params.delete('resetCalcGate');
var qs = params.toString();
var limpa = window.location.pathname + (qs ? '?' + qs : '') + window.location.hash;
window.history.replaceState({}, '', limpa);
}
} catch (e) {}
ready(function () {
var overlay = document.getElementById('calcGateOverlay');
var modal = document.getElementById('calcGateModal');
var form = document.getElementById('calcGateForm');
var iframe = document.getElementById('calcGateFrame');
var erroEl = document.getElementById('calcGateErro');
var sucessoEl = document.getElementById('calcGateSucesso');
var submitBtn = document.getElementById('calcGateSubmit');
var enviando = false;
if (!overlay || !form) return;
// Se já enviou antes neste navegador, não bloqueia de novo
if (isLiberado()) return;
function abrirModal() {
if (isLiberado()) return;
erroEl.classList.remove('is-visible');
sucessoEl.classList.remove('is-visible');
overlay.classList.add('is-open');
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
var primeiro = document.getElementById('calc_gate_nome');
if (primeiro) setTimeout(function () { primeiro.focus(); }, 60);
}
function fecharModal() {
overlay.classList.remove('is-open');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
}
function liberar() {
setLiberado();
sucessoEl.classList.add('is-visible');
setTimeout(function () {
fecharModal();
enviando = false;
submitBtn.disabled = false;
submitBtn.textContent = 'Quero receber mais informações';
// Remove listeners: a partir daqui a calculadora funciona normal
document.removeEventListener('focusin', onFocusIn, true);
document.removeEventListener('click', onClick, true);
document.removeEventListener('keydown', onKeyDown, true);
}, 900);
}
function isElementoDaCalculadora(el) {
if (!el || !el.closest) return false;
// Campo conhecido
if (el.matches && el.matches(SELECTOR_CAMPOS)) return true;
// Botão da calculadora (onclick original)
if (el.matches && el.matches(SELECTOR_BOTOES)) return true;
// Clique no texto interno do botão
var btn = el.closest(SELECTOR_BOTOES);
if (btn) return true;
return false;
}
function bloquearSeNecessario(e) {
if (isLiberado()) return false;
if (!isElementoDaCalculadora(e.target)) return false;
e.preventDefault();
e.stopPropagation();
if (typeof e.stopImmediatePropagation === 'function') {
e.stopImmediatePropagation();
}
if (e.target && e.target.blur) e.target.blur();
abrirModal();
return true;
}
function onFocusIn(e) {
bloquearSeNecessario(e);
}
function onClick(e) {
bloquearSeNecessario(e);
}
function onKeyDown(e) {
// Bloqueia ESC enquanto o modal estiver aberto
if (overlay.classList.contains('is-open') && e.key === 'Escape') {
e.preventDefault();
e.stopPropagation();
if (typeof e.stopImmediatePropagation === 'function') {
e.stopImmediatePropagation();
}
}
}
// capture: true = pega o evento ANTES do HTML original (contorna vários bloqueios)
document.addEventListener('focusin', onFocusIn, true);
document.addEventListener('click', onClick, true);
document.addEventListener('keydown', onKeyDown, true);
// Não fecha ao clicar no fundo
overlay.addEventListener('click', function (e) {
e.stopPropagation();
});
modal.addEventListener('click', function (e) {
e.stopPropagation();
});
iframe.addEventListener('load', function () {
if (!enviando) return;
liberar();
});
form.addEventListener('submit', function (e) {
if (!form.checkValidity()) {
e.preventDefault();
erroEl.classList.add('is-visible');
form.reportValidity();
return;
}
erroEl.classList.remove('is-visible');
enviando = true;
submitBtn.disabled = true;
submitBtn.textContent = 'Enviando...';
// Fallback se o iframe não disparar load
setTimeout(function () {
if (enviando) liberar();
}, 1500);
// submit nativo segue para o iframe (target)
});
});
})();