jQuery(function ($) { //Global object passed by admin var wpChatBotVar = wp_chatbot_obj; var LoadwpwBotPlugin = 0; var textEditorHandler = 0; if( typeof(openingHourIsFn) !='undefined'){ var openingHourIs = openingHourIsFn; }else{ var openingHourIs = 0; } /** * Hide slimScroll bar when content fits; otherwise pin bar to the bottom correctly. * slimScroll shows the bar when scrollHeight < clientHeight due to its size math. */ window.wpbotSyncSlimScrollBar = function ($inner) { $inner = ($inner && $inner.jquery) ? $inner : $('.wp-chatbot-ball-inner'); $inner.each(function () { var el = this; var $el = $(el); var $wrap = $el.parent(); if (!$wrap.hasClass('slimScrollDiv')) { return; } var $bar = $wrap.children('.slimScrollBar'); var $rail = $wrap.children('.slimScrollRail'); if (!$bar.length) { return; } if (el.scrollHeight <= el.clientHeight + 2) { $wrap.addClass('wpbot-no-scroll'); $bar.stop(true, true).hide().css({ opacity: 0 }); $rail.stop(true, true).hide(); return; } $wrap.removeClass('wpbot-no-scroll'); var barH = Math.max(($el.outerHeight() / el.scrollHeight) * $el.outerHeight(), 30); barH = Math.min(barH, $el.outerHeight()); var maxTop = Math.max(0, $el.outerHeight() - barH); var ratio = el.scrollHeight > el.clientHeight ? el.scrollTop / (el.scrollHeight - el.clientHeight) : 1; $bar.css({ height: barH + 'px', top: (ratio * maxTop) + 'px', display: 'block', opacity: 0.4 }); clearTimeout($bar.data('wpbotBarHideTimer')); $bar.data('wpbotBarHideTimer', setTimeout(function () { if (!$bar.is(':hover')) { $bar.fadeOut('slow'); } }, 1000)); }); }; wpChatBotVar.exit_intent_handler = 0; wpChatBotVar.scroll_open_handler = 0; wpChatBotVar.auto_open_handler = 0; wpChatBotVar.re_target_handler = 0; $(document).ready(function () { if(typeof(wpbot_clear_cache) !=="undefined" && wpbot_clear_cache !=''){ wpwKits.reset(); LoadwpwBotPlugin = 0; } var botimage = jQuery('#wp-chatbot-ball').find('img').attr('qcld_agent'); // Custom Icon Video / YouTube: start playback after configured delay var wpbotIconVideo = wpChatBotVar.icon_video || ''; var wpbotVideoDelay = parseInt(wpChatBotVar.icon_video_delay, 10) || 0; if (wpbotIconVideo !== '') { var $wpbotVidEl = $('#wp-chatbot-ball-icon-video'); if ($wpbotVidEl.length) { if (wpbotVideoDelay > 0) { $wpbotVidEl.hide(); setTimeout(function () { $wpbotVidEl.show(); if ($wpbotVidEl.is('video')) { try { $wpbotVidEl[0].play(); } catch(e){} } }, wpbotVideoDelay * 1000); } else { if ($wpbotVidEl.is('video')) { try { $wpbotVidEl[0].play(); } catch(e){} } } } } if ($('#wp-chatbot-shortcode-template-container').length == 0 && $('#wp-chatbot-chat-app-shortcode-container').length == 0) { //Main wpwbot area. //show it $('#wp-chatbot-ball-wrapper').css({ 'display': 'block', }); //wpChatBot icon position. $('#wp-chatbot-chat-container').css({ 'right': wpChatBotVar.wp_chatbot_position_x + 'px', 'bottom': wpChatBotVar.wp_chatbot_position_y + 'px' }) //Facebook Messenger desktop setTimeout(function () { $('.fb_dialog').css({ 'right': parseInt(55 + parseInt(wpChatBotVar.wp_chatbot_position_x)) + 'px', 'bottom': parseInt(17 + parseInt(wpChatBotVar.wp_chatbot_position_y)) + 'px', 'visibility': 'visible' }); }, 3000); //wpchatbot icon animation disable or enable //Disable wpwBot icon Animation if (wpChatBotVar.disable_icon_animation == 1) { $('.wp-chatbot-ball').addClass('wp-chatbot-animation-deactive'); } else { $('.wp-chatbot-ball').addClass('wp-chatbot-animation-active'); //wpchatbot icon animation timing //var itemHide = function(){ // $('.wp-chatbot-animation-active .wp-chatbot-ball-animation-switch').css({ // "opacity": 0, // }) //}; var itemHide = function () { $('.wp-chatbot-animation-active .wp-chatbot-ball-animation-switch').fadeOut(1000); }; setTimeout(function () { itemHide() }, 1000); //Click Animation $('.wp-chatbot-animation-active').click(function () { $('.wp-chatbot-animation-active .wp-chatbot-ball-animation-switch').fadeIn(100); setTimeout(function () { itemHide() }, 1000); }); } //window resize. var widowH = $(window).height(); var widowW = $(window).width(); if (widowW > 767) { var ballConH = parseInt(widowH * 0.5)+ parseInt(114); //$('.wp-chatbot-ball-inner').css({'height': ballConH + 'px'}) $(window).resize(function () { var widowH = $(window).height(); var ballConH = parseInt(widowH * 0.5)+ parseInt(114); //$('.wp-chatbot-ball-inner').css({'height': ballConH + 'px'}) }); }; $(document).on('click', '#wp-chatbot-ball', function (event) { if($('.active-chat-board').length>0){ if(wpChatBotVar.template=='template-06' || wpChatBotVar.template=='template-07'){ $('#wp-chatbot-ball').show(); } $('#wp-chatbot-ball').removeClass('wpbot_chatopen_iconanimation'); $('#wp-chatbot-ball').addClass('wpbot_chatclose_iconanimation'); // Restore: hide close icon, show video OR image $('#wp-chatbot-ball').find('img#wp-chatbot-ball-icon-img').attr('src', botimage); if (wpbotIconVideo !== '') { $('#wp-chatbot-ball-icon-video').show(); $('#wp-chatbot-ball').find('img#wp-chatbot-ball-icon-img').hide(); $('#wp-chatbot-ball').find('img.wpbot-close-icon-overlay').hide(); } else { $('#wp-chatbot-ball').find('img#wp-chatbot-ball-icon-img').show(); } $('.wp-chatbot-ball').css('background', '#ffffff'); }else{ $('#wp-chatbot-ball').removeClass('wpbot_chatclose_iconanimation'); $('#wp-chatbot-ball').addClass('wpbot_chatopen_iconanimation'); // Show close icon; hide video OR image if (wpbotIconVideo !== '') { $('#wp-chatbot-ball-icon-video').hide(); $('#wp-chatbot-ball').find('img#wp-chatbot-ball-icon-img').attr('src', wpChatBotVar.imgurl+'wpbot-close-icon.png').show(); } else { $('#wp-chatbot-ball').find('img').attr('src', wpChatBotVar.imgurl+'wpbot-close-icon.png'); } //$('.wp-chatbot-ball').css('background', 'unset'); } var $boardContainer = $("#wp-chatbot-board-container"); var animationDuration = 280; var isOpening = !$boardContainer.hasClass('active-chat-board'); $boardContainer.removeClass('wp-chatbot-open-anim wp-chatbot-close-anim'); if (isOpening) { $boardContainer.addClass('active-chat-board'); void $boardContainer[0].offsetWidth; $boardContainer.addClass('wp-chatbot-open-anim'); wpwbot_board_action(); setTimeout(function () { $boardContainer.removeClass('wp-chatbot-open-anim'); }, 360); } else { void $boardContainer[0].offsetWidth; $boardContainer.addClass('wp-chatbot-close-anim'); setTimeout(function () { $boardContainer.removeClass('active-chat-board wp-chatbot-close-anim'); wpwbot_board_action(); }, animationDuration); } }); //wpwBot proActive start //Attention on if(wpChatBotVar.enable_meta_title==1 && wpChatBotVar.meta_label!="") { var MetaTitleInterval; var orginalTitle = document.title; $(document).on("mouseover", 'body', function (e) { document.title = orginalTitle; clearInterval(MetaTitleInterval); }); } //Exit Intent if(wpChatBotVar.enable_exit_intent == 1){ window.addEventListener("mouseout", function (e) { e = e ? e : window.event; // If this is an autocomplete element. if (e.target.tagName.toLowerCase() == "input") return; // Get the current viewport width. var vpWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); // If the current mouse X position is within 50px of the right edge // of the viewport, return. if (e.clientX >= (vpWidth - 50)) return; // If the current mouse Y position is not within 50px of the top // edge of the viewport, return. if (e.clientY >= 50) return; // Reliable, works on mouse exiting window and // user switching active program var from = e.relatedTarget || e.toElement; if (!from) //if will open once if setup from backend. var exitIntentOpen=true; if($.cookie('exit_intent')=='yes' && wpChatBotVar.exit_intent_once==1) { exitIntentOpen=false; } if ($('.active-chat-board').length == 0 && exitIntentOpen==true) { if (wpChatBotVar.exit_intent_handler == 0) { $("#wp-chatbot-board-container").addClass('active-chat-board'); wpChatBotVar.exit_intent_handler++; wpChatBotVar.re_target_handler = 1; wpwbot_board_action(); //Shopper Name if(localStorage.getItem('shopper')){ var shopper=localStorage.getItem('shopper'); }else{ var shopper=wpChatBotVar.shopper_demo_name; } setTimeout(function () { if (localStorage.getItem("wpwHitory")) { showing_proactive_msg( wpChatBotVar.ret_greet+' '+shopper +', '+wpChatBotVar.exit_intent_msg); } else { showing_proactive_double_msg(wpChatBotVar.ret_greet+' '+shopper+', '+wpChatBotVar.exit_intent_msg) } $.cookie('exit_intent','yes'); //pro active sound proactive_retargeting_sound(); //Window foucus meta title change. window_focus_change_meta_title(); }, 1000) } } }); } if(wpChatBotVar.enable_scroll_open==1){ $(document).on('scroll', function (event) { var OpenScroll=true; //if will open once if setup from backend. if( $.cookie('scroll_open')=='yes' && wpChatBotVar.scroll_open_once==1) { OpenScroll=false; } //it will be open only for single time. if ($('.active-chat-board').length ==0 && OpenScroll==true) { if (wpChatBotVar.scroll_open_handler == 0) { var scrollOpenVal = parseInt(($(document).height() * wpChatBotVar.scroll_open_percent) / 100); if ($(window).scrollTop() + $(window).height() > scrollOpenVal) { $("#wp-chatbot-board-container").addClass('active-chat-board'); wpChatBotVar.scroll_open_handler++; wpChatBotVar.re_target_handler = 2; wpwbot_board_action(); //Shopper Name if(localStorage.getItem('shopper')){ var shopper=localStorage.getItem('shopper'); }else{ var shopper=wpChatBotVar.shopper_demo_name; } setTimeout(function () { if (localStorage.getItem("wpwHitory")) { showing_proactive_msg(wpChatBotVar.ret_greet+' '+ shopper+', '+wpChatBotVar.scroll_open_msg); } else { showing_proactive_double_msg(wpChatBotVar.ret_greet+' '+ shopper+', '+wpChatBotVar.scroll_open_msg) } $.cookie('scroll_open','yes'); //pro active sound proactive_retargeting_sound(); //Window foucus meta title change. window_focus_change_meta_title(); }, 1000) } } } }); } if(wpChatBotVar.enable_auto_open==1 ){ //if will open once if setup from backend. var autoOpen=true; if($.cookie('auto_open')=='yes' && wpChatBotVar.auto_open_once==1) { autoOpen=false; } if( wpChatBotVar.auto_open_handler == 0 && autoOpen==true) { setTimeout(function (e) { if ($('.active-chat-board').length == 0) { $("#wp-chatbot-board-container").addClass('active-chat-board'); wpChatBotVar.auto_open_handler++; wpChatBotVar.re_target_handler = 3; wpwbot_board_action(); //Shopper Name if(localStorage.getItem('shopper')){ var shopper=localStorage.getItem('shopper'); }else{ var shopper=wpChatBotVar.shopper_demo_name; } setTimeout(function () { if (localStorage.getItem("wpwHitory")) { showing_proactive_msg(wpChatBotVar.ret_greet+' '+ shopper+', '+wpChatBotVar.auto_open_msg); } else { showing_proactive_double_msg(wpChatBotVar.ret_greet+' '+shopper+', '+wpChatBotVar.auto_open_msg) } $.cookie('auto_open','yes'); //pro active sound proactive_retargeting_sound(); //Window foucus meta title change. window_focus_change_meta_title(); }, 1000) } }, parseInt(wpChatBotVar.auto_open_time * 1000)); } } //Retargeting for Cart to complete checkout. if(wpChatBotVar.enable_ret_user_show==1 && localStorage.getItem("wpwHitory") && $.cookie('return_user')!='yes') { $.cookie('return_user','yes'); var data = {'action': 'qcld_wb_chatbot_only_cart'}; jQuery.post(wpChatBotVar.ajax_url, data, function (response) { if (response.items > 0) { if ($('.active-chat-board').length == 0) { setTimeout(function () { $("#wp-chatbot-board-container").addClass('active-chat-board'); wpwbot_board_action(); showing_proactive_msg(wpChatBotVar.checkout_msg); setTimeout(function () { showing_proactive_msg(response.html); //Window foucus meta title change. window_focus_change_meta_title(); }, 2000); }, 1000); } } }); }else{ $.cookie('return_user','yes'); } if(wpChatBotVar.enable_inactive_time_show==1 && localStorage.getItem("wpwHitory") ) { var timeoutID; function setup() { this.addEventListener("mousemove", resetTimer, false); this.addEventListener("mousedown", resetTimer, false); this.addEventListener("keypress", resetTimer, false); this.addEventListener("DOMMouseScroll", resetTimer, false); this.addEventListener("mousewheel", resetTimer, false); this.addEventListener("touchmove", resetTimer, false); this.addEventListener("MSPointerMove", resetTimer, false); startTimer(); } setup(); function startTimer() { // wait as set from admin seconds before calling goInactive timeoutID = window.setTimeout(goInactive, parseInt(wpChatBotVar.inactive_time*1000)); } function resetTimer(e) { window.clearTimeout(timeoutID); goActive(); } function goInactive() { if(wpChatBotVar.ret_inactive_user_once==1 && $.cookie('return_inactive_user')!='yes') { $.cookie('return_inactive_user','yes'); var data = {'action': 'qcld_wb_chatbot_only_cart'}; jQuery.post(wpChatBotVar.ajax_url, data, function (response) { if (response.items > 0) { if ($('.active-chat-board').length == 0) { setTimeout(function () { $('#wp-chatbot-ball').removeClass('wpbot_chatclose_iconanimation'); $('#wp-chatbot-ball').addClass('wpbot_chatopen_iconanimation'); if (wpbotIconVideo !== '') { $('#wp-chatbot-ball-icon-video').hide(); $('#wp-chatbot-ball').find('img#wp-chatbot-ball-icon-img').attr('src', wpChatBotVar.imgurl+'wpbot-close-icon.png').show(); } else { $('#wp-chatbot-ball').find('img').attr('src', wpChatBotVar.imgurl+'wpbot-close-icon.png'); } $("#wp-chatbot-board-container").addClass('active-chat-board'); wpwbot_board_action(); showing_proactive_msg(wpChatBotVar.checkout_msg); setTimeout(function () { showing_proactive_msg(response.html); //Window foucus meta title change. window_focus_change_meta_title(); }, 2000); }, 2000); } } }); }else{ $.cookie('return_inactive_user','yes'); } } function goActive() { // do something startTimer(); } } //Proactive retargeting sound for auto open. scroll open and function proactive_retargeting_sound() { if(wpChatBotVar.enable_ret_sound==1){ var promise = document.querySelector('#wp-chatbot-proactive-audio').play(); if (promise !== undefined) { promise.then(function (success) { //success to play }).catch(function (error) { //some error //console.log(error); }); } } } //When user will be out of window and news retargetting will be shown. where opening hour, title and meta need to be set. function window_focus_change_meta_title() { if(wpChatBotVar.enable_meta_title==1 && wpChatBotVar.meta_label!="" && openingHourIs==0) { var showInactive = 0; MetaTitleInterval = setInterval(function () { if (showInactive == 0) { document.title = wpChatBotVar.meta_label; showInactive = 1; } else { document.title = orginalTitle; showInactive = 0; } }, 1000); } } //wpwBot proActive end function wpwbot_board_action() { var currentW = $(window).width(); var isBoardOpen = $('#wp-chatbot-board-container').hasClass('active-chat-board'); if (currentW <= 480 && wpChatBotVar.mobile_full_screen==1 && isBoardOpen) {//For mobile if ($('#wp-chatbot-mobile-close').length <= 0) { $('.wp-chatbot-board-container').append('


');
var data = {'action': 'qcld_wb_chatbot_cart_page'};
jQuery.post(wpChatBotVar.ajax_url, data, function (response) {
$("#wp-chatbot-cart-short-code").html(response);
});
});
$(document).on('click', '.wp-chatbot-checkout-link, .checkout-button', function (event) {
event.preventDefault();
$('.wp-chatbot-messages-wrapper').hide();
$('#wp-chatbot-cart-short-code').hide();
$('#wp-chatbot-checkout-short-code').show();
$('#wp-chatbot-checkout-short-code').html('
');
var data = {'action': 'qcld_wb_chatbot_checkout_page'};
jQuery.post(wpChatBotVar.ajax_url, data, function (response) {
if (response.status == 'yes') {
window.location.href = response.html;
} else {
$("#wp-chatbot-checkout-short-code").html(response.html);
}
});
});
//Preventing url redirect from cart page.
$(document).on('click', '#wp-chatbot-chat-app-shortcode-container .wpcommerce-cart-form a', function (e) {
e.preventDefault();
});
}
//For variable product configuration
$(document).on('change', "#wp-chatbot-product-variable select ", function () {
var variations = JSON.parse($("#wp-chatbot-variation-data").attr('data-product-variation'));
var item_conditions = [];
var totalAttr = $("#wp-chatbot-product-variable select").length;
var i = 1;
$("#wp-chatbot-product-variable select").each(function (index, element) {
var myVal = $(this).find('option:selected').val();
if (myVal != "") {
item_conditions.push({
'left': 'item["variation_data"]["' + $(this).attr('name') + '"][0]',
'right': myVal
})
}
});
var newVariation = [];
for (var a = 0; variations.length > a; a++) {
var item = variations[a];
var item_condition = "";
for (var i = 0; item_conditions.length > i; i++) {
if (i > 0) {
item_condition += ' && ' + '"' + eval(item_conditions[i].left).toLowerCase() + '"' + '==' + '"' + item_conditions[i].right.toLowerCase() + '"';
} else {
item_condition += '"' + eval(item_conditions[i].left).toLowerCase() + '"' + '==' + '"' + item_conditions[i].right.toLowerCase() + '"';
}
}
if (eval(item_condition)) {
newVariation[0] = item;
}
}
if (newVariation.length > 0) {
$('#wp-chatbot-variation-add-to-cart').attr('variation_id', newVariation[0]['variation_id']);
var priceSets = "";
if (newVariation[0]['variation_data']['_sale_price'][0] != "") {
priceSets += '