Scripts

<script>
  // Delay script = performance score
  // Add code at the end of the <head> tag
  
  const load = () => {
    document.querySelectorAll("script[data-type='lazy']").forEach(el => el.setAttribute("src", el.getAttribute("data-src")));
    document.querySelectorAll("iframe[data-type='lazy']").forEach(el => el.setAttribute("src", el.getAttribute("data-src")));
  }
  const timer = setTimeout(load, 5000);
  const trigger = () => {
    load();
    clearTimeout(timer);
  }
  const events = ["mouseover","keydown","touchmove","touchstart"];
  events.forEach(e => window.addEventListener(e, trigger, {passive: true, once: true}));
</script>
// Header Fixed

$(window).scroll(function() {
  var scroll = $(window).scrollTop();

  if (scroll >= 40) {
    $(".navbar").addClass("scrolled");
  } else {
    $(".navbar").removeClass("scrolled");
  }
});
// Scroll to Top

const iconToTop = document.getElementById('scroll-to-top')
if (iconToTop) {
  iconToTop.addEventListener('click', () => {
    window.scrollTo({top: 0, behavior: 'smooth'});
  })
}
// Modal

$('[data-modal]').click((e) => {
  let id = e.target.closest('[data-modal]').dataset.modal;
  let modal = $('#' + id);

  modal.css({ display: 'flex', opacity: 0 }).animate({ opacity: 1 }, 'fast');

  // Left to right
  if (modal.is('.modal-right')) {
    modal
      .find('.modal-container')
      .css({ left: '100%' })
      .animate({ left: '0%' }, 'easeInQuad');
  }
});
// Máscara telefone brasileiro

  const inputPhone = $('.form_contact_phone')
  inputPhone.on('input', (e) => {
    let input = e.target.value.replace(/\D/g, '');
    let formatted = '';

    if (input.length > 10) {
      formatted = `(${input.substring(0, 2)}) ${input.substring(2, 7)}-${input.substring(7, 11)}`;
    } else if (input.length > 5) {
      formatted = `(${input.substring(0, 2)}) ${input.substring(2, 6)}-${input.substring(6, 10)}`;
    } else if (input.length > 2) {
      formatted = `(${input.substring(0, 2)}) ${input.substring(2)}`;
    } else {
      formatted = `(${input}`;
    }

    e.target.value = formatted;
  });

  inputPhone.on('keydown', (e) => {
    if (e.key === 'Backspace' || e.key === 'Delete') {
      e.preventDefault();
      let newValue = e.target.value.slice(0, -1)
      e.target.value = newValue;
      phoneInput.dispatchEvent(new Event('input'));
    }
  });