Untitled
unknown
plain_text
a year ago
2.6 kB
6
Indexable
(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);
}
const addToCart =
`<div class="eg-cta">
<div class="eg-cta-bg">
<div class="eg-sticky-cta">Add to cart</div>
</div>
</div>`;
function init() {
document.body.classList.add('PP-0041');
document.body.insertAdjacentHTML('beforeend', addToCart);
var stickyCTA = document.querySelector('.eg-sticky-cta');
var realAddToCartButton = document.querySelector('.product-block .add-to-cart');
stickyCTA.addEventListener('click', function () {
if (realAddToCartButton) {
realAddToCartButton.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
});
waitForElement('.product-block [data-imageuploader-btn-clone] + .add-to-cart', function () {
let intv = setInterval(() => {
const addToCartButton = document.querySelector(".product-block [data-imageuploader-btn-clone] + .add-to-cart");
if (addToCartButton && addToCartButton.style.display === "none") {
addToCartButton.removeAttribute("style");
}
}, 100);
setTimeout(() => {
clearInterval(intv);
}, 3000);
}, 50, 15000);
function toggleStickyCTA() {
if (realAddToCartButton) {
var rect = realAddToCartButton.getBoundingClientRect();
var isVisible = rect.top >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight);
if (isVisible) {
stickyCTA.classList.add('hidden');
} else {
stickyCTA.classList.remove('hidden');
}
}
}
toggleStickyCTA();
window.addEventListener('scroll', toggleStickyCTA);
}
if (window.location.href.indexOf('/products/') !== -1) {
waitForElement('.product-block .add-to-cart', init, 50, 15000);
}
} catch (e) {
if (debug) console.log(e, "error in Test" + variation_name);
}
})();
Editor is loading...
Leave a Comment