Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.4 kB
3
Indexable
Never
(function () {
  try {
    /* main variables */
    var debug = 0;
    var variation_name = "";
    var $;
    /* all Pure helper functions */

    function waitForElement(selector, trigger, delayInterval, delayTimeout) {
      var interval = setInterval(function () {
        if (
          document &&
          document.querySelector(selector) &&
          document.querySelectorAll(selector).length > 0
        ) {
          clearInterval(interval);
          trigger();
        }
      }, delayInterval);
      setTimeout(function () {
        clearInterval(interval);
      }, delayTimeout);
    }

    function init() {
      const cta = document.querySelector(".product-add-form");
      const ctaBottom = cta.offsetTop + cta.offsetHeight;
      if (!document.querySelector(".eg-product-name")) {
        cta.insertAdjacentHTML("afterbegin", `<div class="eg-product-name"></div>`);
        waitForElement(".product-sticky-addtocart__product-name", function () {
          document.querySelector(".eg-product-name").innerHTML = document.querySelector(".product-sticky-addtocart__product-name").innerHTML;
        }, 100, 15000);
      }
      window.addEventListener("scroll", () => {
        if (window.scrollY >= ctaBottom) {
          document.body.classList.add("eg-sticky");
        } else {
          document.body.classList.remove("eg-sticky");
        }
      });
    }

    if (window.innerWidth < 641) {
      waitForElement('.product-add-form  .box-tocart', init, 150, 25000);
    }
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();


@media screen and (max-width:640px) {
    html body.eg-sticky .product-add-form {
        position: fixed;
        top: 63px;
        border-radius: 0 !important;
        z-index: 9 !important;
        max-width: 100% !important;
        left: 0;
        right: 0;
        background: #fff;
        padding-left: 15px;
        padding-right: 15px;
    }

    html body.eg-sticky {
        padding-bottom: 21px !important;
    }

    .eg-product-name {
        font-family: 'Oswald', sans-serif;
        font-weight: 700;
        font-size: 1.8rem;
        text-align: center;
        padding-top: 1rem;
        padding-bottom: 0.5rem;
    }

    html body:not(.eg-sticky) .eg-product-name {
        display: none !important;
    }

    .page-wrapper>.page-bottom>.widget {
        isolation: isolate !important;
    }
}