bars-line

Search product result:

Search product result:

document.addEventListener('DOMContentLoaded', function () {
  const wrappers = document.querySelectorAll('.artx__search-wrapper');

  if (!wrappers.length) return;

  function closeAll() {
    wrappers.forEach(wrapper => wrapper.classList.remove('is-open'));

    if (
      document.activeElement &&
      document.activeElement.matches('.artx__search-wrapper input')
    ) {
      document.activeElement.blur();
    }
  }

  function openWrapper(wrapper) {
    closeAll();
    wrapper.classList.add('is-open');
  }

  function isInsideBox(element, event) {
    if (!element) return false;

    const rect = element.getBoundingClientRect();

    return (
      event.clientX >= rect.left &&
      event.clientX <= rect.right &&
      event.clientY >= rect.top &&
      event.clientY <= rect.bottom
    );
  }

  document.addEventListener('pointerdown', function (e) {
    const closeButton = e.target.closest('.artx__search-main-content-close');

    if (closeButton) {
      e.preventDefault();
      e.stopImmediatePropagation();

      setTimeout(function () {
        closeAll();
      }, 0);

      return;
    }

    let clickedInsideMainContent = false;

    wrappers.forEach(function (wrapper) {
      const mainContent = wrapper.querySelector('.artx__search-main-content');

      if (isInsideBox(mainContent, e)) {
        clickedInsideMainContent = true;
      }
    });

    if (clickedInsideMainContent) return;

    const clickedInput = e.target.closest('.artx__search-wrapper input');

    if (clickedInput) {
      const wrapper = clickedInput.closest('.artx__search-wrapper');
      openWrapper(wrapper);
      return;
    }

    closeAll();
  }, true);

  document.addEventListener('click', function (e) {
    const closeButton = e.target.closest('.artx__search-main-content-close');

    if (closeButton) {
      e.preventDefault();
      e.stopImmediatePropagation();
      closeAll();
    }
  }, true);

  document.addEventListener('keydown', function (e) {
    if (e.key === 'Escape') closeAll();
  });
});
bars-line
.artx__second-header-menu {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  z-index: 9999;
  background: #000;
  transition: all 0.25s ease;
}

.artx__second-header-menu.is-sticky {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
window.addEventListener('load', function () {
  const header = document.querySelector('.artx__second-header-menu');
  if (!header) return;

  let placeholder = document.createElement('div');
  let headerOffset = 0;
  let headerHeight = 0;

  placeholder.style.display = 'none';
  header.parentNode.insertBefore(placeholder, header);

  function recalc() {
    header.classList.remove('is-sticky');
    placeholder.style.display = 'none';

    headerHeight = header.offsetHeight;
    headerOffset = header.getBoundingClientRect().top + window.scrollY;

    placeholder.style.height = headerHeight + 'px';

    onScroll();
  }

  function onScroll() {
    if (window.scrollY > headerOffset) {
      header.classList.add('is-sticky');
      placeholder.style.display = 'block';
    } else {
      header.classList.remove('is-sticky');
      placeholder.style.display = 'none';
    }
  }

  window.addEventListener('scroll', onScroll, { passive: true });
  window.addEventListener('resize', recalc);

  recalc();
});

Home Hydroponics