window.addEventListener('wixDevelopersAnalyticsReady', registerListenerPopifyLive);
if (window.location.href.indexOf('ifaas.co') >= 0 || window.location.href.indexOf('knelahogar.com') >= 0)
{
try
{
registerListenerPopifyLive();
}
catch(e)
{
console.log(e)
}
}
else
{
setTimeout(function(){
if(typeof(window.PopifyLoaded) == "undefined")
{
console.log("popify not loaded");
registerListenerPopifyLive();
setTimeout(function(){window.wixDevelopersAnalytics.triggerEvent('PageView', {eventName: 'eventName'}
)},1000)
}
},2000);
}
if (!window.jQuery)
{
var script = document.createElement('script');
document.head.appendChild(script);
script.type = 'text/javascript';
script.src = "//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js";
}
function registerListenerPopifyLive()
{
window.wixDevelopersAnalytics.register("179f2519-5838-4797-b9ad-ab27cf6c3e14", (eventName, eventParams) =>
{
console.log('heree');
if (eventName == "AddToCart")
{
console.log('popify live add cart event');
trackAddToCartButton(eventParams.sku, eventParams.quantity, eventParams.id, eventParams.cartId);
console.log('popify abandoned carts event');
trackAbandonedCartsRecovery(eventParams.sku, eventParams.quantity, eventParams.id);
}
else if (eventName == "Purchase")
{
console.log('popify thank you page');
trackThankyouPage(eventParams.contents);
}
else if (eventName == "RemoveFromCart")
{
console.log('popify remove from cart');
removeProductFromCart(eventParams.id);
}
else if (eventName == "PageView")
{
console.log("popify live page view", eventName, eventParams);
if(typeof(window.PopifyLoaded) == "undefined" && !window.PopifyLoaded)
{
loadPopifyScript();
window.PopifyLoaded = true;
return;
}
else if(window.location.href.indexOf("trinityeliteeducation") > -1 && typeof(window.PopifyLoaded) != "undefined" && window.PopifyLoaded)
{
if(window.location.href == "https://www.trinityeliteeducation.com/" || window.location.href == "https://www.trinityeliteeducation.com/ggsbookclub" || window.location.href == "https://www.trinityeliteeducation.com/book-club-box" || window.location.href == "https://www.trinityeliteeducation.com/shop")
{
loadPopifyScript();
}
}
else if(typeof(window.PopifyLoaded) != "undefined" && window.PopifyLoaded)
{
loadPopifyScript();
return;
}
}
else
{
console.log("popify live wix head", eventName, eventParams);
}
});
}
window.popifyApiDomain = "https://app.popify.app";
var ApplicationServerPublicKey = 'BMI1J76xxU1JRxm6j3hBU0LUFN6uYB8gj8BWi0RtAUt-0m3ezYlgv7imp6cinQ8ezGPsqfOg50MsnFFIdud5p5I';
IsSubscribed = false;
SwRegistration = null;
Registration_id = null;
devVerified = false;
if (!window.d3)
{
// jQuery('head').append('');
var script = document.createElement('script');
document.head.appendChild(script);
script.type = 'text/javascript';
script.src = window.popifyApiDomain+"/assets/js/d3.v3.min.js";
}
if (!window.flipTimer)
{
// jQuery('head').append('');
var script = document.createElement('script');
document.head.appendChild(script);
script.type = 'text/javascript';
script.src = window.popifyApiDomain+"/assets/js/jquery.flipTimer.js";
}
function loadPopifyScript()
{
window.PopifyNotifications = [];
window.popifyTimeout = [];
$('div.popify-preview').remove();
(function($)
{
$(document).ready(
function()
{
setTimeout(addCssFiles(),1000);
}
);
function trackPage()
{
var tracking_id = "";
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
if(getCookie("popify_track"))
{
tracking_id = getCookie("popify_track");
}
else
{
tracking_id = generateKey();
setCookie("popify_track", tracking_id,30,window.location.hostname);
}
jQuery.ajax({
url: window.popifyApiDomain+"/Api/analyticsTrack?api_key="+api_key+"&id="+tracking_id,
type: "GET",
crossDomain: true,
dataType: "json",
success: function (response) {
if (window.location.href.indexOf('ifaas.co') >= 0)
{
setTimeout(function() { loadNotifications(); }, 3000);
}
else
{
loadNotifications();
}
},
error: function (xhr, status) {
console.log("Tracking Error");
}
});
}
function trackPageVisitors()
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
if (!getCookie("popify_visitor"))
{
setCookie("popify_visitor","true",0,window.location.hostname);
$.ajax({
url: window.popifyApiDomain+"/Api/analyticsTrackVisitors?api_key="+api_key,
type: "GET",
crossDomain: true,
dataType: "json",
success: function (response) { },
error: function (xhr, status) {
console.log("Tracking Error");
}
});
}
}
function addDiscountCodeToCheckOut()
{
var discount_code = getCookie("popify_discount_code");
if(discount_code)
{
if(window.location.pathname == "/cart")
{
jQuery("form").each(
function()
{
if(jQuery(this).attr("action") == "/cart")
{
var action = jQuery(this).attr("action");
action += "?discount="+discount_code;
jQuery(this).attr("action", action);
return;
}
}
);
}
}
}
function SetDiscountCode(code)
{
setCookie("popify_discount_code", code, 0, window.location.hostname)
}
function loadNotifications()
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
if(getCookie("popify_close_site_notifications") && getCookie("popify_close_site_notifications") == "yes")
{
console.log("Notifications disabled for site");
return false;
}
jQuery.ajax({
url: window.popifyApiDomain+"/Api/getNotifications?api_key="+api_key+"&location="+encodeURI(current_link)+"&platform=wix",
type: "GET",
crossDomain: true,
dataType: "json",
xhrFields: { withCredentials: true },
success: function (response)
{
if(response.notifications && response.notifications.length > 0)
{
if(window.PopifyNotifications.length < 1)
{
window.PopifyNotifications = response.notifications;
window.PopifySettings = response.settings;
showNotifications();
}
}
},
error: function (xhr, status) {
console.log("Load Error");
}
});
}
function setCookie(cname, cvalue, exdays, domain) {
var d = new Date();
if(exdays >= 1)
{
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;domain="+domain+";SameSite=Lax";
}
else
{
document.cookie = cname + "=" + cvalue + ";expires=0;path=/;domain="+domain+";SameSite=Lax";
}
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i ');
jQuery('head').append('');
if(jQuery("head link[href*='fontawsome']").length < 1)
{
// var link = '';
var link = '';
jQuery("head").append(link);
}
var css_style = "@media (max-width: 800px) { .popify-preview.popify-preview-new.popify-preview-bottom { zoom: .85 !important; top: 93% !important;} .popify-preview { z-index: 999999 !important; } }";
jQuery("head").append('');
}
if(window.location.host.includes("vcinnamongirl"))
{
var css = '@media (max-width: 800px) { .popify-toast:not(.popify-new-popup-design) { zoom: .8 !important; width: 289px !important; } } .popify-rtl-support.popifyOrders .popify-close-notification-icon i.fa-times {margin-right: 0px !important;}';
$("head").append('');
}
if(window.location.host.includes("swally.com"))
{
var css = '@media (max-width: 800px) { .popify-toast:not(.popify-new-popup-design) { zoom: .8 !important; width: 289px !important; } }';
$("head").append('');
}
if(window.location.host.includes("thefoxandfrills.com"))
{
var css = '@media (max-width: 800px) { .popify-preview .popify-toast { zoom: .8 !important; margin-bottom: -45px !important; } }';
$("head").append('');
}
if(window.location.host.indexOf("thefeelbar.com") > -1)
{
$("head").append('');
}
if(window.location.host.indexOf("autumnskyeproductions.com") > -1)
{
$("head").append('');
}
if (window.location.href.indexOf('sewinloveballito.co.za') >= 0)
{
$("head").append('');
}
if(window.PopifyNotifications[i].animation && window.PopifyNotifications[i].animation == "fade")
{
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-fade");
}
if(i != 0 && window.PopifyNotifications[i].animation && window.PopifyNotifications[i].animation == "fade")
{
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-hide");
}
if(window.PopifySettings.notification_hover_effect == "yes")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").addClass("popify-hover");
}
var notification_height = jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").height()+40;
if(mobilecheck() && !jQuery("#"+window.PopifyNotifications[i].key).hasClass("popify-preview-new"))
{
if(window.PopifyNotifications[i].mobile_position == "bottom")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("bottom","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom-center");
}
if(window.PopifyNotifications[i].mobile_position == "top")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("top","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top-center");
}
}
else if((window.location.host.includes("vcinnamongirl") || window.location.host.includes("m2mcycling") || window.location.host.includes("lightclubsg") || window.location.host.includes("theincrediblek9") || window.location.host.includes("greendwelling")) && mobilecheck())
{
// Comments go here
if(window.PopifyNotifications[i].mobile_position == "bottom")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("bottom","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom-center");
}
if(window.PopifyNotifications[i].mobile_position == "top")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("top","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top-center");
}
}
else
{
if(window.PopifyNotifications[i].position == "bottom_left")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("bottom","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-left");
}
if(window.PopifyNotifications[i].position == "bottom_right")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("bottom","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-right");
}
if(window.PopifyNotifications[i].position == "top_left")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("top","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-left");
}
if(window.PopifyNotifications[i].position == "top_right")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("top","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-right");
}
if(window.PopifyNotifications[i].position == "top_center")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("top","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-top-center");
}
if(window.PopifyNotifications[i].position == "bottom_center")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast").css("bottom","-"+notification_height+"px");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom");
jQuery("#"+window.PopifyNotifications[i].key).addClass("popify-preview-bottom-center");
}
}
jQuery("#"+window.PopifyNotifications[i].key+" .popify-close-notification-icon").click(
function(event)
{
event.stopPropagation();
var notification_index = getArrayKey(window.PopifyNotifications, jQuery(this).parents(".popify-preview").attr("id").replace("#",""));
if (window.PopifyNotifications[notification_index])
{
hideNotification(window.PopifyNotifications[notification_index],"close");
}
else
{
jQuery(this).parent().parent().removeClass("show");
}
}
);
if(jQuery("#"+window.PopifyNotifications[i].key+" .call_to_action_container a").length > 0)
{
jQuery("#"+window.PopifyNotifications[i].key+" .call_to_action_container a").click(
function()
{
addNotificationAnalytics(jQuery(this).parents(".popify-preview").attr("id").replace("#",""),"click");
}
);
}
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast-body").mouseenter(
function()
{
addNotificationAnalytics(jQuery(this).parents(".popify-preview").attr("id").replace("#",""),"hover");
}
);
if(window.PopifyNotifications[i].notification_type == "discount_code")
{
if(window.PopifyNotifications[i].discount_code_application && window.PopifyNotifications[i].discount_code_application == "auto")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast-body .call_to_action_container a").click({notification:window.PopifyNotifications[i]},
function(event)
{
event.preventDefault();
jQuery("#"+event.data.notification.key+" .popify-progress").show();
jQuery("#"+event.data.notification.key+" .popify-progress-value").addClass("popifyload");
if(event.data.notification.discount_code_notification_hide == "on")
{
setCookie("popify_hide_notification_"+event.data.notification.key, "true", "2", window.location.hostname);
}
SetDiscountCode(event.data.notification.discount_code_code);
jQuery("#"+event.data.notification.key+" .popify-toast-body .call_to_action_container").html(event.data.notification.discount_code_success_message);
setTimeout(function(){window.location.href=event.data.notification.call_to_link_url;},5000);
}
);
}
}
if(window.PopifyNotifications[i].clickable_notification == "on")
{
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast-body").click(
function()
{
var link = jQuery(this).parents(".popify-preview").attr("data-target-link");
var target_type = jQuery(this).parents(".popify-preview").attr("data-target-type");
window.open(link, (target_type.length > 0) ? '_blank' : '_self');
addNotificationAnalytics(jQuery(this).parents(".popify-preview").attr("id").replace("#",""),"click");
}
);
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast-header").click(
function()
{
var link = jQuery(this).parents(".popify-preview").attr("data-target-link");
var target_type = jQuery(this).parents(".popify-preview").attr("data-target-type");
window.open(link, (target_type.length > 0) ? '_blank' : '_self');
addNotificationAnalytics(jQuery(this).parents(".popify-preview").attr("id").replace("#",""),"click");
}
);
jQuery("#"+window.PopifyNotifications[i].key+" .popify-toast-left").click(
function()
{
var link = jQuery(this).parents(".popify-preview").attr("data-target-link");
var target_type = jQuery(this).parents(".popify-preview").attr("data-target-type");
window.open(link, (target_type.length > 0) ? '_blank' : '_self');
addNotificationAnalytics(jQuery(this).parents(".popify-preview").attr("id").replace("#",""),"click");
}
);
}
}
}
}
}
}
startNotificationDisplay(show_index_start);
}
function startNotificationDisplay(notificaiton_index = 0)
{
if(window.PopifyNotifications.length > 0)
{
if (window.PopifySettings.loop_notifications == "yes" && window.PopifySettings.loop_notifications_type == "number")
{
var loop_notifications_cnt = getCookie("loop_notifications_cnt");
if (!loop_notifications_cnt)
{
setCookie("loop_notifications_cnt", "1", 0,window.location.hostname);
}
}
if(window.PopifySettings.first_notification_delay_type && window.PopifySettings.first_notification_delay_type == "fixed")
{
var timeout_nr = parseInt(window.PopifySettings.first_notification_delay) * 1000+1000;
setTimeout(displayNotification,timeout_nr,window.PopifyNotifications[notificaiton_index]);
}
else if(window.PopifySettings.first_notification_delay_type && window.PopifySettings.first_notification_delay_type == "random")
{
var timeout_nr = getRndInteger(parseInt(window.PopifySettings.first_notification_delay.min), parseInt(window.PopifySettings.first_notification_delay.max))* 1000+1000;
setTimeout(displayNotification,timeout_nr,window.PopifyNotifications[notificaiton_index]);
}
else
{
setTimeout(displayNotification,1000,window.PopifyNotifications[notificaiton_indexnotificaiton_index]);
}
}
}
function displayNotification(notification_data)
{
var show_nr = getCookie("show_"+notification_data.key);
if(show_nr)
{
show_nr++;
setCookie("show_"+notification_data.key, show_nr, 0,window.location.hostname);
}
else
{
setCookie("show_"+notification_data.key, "1", 0,window.location.hostname);
}
if(jQuery("#"+notification_data.key).hasClass("popify-preview-hide"))
{
jQuery("#"+notification_data.key).removeClass("popify-preview-hide");
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index--;
jQuery("#"+window.PopifyNotifications[notification_index].key).addClass("popify-preview-hide");
setTimeout(function(){
jQuery("#"+notification_data.key+" .popify-toast").addClass("fade");
jQuery("#"+notification_data.key+" .popify-toast").addClass("show");
},500,notification_data);
}
else
{
jQuery("#"+notification_data.key+" .popify-toast").addClass("fade");
jQuery("#"+notification_data.key+" .popify-toast").addClass("show");
}
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var track = getCookie("popify_track");
console.log(notification_data);
jQuery.ajax({
url: window.popifyApiDomain+"/Api/notificationShowTrack?api_key="+api_key+"¬ification="+notification_data.key+"&track="+track,
type: "GET",
crossDomain: true,
dataType: "json",
success: function (response)
{
},
error: function (xhr, status) {
console.log("Notification review load Error");
}
});
if(notification_data.notification_type == "reviews")
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
if(notification_index >= 0)
{
var notification_cookie = getCookie("counter"+notification_data.key);
if(!notification_cookie)
{
setCookie("counter"+notification_data.key, 1, 1,window.location.hostname);
}
var notification_reviews_cookie = getCookie("popify_displayed_reviews");
if(!notification_reviews_cookie)
{
setCookie("popify_displayed_reviews", 1, 1,window.location.hostname);
}
loadNextReview(notification_index,notification_data.key, notification_data.max_nr_of_reviews);
}
var timeout_value = 1000* notification_data.display_time;
window.popifyTimeout.push(setTimeout(hideNotification,timeout_value,notification_data,""));
}
else if(notification_data.notification_type == "customers_activity" && (notification_data.counter_type == "orders" || notification_data.counter_type == "cart"))
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
if(notification_index >= 0)
{
var notification_cookie = getCookie("counter"+notification_data.key);
if(!notification_cookie)
{
setCookie("counter"+notification_data.key, 1, 1,window.location.hostname);
}
loadNextPurchase(notification_index,notification_data.key, notification_data.max_nr_of_purchases);
}
var timeout_value = 1000* notification_data.display_time;
window.popifyTimeout.push(setTimeout(hideNotification,timeout_value,notification_data,""));
}
else if(notification_data.notification_type == "product_purchases_counter")
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
if(notification_index >= 0)
{
var notification_cookie = getCookie("counter"+notification_data.key);
if(!notification_cookie)
{
setCookie("counter"+notification_data.key, 1, 1,window.location.hostname);
}
loadNextProductPurchases(notification_index,notification_data.key);
}
var timeout_value = 1000* notification_data.display_time;
window.popifyTimeout.push(setTimeout(hideNotification,timeout_value,notification_data,""));
}
else if(notification_data.notification_type == "recent_wix_activity")
{
var notification_index = getArrayKey(window.PopifyNotifications,notification_data.key);
if(notification_index >= 0)
{
var notification_cookie = getCookie("counter"+notification_data.key);
if(!notification_cookie)
{
setCookie("counter"+notification_data.key, 1, 1,window.location.hostname);
}
loadNextRecentWixActivity(notification_index,notification_data.key);
}
var timeout_value = 1000* notification_data.display_time;
window.popifyTimeout.push(setTimeout(hideNotification,timeout_value,notification_data,""));
}
else if(notification_data.auto_hide)
{
window.popifyTimeout.push(setTimeout(hideNotification,notification_data.auto_hide,notification_data,""));
}
}
function hideNotification(notification_data,action_source)
{
console.log(action_source);
var timeout_nr = 0;
clearTimeouts();
if(window.PopifySettings.notification_delay_type && window.PopifySettings.notification_delay_type == "fixed")
{
timeout_nr = parseInt(window.PopifySettings.notification_delay) * 1000+1000;
}
else if(window.PopifySettings.notification_delay_type && window.PopifySettings.notification_delay_type == "random")
{
timeout_nr = getRndInteger(parseInt(window.PopifySettings.notification_delay.min), parseInt(window.PopifySettings.notification_delay.max))* 1000+1000;
}
if (notification_data.key)
{
jQuery("#"+notification_data.key+" .popify-toast").removeClass("show");
}
if(window.location.href.indexOf("trinityeliteeducation") > -1 && (window.location.href != "https://www.trinityeliteeducation.com/" && window.location.href != "https://www.trinityeliteeducation.com/ggsbookclub" && window.location.href != "https://www.trinityeliteeducation.com/book-club-box" && window.location.href != "https://www.trinityeliteeducation.com/shop"))
{
jQuery("#"+notification_data.key).addClass("popify-preview-hide");
return false;
}
if (typeof(window.PopifySettings.close_site_notifications) !== "undefined" && window.PopifySettings.close_site_notifications == "yes" && action_source == "close")
{
jQuery("#"+notification_data.key).addClass("popify-preview-hide");
setCookie("popify_close_site_notifications", "yes", 30, window.location.hostname);
return false;
}
if(jQuery("#"+notification_data.key+" .popify-close-notification-icon").attr("data-close-all") && jQuery("#"+notification_data.key+" .popify-close-notification-icon").attr("data-close-all") == "yes" && action_source == "close")
{
jQuery("#"+notification_data.key).addClass("popify-preview-hide");
return false;
}
if(notification_data.notification_type == "reviews" && action_source == "close")
{
notification_data.nextReview = "";
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
return false;
}
if(notification_data.notification_type == "customers_activity" && (notification_data.counter_type == "orders" || notification_data.counter_type == "cart") && action_source == "close")
{
notification_data.nextPurchase = "";
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
return false;
}
if(notification_data.notification_type == "product_purchases_counter" && action_source == "close")
{
notification_data.nextProductPurchase = "";
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
return false;
}
if(notification_data.notification_type == "recent_wix_activity" && action_source == "close")
{
notification_data.nextRecentWixActivity = "";
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
return false;
}
if(action_source == "close")
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
return false;
}
if(notification_data.notification_type == "reviews")
{
if(notification_data.nextReview)
{
setTimeout(function(){
jQuery("#"+notification_data.key+" .popify-toast-header").html(notification_data.nextReview.header);
jQuery("#"+notification_data.key+" .popify-toast-body").html(notification_data.nextReview.body);
jQuery("#"+notification_data.key+" .popify-toast-footer").html(notification_data.nextReview.footer);
jQuery("#"+notification_data.key+" .popify-toast-left").html(notification_data.nextReview.img);
if(notification_data.clickable_notification == "on")
{
jQuery("#"+notification_data.key).attr("data-target-link", notification_data.nextReview.product_link);
}
jQuery("#"+notification_data.key+" .popify-close-notification-icon").click(
function(event)
{
event.stopPropagation();
var notification_index = getArrayKey(window.PopifyNotifications, notification_data.key);
if (window.PopifyNotifications[notification_index])
{
hideNotification(window.PopifyNotifications[notification_index],"close");
}
else
{
jQuery(this).parent().parent().removeClass("show");
}
}
);
},1500,notification_data);
window.popifyTimeout.push(setTimeout(displayNotification,2500+timeout_nr,notification_data));
}
else
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
}
}
else if(notification_data.notification_type == "customers_activity" && (notification_data.counter_type == "orders" || notification_data.counter_type == "cart"))
{
if(notification_data.nextPurchase && notification_data.nextPurchase.order_key)
{
setTimeout(function(){
jQuery("#"+notification_data.key+" .popify-toast-header").html(notification_data.nextPurchase.header);
jQuery("#"+notification_data.key+" .popify-toast-body").html(notification_data.nextPurchase.body);
jQuery("#"+notification_data.key+" .popify-toast-left").html(notification_data.nextPurchase.img);
if(notification_data.clickable_notification == "on")
{
jQuery("#"+notification_data.key).attr("data-target-link", notification_data.nextPurchase.product_link);
}
jQuery("#"+notification_data.key+" .popify-close-notification-icon").click(
function(event)
{
event.stopPropagation();
var notification_index = getArrayKey(window.PopifyNotifications, notification_data.key);
if (window.PopifyNotifications[notification_index])
{
hideNotification(window.PopifyNotifications[notification_index],"close");
}
else
{
jQuery(this).parent().parent().removeClass("show");
}
}
);
},1500,notification_data);
window.popifyTimeout.push(setTimeout(displayNotification,2500+timeout_nr,notification_data));
}
else
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
var current_notification_index = notification_index;
notification_index++;
var next_notification_index = notification_index;
notification_index = LoopNotificationIndex(notification_index);
if (notification_data.nextPurchase == "" && window.PopifySettings.loop_notifications == "yes" && next_notification_index != notification_index && current_notification_index == notification_index)
{
devdeleteCookie("show_"+notification_data.key);
devdeleteCookie("counter"+notification_data.key);
}
else
{
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
}
}
}
else if(notification_data.notification_type == "product_purchases_counter")
{
if(notification_data.nextProductPurchase)
{
setTimeout(function()
{
jQuery("#"+notification_data.key+" .popify-toast-body").html(notification_data.nextProductPurchase.body);
jQuery("#"+notification_data.key+" .popify-toast-left").html(notification_data.nextProductPurchase.img);
if(notification_data.clickable_notification == "on")
{
jQuery("#"+notification_data.key).attr("data-target-link", notification_data.nextProductPurchase.product_link);
}
jQuery("#"+notification_data.key+" .popify-close-notification-icon").click(
function(event)
{
event.stopPropagation();
var notification_index = getArrayKey(window.PopifyNotifications, notification_data.key);
if (window.PopifyNotifications[notification_index])
{
hideNotification(window.PopifyNotifications[notification_index],"close");
}
else
{
jQuery(this).parent().parent().removeClass("show");
}
}
);
},1500,notification_data);
window.popifyTimeout.push(setTimeout(displayNotification,2500+timeout_nr,notification_data));
}
else
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
}
}
else if(notification_data.notification_type == "recent_wix_activity")
{
if(notification_data.nextRecentWixActivity)
{
setTimeout(function()
{
jQuery("#"+notification_data.key+" .popify-toast-header").html(notification_data.nextRecentWixActivity.header);
jQuery("#"+notification_data.key+" .popify-toast-body").html(notification_data.nextRecentWixActivity.body);
jQuery("#"+notification_data.key+" .popify-toast-left").html(notification_data.nextRecentWixActivity.img);
jQuery("#"+notification_data.key+" .popify-close-notification-icon").click(
function(event)
{
event.stopPropagation();
var notification_index = getArrayKey(window.PopifyNotifications, notification_data.key);
if (window.PopifyNotifications[notification_index])
{
hideNotification(window.PopifyNotifications[notification_index],"close");
}
else
{
jQuery(this).parent().parent().removeClass("show");
}
}
);
},1500,notification_data);
window.popifyTimeout.push(setTimeout(displayNotification,2500+timeout_nr,notification_data));
}
else
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
setCookie("counter"+notification_data.key, 0, 0,window.location.hostname);
}
}
else
{
var notification_index =getArrayKey(window.PopifyNotifications,notification_data.key);
notification_index++;
notification_index = LoopNotificationIndex(notification_index);
if(window.PopifyNotifications[notification_index])
{
window.popifyTimeout.push(setTimeout(displayNotification,1000+timeout_nr,window.PopifyNotifications[notification_index]));
}
}
}
function LoopNotificationIndex(notification_index)
{
if (window.PopifySettings.loop_notifications == "yes")
{
var condition = true;
if (window.PopifySettings.loop_notifications_type == "number")
{
var loop_notifications_cnt = getCookie("loop_notifications_cnt");
condition = (loop_notifications_cnt < window.PopifySettings.loop_notifications_cnt);
}
if (!window.PopifyNotifications[notification_index] && notification_index >= window.PopifyNotifications.length - 1 && condition)
{
notification_index = 0;
if (window.PopifySettings.loop_notifications_type == "number")
{
var loop_notifications_cnt = getCookie("loop_notifications_cnt");
loop_notifications_cnt++;
setCookie("loop_notifications_cnt", loop_notifications_cnt, 0,window.location.hostname);
}
}
}
return notification_index;
}
function loadNextReview(array_key,notification_key, notification_limit)
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var notification_cookie = parseInt(getCookie("counter"+notification_key));
var notification_reviews_cookie = parseInt(getCookie("popify_displayed_reviews"));
if (parseInt(notification_cookie) < parseInt(notification_limit)-1 && parseInt(notification_reviews_cookie) < parseInt(notification_limit))
{
jQuery.ajax({
url: window.popifyApiDomain+"/Api/getNotificationNextReview?api_key="+api_key+"¬ification="+notification_key+"&displayed_reviews="+encodeURI(JSON.stringify(window.PopifyNotifications[array_key].displayed_reviews)),
type: "GET",
crossDomain: true,
dataType: "json",
success: function (response)
{
if(response.success == 1)
{
window.PopifyNotifications[array_key].nextReview = response.notification;
if(window.PopifyNotifications[array_key].displayed_reviews.length< window.PopifyNotifications[array_key].max_displayed_reviews)
{
window.PopifyNotifications[array_key].displayed_reviews.push(response.notification.review_key);
}
else
{
window.PopifyNotifications[array_key].displayed_reviews.shift();
window.PopifyNotifications[array_key].displayed_reviews.push(response.notification.review_key);
}
notification_cookie++;
setCookie("counter"+window.PopifyNotifications[array_key].key, notification_cookie, 1,window.location.hostname);
}
},
error: function (xhr, status) {
console.log("Notification review load Error");
}
});
}
else
{
window.PopifyNotifications[array_key].nextReview = "";
}
}
function loadNextPurchase(array_key,notification_key, notification_limit)
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var notification_cookie = parseInt(getCookie("counter"+notification_key));
if (parseInt(notification_cookie) < parseInt(notification_limit) && window.PopifyNotifications[array_key] && window.PopifyNotifications[array_key].displayed_orders)
{
var displayed_orders = [];
if (window.PopifyNotifications[array_key] && window.PopifyNotifications[array_key].displayed_orders)
{
displayed_orders = window.PopifyNotifications[array_key].displayed_orders;
}
jQuery.ajax({
url: window.popifyApiDomain+"/Api/getNotificationNextPurchase?api_key="+api_key+"¬ification="+notification_key+"&counter="+notification_cookie+"&displayed_orders="+encodeURI(JSON.stringify(displayed_orders)),
type: "GET",
crossDomain: true,
dataType: "json",
success: function (response)
{
if(response.success == 1)
{
if (window.PopifyNotifications[array_key] && typeof(window.PopifyNotifications[array_key].hide_on_target_url) !== "undefined" && window.PopifyNotifications[array_key].hide_on_target_url == "on")
{
if (window.location.href == response.purchase.product_link)
{
if (window.PopifyNotifications[array_key] && !window.PopifyNotifications[array_key].displayed_orders)
{
window.PopifyNotifications[array_key].displayed_orders = [];
}
window.PopifyNotifications[array_key].displayed_orders.push(notification_key);
loadNextPurchase(array_key,notification_key, notification_limit);
return false;
}
}
window.PopifyNotifications[array_key].nextPurchase = response.purchase;
if(window.PopifyNotifications[array_key].displayed_orders.length< window.PopifyNotifications[array_key].max_displayed_orders)
{
window.PopifyNotifications[array_key].displayed_orders.push(response.purchase.order_key);
}
else
{
window.PopifyNotifications[array_key].displayed_orders.shift();
window.PopifyNotifications[array_key].displayed_orders.push(response.purchase.order_key);
}
notification_cookie++;
setCookie("counter"+window.PopifyNotifications[array_key].key, notification_cookie, 1,window.location.hostname);
}
else
{
window.PopifyNotifications[array_key].nextPurchase = "";
setCookie("counter"+window.PopifyNotifications[array_key].key, 0, 0,window.location.hostname);
}
},
error: function (xhr, status) {
console.log("Notification purchase load Error");
}
});
}
else
{
if (window.PopifyNotifications[array_key] && window.PopifyNotifications[array_key].nextPurchase)
{
window.PopifyNotifications[array_key].nextPurchase = "";
}
}
}
function getArrayKey(array_list,match_value)
{
for (var i = 0; i= 2)
{
var urlBase = urlParts.shift();
var queryString = urlParts.join('?');
var prefix = encodeURIComponent(parameter) + '=';
var parts = queryString.split(/[&;]/g);
for (var i = parts.length; i-- > 0; )
{
if (parts[i].lastIndexOf(prefix, 0) !== -1)
{
parts.splice(i, 1);
}
}
url = (parts.length > 0) ? urlBase + '?' + parts.join('&') : urlBase;
}
return url;
}
function devdeleteCookie(name)
{
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
function getWorkerURL( url ) {
var content = `importScripts( "${ url }" );`;
return URL.createObjectURL(new File([ content ], { type: "text/plain" }));
}
if (window.location.href.indexOf('location=notification') >= 0)
{
history.pushState({}, null, RemoveUrlParameter(window.location.href, "location"));
if (!localStorage.getItem("popify_acr_push_clicked"))
{
localStorage.setItem("popify_acr_push_clicked", "true");
}
}
if ('serviceWorker' in navigator && 'PushManager' in window)
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key);
jQuery.ajax({
url: window.popifyApiDomain+"/Api/checkUserOptins",
type: "POST",
data: form_data,
processData: false,
contentType: false,
crossDomain: true,
success: function (response)
{
if (response.success == 1)
{
navigator.serviceWorker.register('app-resource-proxy/v1/resource/179f2519-5838-4797-b9ad-ab27cf6c3e14/sw_wix.js')
.then(function(swReg)
{
console.log('popify: service worker registered');
SwRegistration = swReg;
InitializeUI();
if ('SyncManager' in window)
{
var interval = setInterval(function()
{
if (devVerified)
{
clearInterval(interval);
navigator.serviceWorker.ready.then(function(registration)
{
if (IsSubscribed && Registration_id)
{
var form_data = new FormData();
form_data.append("api_key", api_key);
form_data.append("current_link", current_link);
form_data.append("registration_id", Registration_id);
jQuery.ajax({
url: window.popifyApiDomain+"/Api/checkUserSync",
type: "POST",
data: form_data,
processData: false,
contentType: false,
crossDomain: true,
success: function (response)
{
if (response.success == 1)
{
// console.log('registered');
registration.sync.register('unseenNotifications');
}
}
});
}
});
}
}, 1000);
}
else
{
// console.log('Background sync not supported!');
}
})
.catch(function(error)
{
console.error('popify: service worker error', error);
});
}
else
{
console.log('popify subscribe: off');
}
}
});
}
else
{
console.warn('popify: push notifications not supported!');
}
})(jQuery);
}
function trackAddToCartButton(product_sku, product_qty, product_id, cart_id)
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
jQuery.ajax({
url: window.popifyApiDomain+"/Api/notificationAnalyticsTrack?api_key="+api_key+"&analytic_type=add_to_cart&product_sku="+product_sku+"&product_qty="+product_qty+"&product_id="+product_id+"&cart_id="+cart_id,
type: "GET",
crossDomain: true,
dataType: "json",
success: function (response)
{
},
error: function (xhr, status) {
console.log("Notification review load Error");
}
});
}
function devSetCookieExtern(cname, cvalue, exdays, domain) {
var d = new Date();
if(exdays >= 1)
{
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;domain="+domain+";SameSite=Lax";
}
else
{
document.cookie = cname + "=" + cvalue + ";expires=0;path=/;domain="+domain+";SameSite=Lax";
}
}
function devGetCookieExtern(cname)
{
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
jQuery("#popifyDiscount1EmailPart").addClass("popify-hide-class");
jQuery("#popifyDiscount1DiscountPart").removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-discount_1').html(response.message);
preview.find('.popify-error-message-discount_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-discount_1').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-discount_1').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-discount_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-discount_1').fadeOut("slow");
}, 5000);
}
}
function popifySubscribeNewsletter1Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input[type="email"]').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? 'Mobile' : 'Desktop')
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
jQuery("#popifyNewsletter1EmailPart").addClass("popify-hide-class");
jQuery("#popifyNewsletter1ThankyouSection").removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-newsletter_1').html(response.message);
preview.find('.popify-error-message-newsletter_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-newsletter_1').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-newsletter_1').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-newsletter_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-newsletter_1').fadeOut("slow");
}, 5000);
}
}
var scratch_x, scratch_y;
var scratch_defaults = {
color: "transparent",
goal: 100,
brush: 25
};
var scratch_element = null;
var isScratching;
var scratch_canvas;
var scratch_canvas_context;
var scratch_total_pixels;
var scratch_offsetxy;
function scratchItPopify(element) {
scratch_element = element;
isScratching === undefined && initScratching();
}
function initScratching()
{
scratch_canvas = scratch_element.find('canvas');
scratch_canvas_context = scratch_canvas[0].getContext('2d');
var context = scratch_canvas_context;
scratch_canvas_context.fillStyle = scratch_defaults.color;
scratch_canvas_context.fillRect(0,0, scratch_canvas[0].width, scratch_canvas[0].height);
scratch_total_pixels = scratch_canvas[0].width * scratch_canvas[0].height;
if (scratch_element.find('img').length > 0)
{
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('platform', 'wix')
jQuery.ajax({
url: window.popifyApiDomain+"/Api/getScratchedImage",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
var scratchedImage = new Image();
scratchedImage.onload = function(){
scratch_canvas_context.drawImage(scratchedImage, 0, 0);
};
scratchedImage.src = response.image_content;
}
});
}
scratch_canvas_context.strokeStyle = "#FFF";
scratch_canvas_context.lineJoin = "round";
scratch_canvas_context.lineCap = "round";
scratch_canvas_context.lineWidth = scratch_defaults.brush;
scratch_offsetxy = scratch_canvas.offset();
if (mobilecheck())
{
scratch_offsetxy.left *= 0.27;
scratch_offsetxy.top *= 0.27;
}
bindMobileEvents();
scratch_canvas.on({
'mousedown.scratchit' : jQuery.proxy(onDownScratch, this),
'mousemove.scratchit' : jQuery.proxy(onMoveScratch, this),
'mouseup.scratchit' : jQuery.proxy(onUpScratch, this),
});
}
function onDownScratch(e)
{
scratch_x = e.pageX - scratch_offsetxy.left;
scratch_y = e.pageY - scratch_offsetxy.top;
scratch_canvas_context.globalCompositeOperation = "destination-out";
scratch_canvas_context.beginPath();
scratch_canvas_context.moveTo(scratch_x, scratch_y);
scratch_canvas_context.lineTo(scratch_x-1, scratch_y);
scratch_canvas_context.stroke();
isScratching = true;
percentScratched();
}
function onMoveScratch(e)
{
if (!isScratching) { return; }
scratch_x = e.pageX - scratch_offsetxy.left;
scratch_y = e.pageY - scratch_offsetxy.top;
scratch_canvas_context.lineTo(scratch_x, scratch_y);
scratch_canvas_context.stroke();
percentScratched();
}
function onUpScratch(e)
{
percentScratched();
isScratching = false;
}
var scratch_last_event;
function percentScratched()
{
var imageData = scratch_canvas_context.getImageData(0,0, scratch_canvas[0].width, scratch_canvas[0].height),
imageDataLength = imageData.data.length;
var now = Date.now();
var clearedPixels = 0;
var pixel_percent = 0;
if (!scratch_last_event || now - scratch_last_event >= 200)
{
for (var i=0; i < imageDataLength; i=i+4)
{
//the alpha of eace pixel is the 4th value
if (imageData.data[i+3] === 0)
{
clearedPixels++;
}
}
pixel_percent = (clearedPixels / scratch_total_pixels) * 100;
var checked_pixel_percent = (mobilecheck()) ? 40 : 50;
if (pixel_percent >= checked_pixel_percent)
{
setTimeout(function()
{
var popup = $('.popify-special-store-offer.popify-games2');
popup.find('.popify-scratch-section').fadeOut(500).addClass("popify-hide-class");
popup.find('.popify-email-section').fadeIn(500).removeClass("popify-hide-class");
}, 200);
}
scratch_last_event = now;
}
}
function bindMobileEvents()
{
scratch_canvas.on("touchstart touchmove touchend touchcancel", function (a)
{
var b = a.changedTouches || a.originalEvent.targetTouches,
c = b[0],
d = "";
switch (a.type) {
case "touchstart":
d = "mousedown";
break;
case "touchmove":
(d = "mousemove"), a.preventDefault();
break;
case "touchend":
d = "mouseup";
break;
default:
return;
}
var e = document.createEvent("MouseEvent");
if (c !== undefined)
{
e.initMouseEvent(d, !0, !0, window, 1, c.screenX, c.screenY, c.clientX, c.clientY, !1, !1, !1, !1, 0, null);
c.target.dispatchEvent(e);
}
});
}
function closePopifyGames2Popup(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').remove();
}
function spinWheelPopify(data)
{
var padding = {top:20, right:40, bottom:0, left:0};
var w = 540 - padding.left - padding.right, h = 540 - padding.top - padding.bottom, r = Math.min(w, h)/2;
var rotation = 0, oldrotation = 0;
var picked = 100000, oldpick = [];
var color = d3.scale.category20();
var colors = [];
for (var i = 0; i < data.length; i++)
{
var each_color = (i % 2 == 0) ? '#063c5d' : '#095b8d';
colors.push(each_color);
}
var spin_wheel_id = jQuery("body").find('.popify-special-store-offer.popify-games3').find('.popify-spin-wheel-selector').attr('data-id');
var svg = d3.select('#popifySpinWheel'+spin_wheel_id).append("svg").data([data]).attr("width", w + padding.left + padding.right).attr("height", h + padding.top + padding.bottom);
var container = svg.append("g").attr("class", "chartholder").attr("transform", "translate(" + (w/2 + padding.left) + "," + (h/2 + padding.top) + ")");
var vis = container.append("g");
var pie = d3.layout.pie().sort(null).value(function(d){return 1;});
var arc = d3.svg.arc().outerRadius(r);
var arcs = vis.selectAll("g.slice").data(pie).enter().append("g").attr("class", "slice");
arcs.append("path").attr("fill", function(d, i){ return colors[i]; }).attr("d", function (d) { return arc(d); });
arcs.append("text").attr("transform", function(d)
{
d.innerRadius = 0;
d.outerRadius = r;
d.angle = (d.startAngle + d.endAngle)/2;
return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")translate(" + (d.outerRadius -10) +")";
}).attr("text-anchor", "end").attr('x', '-10').attr('style', 'fill: white;').attr('data-selector', function(d, i) {
return data[i].selector;
}).text(function(d, i) {
return data[i].label;
});
container.on("click", spinPopify);
container.append("circle").attr("cx", 0).attr("cy", 0).attr("r", 60).style({"fill":"white","cursor":"pointer"});
container.append("text").attr("x", 0).attr("y", 15).attr("text-anchor", "middle").text("SPIN").style({"font-weight":"bold", "font-size":"25px"});
function spinPopify(d)
{
container.on("click", null);
console.log("OldPick: " + oldpick.length, "Data length: " + data.length);
if (oldpick.length == data.length)
{
console.log("done");
container.on("click", null);
return;
}
var ps = 360 / data.length,
pieslice = Math.round(1440/data.length),
rng = Math.floor((Math.random() * 1440) + 360);
var parent = jQuery("body").find('.popify-special-store-offer.popify-games3');
rotation = (Math.round(rng / ps) * ps);
picked = Math.round(data.length - (rotation % 360)/ps);
picked = picked >= data.length ? (picked % data.length) : picked;
if (oldpick.indexOf(picked) !== -1)
{
d3.select(this).call(spin);
return;
}
else
{
oldpick.push(picked);
}
rotation += 90 - Math.round(ps/2);
vis.transition().duration(3000).attrTween("transform", rotTweenPopify).each("end", function()
{
oldrotation = rotation;
container.on("click", spinPopify);
setTimeout(function()
{
if (data[picked].losing_option == "on")
{
parent.find('.popify-win-section').addClass("popify-hide-class");
parent.find('.popify-email-section').addClass("popify-hide-class");
parent.find('.popify-play-section').fadeOut(500).addClass("popify-hide-class");
parent.find('.popify-loose-section').fadeIn(500).removeClass("popify-hide-class");
}
else
{
parent.find('.popify-loose-section').addClass("popify-hide-class");
parent.find('.popify-win-section').addClass("popify-hide-class");
parent.find('.popify-play-section').fadeOut(500).addClass("popify-hide-class");
parent.find('.popify-email-section').fadeIn(500).removeClass("popify-hide-class");
parent.find('.popify-win-section .popify-discount-code-place').html(data[picked].value);
}
}, 500);
});
}
function rotTweenPopify(to)
{
var i = d3.interpolate(oldrotation % 360, rotation);
return function(t) {
return "rotate(" + i(t) + ")";
};
}
function getRandomNumbers()
{
var array = new Uint16Array(1000);
var scale = d3.scale.linear().range([360, 1440]).domain([0, 100000]);
if(window.hasOwnProperty("crypto") && typeof window.crypto.getRandomValues === "function")
{
window.crypto.getRandomValues(array);
console.log("works");
}
else
{
for(var i=0; i < 1000; i++){
array[i] = Math.floor(Math.random() * 100000) + 1;
}
}
return array;
}
}
function closeGames3PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').remove();
}
function closeSpecialStoreOfferNewsletter1(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').remove();
}
function closeGames1PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').remove();
}
function subscribeScratchPopupPopify(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input[type="email"]').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-email-section').fadeOut(500).addClass("popify-hide-class");
preview.find('.popify-win-section').fadeIn(500).removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-games_2').html(response.message);
preview.find('.popify-error-message-games_2').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-games_2').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-games_2').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-games_2').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-games_2').fadeOut("slow");
}, 5000);
}
}
function subscribeSpinWheelPopupPopify(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input[type="email"]').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-email-section').fadeOut(500).addClass("popify-hide-class");
preview.find('.popify-win-section').fadeIn(500).removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-games_3').html(response.message);
preview.find('.popify-error-message-games_3').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-games_3').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-games_3').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-games_3').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-games_3').fadeOut("slow");
}, 5000);
}
}
function chooseGiftGames1Popify(gift)
{
var discount = gift.attr('data-d');
var losing_option = gift.attr('data-fail');
var preview = gift.closest('.popify-preview');
if (losing_option == "on")
{
preview.find('.popify-choose-gift').fadeOut(500).addClass("popify-hide-class");
preview.find('.popify-loose-section').fadeIn(500).removeClass("popify-hide-class");
}
else
{
preview.find('.popify-choose-gift').fadeOut(500).addClass("popify-hide-class");
preview.find('.popify-email-section').fadeIn(500).removeClass("popify-hide-class");
preview.find('.popify-win-section .popify-discount-code-place').html(discount);
}
}
function subscribeGames1PopupPopify(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input[type="email"]').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-email-section').fadeOut(500).addClass("popify-hide-class");
preview.find('.popify-win-section').fadeIn(500).removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-games_1').html(response.message);
preview.find('.popify-error-message-games_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-games_1').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-games_1').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-games_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-games_1').fadeOut("slow");
}, 5000);
}
}
function closeEmails1PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').fadeOut(1000);
setTimeout(function()
{
jQuery(element).closest('.popify-preview').remove();
}, 1000);
}
function popifyGetOfferEmails1Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var name = parent.find('input.popify-special-store-offer-name-input').val();
var email = parent.find('input.popify-special-store-offer-email-input').val();
if (name.length > 0 && email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('name', name)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('#popifyMainSection').fadeOut(500).addClass("popify-hide-class");
preview.find('#popifyThanksSection').fadeIn(500).removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-emails_1').html(response.message);
preview.find('.popify-error-message-emails_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_1').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
if (name.length < 1)
{
preview.find('.popify-error-message-emails_1').html('Please fill in the name before continue!');
preview.find('.popify-error-message-emails_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_1').fadeOut("slow");
}, 5000);
}
if (email.length < 1)
{
preview.find('.popify-error-message-emails_1').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-emails_1').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_1').fadeOut("slow");
}, 5000);
}
}
}
function closeEmails2PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').fadeOut(1000);
setTimeout(function()
{
jQuery(element).closest('.popify-preview').remove();
}, 1000);
}
function popifySubscribeEmails2Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-success-message-emails_2').html('Thank you for subscribe! The popup will be closed.');
preview.find('.popify-success-message-emails_2').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-success-message-emails_2').fadeOut("slow");
preview.fadeOut("slow");
}, 3000);
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-emails_2').html(response.message);
preview.find('.popify-error-message-emails_2').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_2').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-emails_2').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-emails_2').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_2').fadeOut("slow");
}, 5000);
}
}
function closeEmails3PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').fadeOut(1000);
setTimeout(function()
{
jQuery(element).closest('.popify-preview').remove();
}, 1000);
}
function popifySubscribeEmails3Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-success-message-emails_3').html('Thank you for subscribe! The popup will be closed.');
preview.find('.popify-success-message-emails_3').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-success-message-emails_3').fadeOut("slow");
preview.fadeOut("slow");
}, 3000);
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-emails_3').html(response.message);
preview.find('.popify-error-message-emails_3').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_3').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-emails_3').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-emails_3').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_3').fadeOut("slow");
}, 5000);
}
}
function popifyAddMinutes(date, minutes, seconds)
{
var total = minutes * 60 + seconds;
return new Date(date.getTime() + total * 1000 + 1000);
}
function closeEmails4PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').fadeOut(1000);
setTimeout(function()
{
jQuery(element).closest('.popify-preview').remove();
}, 1000);
}
function popifySubscribeEmails4Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('#popifyMainSection').fadeOut(500).addClass("popify-hide-class");
preview.find('#popifyDiscountSection').fadeIn(500).removeClass("popify-hide-class");
if (localStorage.getItem('popify_special_store_offers_'+jQuery(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+jQuery(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+jQuery(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-emails_4').html(response.message);
preview.find('.popify-error-message-emails_4').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_4').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-emails_4').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-emails_4').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_4').fadeOut("slow");
}, 5000);
}
}
function popifyExpiredTimerPopupEmails4(timer)
{
var preview = jQuery("body").find('.popify-preview-emails_4');
var popup = preview.find('.popify-special-store-offer');
var notification_id = popup.attr('data-id');
if (localStorage.getItem('popify_special_store_offers_'+notification_id))
{
localStorage.removeItem('popify_special_store_offers_'+notification_id);
}
localStorage.setItem('popify_special_store_offers_'+notification_id, 'true');
preview.addClass("popify-hide-class");
}
function closeEmails5PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').fadeOut(1000);
setTimeout(function()
{
jQuery(element).closest('.popify-preview').remove();
}, 1000);
}
function popifySubscribeEmails5Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var email = parent.find('input').val();
if (email.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('email', email)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-success-message-emails_5').html('Thank you for subscribe! The popup will be closed.');
preview.find('.popify-success-message-emails_5').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-success-message-emails_5').fadeOut("slow");
preview.fadeOut("slow");
}, 3000);
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-emails_5').html(response.message);
preview.find('.popify-error-message-emails_5').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_5').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
preview.find('.popify-error-message-emails_5').html('Please fill in the email address before continue!');
preview.find('.popify-error-message-emails_5').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_5').fadeOut("slow");
}, 5000);
}
}
function closeEmails6PopupPopify(event, element)
{
event.preventDefault();
jQuery(element).closest('.popify-preview').fadeOut(1000);
setTimeout(function()
{
jQuery(element).closest('.popify-preview').remove();
}, 1000);
}
function popifySubscribeEmails6Popup(event, element)
{
event.preventDefault();
var parent = jQuery(element).parent();
var preview = jQuery(element).closest('.popify-preview');
var name = parent.find('input.popify-special-store-offer-name-input').val();
var phone = parent.find('input.popify-special-store-offer-phone-input').val();
if (name.length > 0 && phone.length > 0)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', true);
var api_key = jQuery("html script[src*='"+window.popifyApiDomain+"/api/js/popifyWix.js']").attr("data-key");
var current_link = window.location.href;
var form_data = new FormData();
form_data.append("api_key", api_key)
form_data.append("location", current_link)
form_data.append('name', name)
form_data.append('phone', phone)
form_data.append('notification_id', jQuery(element).attr('data-id'))
form_data.append('platform', 'wix')
form_data.append('device', mobilecheck() ? "Mobile" : "Desktop")
jQuery.ajax({
url: window.popifyApiDomain+"/Api/subscribeSpecialStoreOffer",
type: "POST",
processData: false,
contentType: false,
data: form_data,
crossDomain: true,
success: function(response)
{
jQuery(element).find('span').html('');
jQuery(element).prop('disabled', false);
if (response.success == 1)
{
preview.find('.popify-success-message-emails_6').html('Thank you for subscribe! The popup will be closed.');
preview.find('.popify-success-message-emails_6').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-success-message-emails_6').fadeOut("slow");
preview.fadeOut("slow");
}, 3000);
if (localStorage.getItem('popify_special_store_offers_'+$(element).attr('data-id')))
{
localStorage.removeItem('popify_special_store_offers_'+$(element).attr('data-id'));
}
localStorage.setItem('popify_special_store_offers_'+$(element).attr('data-id'), 'true');
}
else
{
preview.find('.popify-error-message-emails_6').html(response.message);
preview.find('.popify-error-message-emails_6').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_6').fadeOut("slow");
}, 5000);
}
}
});
}
else
{
if (name.length < 1)
{
preview.find('.popify-error-message-emails_6').html('Please fill in the name before continue!');
preview.find('.popify-error-message-emails_6').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_6').fadeOut("slow");
}, 5000);
}
if (phone.length < 1)
{
preview.find('.popify-error-message-emails_6').html('Please fill in the phone number before continue!');
preview.find('.popify-error-message-emails_6').fadeIn("slow");
setTimeout(function()
{
preview.find('.popify-error-message-emails_6').fadeOut("slow");
}, 5000);
}
}
}