Untitled

 avatar
unknown
plain_text
3 years ago
14 kB
5
Indexable
(function () {
    try {
        /* main variables */
        var debug=0;
        var variation_name="";
 
        /* 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 waitForTrust(trigger, delayInterval, delayTimeout) {
            var interval=setInterval(function () {
                    if (window.Trustpilot && window.Trustpilot.loadFromElement) {
                        clearInterval(interval);
                        trigger();
                    }
                }
 
                , delayInterval);
 
            setTimeout(function () {
                    clearInterval(interval);
                }
 
                , delayTimeout);
        }
        function live(selector, event, callback, context) {
            // helper for enabling IE 8 event bindings
            function addEvent(el, type, handler) {
                if (el.attachEvent) el.attachEvent("on" + type, handler);
                else el.addEventListener(type, handler);
            }
            // matches polyfill
            this.Element &&
                (function(ElementPrototype) {
                    ElementPrototype.matches =
                        ElementPrototype.matches ||
                        ElementPrototype.matchesSelector ||
                        ElementPrototype.webkitMatchesSelector ||
                        ElementPrototype.msMatchesSelector ||
                        function(selector) {
                            var node = this,
                                nodes = (node.parentNode || node.document).querySelectorAll(
                                    selector
                                ),
                                i = -1;
                            while (nodes[++i] && nodes[i] != node);
                            return !!nodes[i];
                        };
                })(Element.prototype);
            // live binding helper using matchesSelector
            function live(selector, event, callback, context) {
                addEvent(context || document, event, function(e) {
                    var found,
                        el = e.target || e.srcElement;
                    while (
                        el &&
                        el.matches &&
                        el !== context &&
                        !(found = el.matches(selector))
                    )
                        el = el.parentElement;
                    if (found) callback.call(el, e);
                });
            }
            live(selector, event, callback, context);
        }
    
var popup=`<div id="eg-popup" class="eg-overlay"></div>
<div class="eg-popup">
    <a class="eg-close" >×</a>
    <p class="eg-popup-title">Please Select Your Size</p>
    <div class="eg-content">
        <button class="eg-add-to-cart" >Add to Cart</button>
    </div>
</div>`;
 
        function init() {
        var Products=document.querySelectorAll(".findify-components-common--grid >div");
        Products.forEach(function (e){
            // console.log(e.parentElement)
            if(!e.classList.contains("eg-cta-added")){
                e.classList.add("eg-cta-added");
                e.insertAdjacentHTML("beforeend","<button class='eg-quick-atc-cta'>Add to Cart</button >")
            }
             
        });
 
        live(".options a:not(.sold-out)", "click", function ($event) {
            $event.preventDefault();
            // event.stopImmediatePropagation();
            if(document.querySelector(".options a.active")){
                document.querySelector(".options a.active").classList.remove("active");
            
                
            }
            document.querySelector(".eg-add-to-cart").classList.add("active")
                    this.classList.add("active");     
          });
 
          live(".options a.sold-out", "click", function () {
            document.querySelector(".eg-add-to-cart").classList.remove("active");
          });
 
       
document.querySelectorAll('.eg-quick-atc-cta').forEach(item => {
    item.addEventListener('click', event => {
        // console.log("clicked")
        
       
                    var Url=item.parentElement.querySelector(".findify-components--cards--product").getAttribute("href");
 ajaxCall(Url)
    })
  })
  live('.eg-close, .eg-overlay', 'click', event => {
    document.querySelector(".eg-overlay").remove();
    document.querySelector(".eg-popup").remove();
 })
 
 live('.eg-add-to-cart', 'click', event => {
    if(document.querySelector(".pdp-fieldset")){
        // console.log("ATC clicked");
    var variant = $(".options a.active").attr("data-variant-id")
    Shopify.addItem(variant,'1',function(){
        // console.log('heelo'+ variant);
    });
    }else{
        var variantID= document.querySelector("#pdp--form > input[name=id]:nth-child(3)").value;
        Shopify.addItem(variantID,'1',function(){
            // console.log('heelo'+ variant);
        });
        
    }
    document.querySelector(".eg-close").click();
    setTimeout(function(){
        sideCartValue();
    },1000)
    
    document.querySelector(".cart__container a").click();
 })
 
           
        }
        function ajaxCall(url){
    
                var xmlHttp = new XMLHttpRequest();
                xmlHttp.onreadystatechange = function () {
                    if (xmlHttp.readyState == 4) {
                        if (xmlHttp.status == 200) {
                            var parser = new DOMParser();
                            var response = parser.parseFromString(xmlHttp.responseText, 'text/html');
                            var productSize = response.querySelector("#pdp--form-container").innerHTML;
                            if(!document.querySelector(".eg-overlay")){
                                document.querySelector("body").insertAdjacentHTML("beforeend", popup);
                            }
                            if(!response.querySelector(".options a")){
                                document.querySelector(".eg-add-to-cart").classList.add("eg-one-size")
                            }
                            if(!document.querySelector(".eg-content").classList.contains("eg-size-added")){
                                document.querySelector(".eg-content").classList.add("eg-size-added");
                                document.querySelector(".eg-add-to-cart").insertAdjacentHTML("beforebegin", productSize);
                            }
                                  
                        }
                    }
                };
                xmlHttp.open("GET", url, true);
                xmlHttp.send(null);
        }
 
        function sideCartValue(){
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                        var parser = new DOMParser();
                        var response = parser.parseFromString(xmlHttp.responseText, 'text/html');
                        var cartproduces= response.querySelector(".inline-cart__content-container").innerHTML;
                        var Itemsqnty =response.querySelector(".inline-cart__header").innerHTML;
                        var ItemSubTotal =response.querySelector(".inline-cart__total-amount-container").innerHTML;
                        var MainNavQty =response.querySelector(".inline-cart__header .inline-cart__total-count").innerText;
                        document.querySelector(".inline-cart__content-container").innerHTML= cartproduces;
                        document.querySelector(".inline-cart__header").innerHTML= Itemsqnty;
                        document.querySelector(".inline-cart__total-amount-container").innerHTML= ItemSubTotal;
                        document.querySelector(".cart__container > a > span > span").innerText= MainNavQty;
                        setTimeout(function(){
                            if(document.querySelector(".checkout-cta-section .inline-cart__btn").classList.contains("is-disabled")){
                                document.querySelector(".checkout-cta-section .inline-cart__btn").classList.remove("is-disabled")
                            }
                        },500)
                    } 
                }
            };
            xmlHttp.open("GET", "https://www.wickedclothes.com/cart?view=contents", true);
            xmlHttp.send(null);
        }
 
        function checkAjax(){
            // console.log("fired")
            const send = XMLHttpRequest.prototype.send;
            XMLHttpRequest.prototype.send = function() { 
                this.addEventListener('load', function() {
                    if(this.responseURL.indexOf('/cart.js?r') != -1){
                        waitForElement(".findify-components-common--grid >div", init, 50, 30000);    
                    }
                });
                return send.apply(this, arguments);
            };
          
     }
   
     live('.findify-components--button.findify-components--checkbox-facet__item, .findify-components--category-facet button, .findify-components-search--mobile-sorting__body button, .findify-components-search--desktop-facets__facet button, .findify-components--dropdown__open button', 'click', event => {
        checkAjax()
     })
     listener();
 
     function listener() {
         /* These are the modifications: */
         window.addEventListener("locationchange", function() {
             if (window.location.href.indexOf('offset=') > -1) {
                waitForElement(".findify-components-common--grid >div", init, 50, 40000);
             }
 
         });
         history.pushState = ((f) =>
             function pushState() {
                 var ret = f.apply(this, arguments);
                 window.dispatchEvent(new Event("pushstate"));
                 window.dispatchEvent(new Event("locationchange"));
                 return ret;
             })(history.pushState);
         history.replaceState = ((f) =>
             function replaceState() {
                 var ret = f.apply(this, arguments);
                 window.dispatchEvent(new Event("replacestate"));
                 window.dispatchEvent(new Event("locationchange"));
                 return ret;
             })(history.replaceState);
         window.addEventListener("popstate", () => {
             window.dispatchEvent(new Event("locationchange"));
         });
     }
 
        waitForElement(".findify-components-common--grid >div", init, 50, 40000);
    }
    catch (e) {
        if (debug) console.log(e, "error in Test" + variation_name);
    }
})();



