fgc.otherpage--s.js 6.53 KB
function sendAjaxAddACTag(a) {
    jQuery.ajax({
        url: "/?action=" + a,
        type: "POST",
        success: function (a) {
        }
    })
}
jQuery(document).ready(function (a) {
    pathname = window.location.pathname, "/tracked-delivery/" === pathname && jQuery(".button.set-tracked-delivery").click(function () {
        addToCartLink = a("#add_to_cart_tracked").text(), jQuery.ajax({
            type: "POST",
            dataType: "html",
            url: "/tracked-delivery/?cancelsubscription=yes",
            success: function (a) {
                window.location = currentsite + addToCartLink.replace("tracked-delivery/", "")
            },
            error: function () {
            }
        })
    }), a(".page-template-our-drink").length > 0 && "undefined" != typeof a.cookie("message_free_sample_ac") && ($message_free_sample = a.cookie("message_free_sample_ac"), a("body article").prepend('<div id="message_free_sample">' + $message_free_sample + "</div>"), setTimeout(function () {
        a("#message_free_sample").animate({
            color: "#f8f7f6"
        }, 500)
    }, 1e5), a.removeCookie("message_free_sample_ac", {
        path: "/"
    })), a(".page-template-free-sample").length > 0 && (a("._form_element._field22 select").val("Website Landing Page"), a("body").on("click", "._submit", function () {
        $email = a('input[name="email"]').val(), $i = 0;
        var b = setInterval(function () {
            "" !== a("._form-thank-you").text() && (a("._form-thank-you").html(""), a.ajax({
                url: "/?action=getSuccessMessageFreeSampleForm&email=" + $email,
                type: "POST",
                success: function (b) {
                    location.href = "/our-drink/"
                }
            }), clearInterval(b)), $i++, $i > 1e3 && clearInterval(b)
        }, 100)
    })), a(".page-template-login_page").length > 0 && $isMobile && a('.tvbutton button[name="login"]').tap(function () {
        a("html, body").animate({
            scrollTop: 0
        }, "slow")
    }), jQuery("body.page-template-challenge_results").on("click", ".sd-content li .share-icon", function () {
//        sendAjaxAddACTag("eventClickToShareChallenge")
    }), a("body.home.page").length > 0 && setTimeout(function () {
        a(".branding-img-container  img").css("width", "60px")
    }, 3e3), a(".page-template-free-sample-survey").length > 0 && (a(".entry-header").prepend('<h5 class="shop-step-title">STEP 2 OF 3</h5>'), jQuery(".page-template-free-sample-survey #free-survey-container iframe").on("load", function () {
        jQuery("html, body").animate({
            scrollTop: 0
        }, "slow")
    })), a(".page-template-free-sample").length > 0 && (a(".entry-header").prepend('<h5 class="shop-step-title">STEP 3 OF 3</h5>'), a('input[name="loginemail"]').length > 0 && a('input[name="email"]').val(a('input[name="loginemail"]').val()), a('input[name="firstname"]').length > 0 && a('input[name="fullname"]').val(a('input[name="firstname"]').val())), a("#free-sample-page").length > 0 && (a('button[type="submit"]').click(function () {
        a("#free-sample-page").find("#checkout_loader_img").removeClass("hide"), a(".entry-content").css("opacity", "0.3")
    }), a("._field-wrapper").on("DOMNodeInserted", "._error", function () {
        a('input[type="text"]').hasClass("_has_error") && a("html, body").animate({
            scrollTop: a("input._has_error").eq(0).offset().top - 25
        }, "slow"), a("#free-sample-page").find("#checkout_loader_img").addClass("hide"), a(".entry-content").css("opacity", "1")
    }))
    
    
    /*add by fgc*/
    function getCookie(name) {
    var matches = document.cookie.match(new RegExp(
            "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
            ));
    return matches ? decodeURIComponent(matches[1]) : undefined;
}

function setCookie(name, value, options) {
    options = options || {};

    var expires = options.expires;

    if (typeof expires == "number" && expires) {
        var d = new Date();
        d.setTime(d.getTime() + expires * 1000);
        expires = options.expires = d;
    }
    if (expires && expires.toUTCString) {
        options.expires = expires.toUTCString();
    }

    value = encodeURIComponent(value);
    var updatedCookie = name + "=" + value;

    for (var propName in options) {
        updatedCookie += "; " + propName;
        var propValue = options[propName];
        if (propValue !== true) {
            updatedCookie += "=" + propValue;
        }
    }

    document.cookie = updatedCookie;
}

function deleteCookie(name) {
    setCookie(name, "", {expires: -1})
}
//var l = window.location;
//var base_url = l.protocol + "//" + l.host;
//    console.log(base_url);
//    if(a('.page-template-free-sample-survey-form-php #gform_submit_button_2').length>0){
//                     // console.log(getCookie('tvnewsletterSubscribe'))
//     a('.page-template-free-sample-survey-form-php').on("click",'#gform_submit_button_2',function(e){  
//                        console.log("fgc"+getCookie('free_sample_survey_form'))
//            if(typeof getCookie('free_sample_survey_form') !==  "undefined" )
//            {  
//                        //  alert("ko dc submit")
//			console.log("da co cookies");
//  e.preventDefault();
//  window.location.href =  base_url+'/thanks/';
//            } else{ 
//                //chua co cookies
//                var days = 3650; // emulate never expire
//              setCookie('free_sample_survey_form', 'yes', {
//                expires: days * 86400,
//                path: '/'
//            });
//        }//endif
//      });
//    }

var l = window.location;
var base_url = l.protocol + "//" + l.host;
    //console.log(base_url);
    if(a('.page-template-free-sample-survey-form-php #gform_submit_button_2').length>0){
                     console.log(getCookie('free_sample_survey_form'))
        a('.page-template-free-sample-survey-form-php').on("click",'#gform_submit_button_2',function(e){  
                        console.log("fgc"+getCookie('free_sample_survey_form'));
            if(typeof getCookie('free_sample_survey_form') !==  "undefined" ){  
                e.preventDefault();
         //  alert("ko dc submit")
			//a.cookie
	// deleteCookie('free_sample_survey_form');
         window.location.href =  base_url+'/thanks/';
            } else{ 
                
                var days = 3650; // emulate never expire
             setCookie('free_sample_survey_form', 'yes', {
                expires: days * 86400,
                path: '/'
            });
           
             }
        });
    }


});