<style>
.eg-quick-atc-cta {
        display: block;
        text-align: center;
        padding: 10px;
        border: 1px solid #000;
        margin-top: 20px;
}
.eg-overlay {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.7);
        transition: opacity 500ms;
        z-index: 8881;
}
.eg-popup {
        position: fixed;
        padding: 20px;
        background: #fcda4b;
        border-radius: 5px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 9999;
}
 
.eg-popup h2 {
        margin-top: 0;
        color: #333;
        font-family: Tahoma, Arial, sans-serif;
}
 
.eg-popup .eg-close {
        position: absolute;
        top: 1px;
        right: 15px;
        transition: all 200ms;
        font-size: 30px;
        font-weight: bold;
        text-decoration: none;
        color: #333;
}
 
.eg-popup .eg-close:hover {
        color: #06D85F;
}
 
.eg-popup .eg-content {
        max-height: 30%;
        overflow: auto;
}
 
@media screen and (max-width: 700px) {
        .eg-popup {
                width: 90%;
        }
}
 
.shopify-payment-button {
        display: none;
}
 
.options a svg {
        height: 40px;
        width: 40px;
        position: absolute;
        top: -5px;
        left: -7px;
        opacity: 0;
        display: none;
}
 
.options {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
}
 
.options a {
        display: flex;
        align-items: center;
        height: 45px;
        width: 45px;
        color: #000000;
        font-family: FuturaPT;
        font-size: 18px;
        font-weight: 500;
        line-height: 23px;
        position: relative;
        margin-bottom: 15px;
        border: 1px solid #000;
        justify-content: center;
        margin-right: 15px;
 
}
 
fieldset.pdp-fieldset {
        border: none;
}
 
.options a.active svg {
        opacity: 1;
}
 
.hidden.options-size {
        display: none;
}
 
.pdp--form__cta-container {
        display: none;
}
 
button.eg-add-to-cart {
        display: inline-block;
        width: 100%;
        padding: 12px;
        background: #000;
        color: #fff;
        font-weight: 700;
}
 
.eg-popup-title {
        font-family: "FuturaPT", sans-serif;
        text-align: center;
        font-size: 20px;
        margin-bottom: 15px;
}
 
button.eg-quick-atc-cta {
        display: block;
        width: 90%;
        color: #fff;
        font-weight: 700;
}
 
a.sold-out {
    opacity: 0.2;
    cursor: not-allowed;
}
 
.eg-add-to-cart {
        opacity: .6;
        pointer-events: none;
}
 
.active.eg-add-to-cart, .eg-one-size.eg-add-to-cart {
        opacity: 1;
        pointer-events: auto;
}
 
.findify-components--cards--product {
        padding-bottom: 15px !important;
}
.options a.active{
  background: #000;
    color: #fff;
}
@media screen and (min-width: 1366px) {
        .eg-popup {
                max-width: 540px;
                padding: 50px;
        }
        .options a{
                width: 95px;
        }
 
}
.shop_dynamic_form .pdp--form__cta-container {
    display: none;
}
</style>
Editor is loading...