芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/www/wp-content/plugins/chaty/admin/assets/js/preview.js
var previewChannelList = []; var advanceCustomCSS = ""; var chtIframeData = ""; jQuery(document).ready(function(){ var iframeData = jQuery("#wp-cta_body_text-wrap").find("iframe"); chtIframeData = iframeData.contents().find("body").html(); setInterval(function(){ if(jQuery("#cta-option-chat-view").is(":checked") && jQuery("#wp-cta_body_text-wrap").length) { var iframeData = jQuery("#wp-cta_body_text-wrap").find("iframe"); bodyMsg = iframeData.contents().find("body").html(); if (bodyMsg != chtIframeData) { chtIframeData = bodyMsg; change_custom_preview(); } } }, 2000); jQuery(document).on("click", "#save-button", function(){ jQuery("#button_type").val(1); }); jQuery(document).on("click", "#save-dashboard-button", function(){ jQuery("#button_type").val(2); }); jQuery(document).on("click", ".custom-channel-button a.custom-channel-link", function(e){ e.preventDefault(); jQuery(".main .channels-icons > .icon.custom-link:not(.active):first").trigger("click"); if(jQuery(".main .channels-icons > .icon.custom-link").length == jQuery(".main .channels-icons > .icon.custom-link.active").length) { jQuery(".custom-channel-button").hide(); } }); jQuery(document).on("mouseover", ".csaas.open-on-hover .csaas-i-trigger:not(.single-channel)", function () { if(!jQuery(this).closest(".csaas-widget").hasClass("csaas-open") && !jQuery(this).closest(".csaas-widget").hasClass("on-csaas-widget")) { jQuery(this).closest(".csaas-widget").addClass("on-csaas-widget"); jQuery(this).find(".csaas-cta-main").trigger("click"); } }).on("mouseleave", ".csaas.open-on-hover .csaas-i-trigger:not(.single-channel)", function () { if(!jQuery(this).closest(".csaas-widget").hasClass("csaas-open") ) { jQuery(this).closest(".csaas-widget").removeClass("on-csaas-widget") } }); jQuery(document).on("click", ".csaas-close-view-list", function(){ jQuery(this).closest(".csaas").find(".csaas-widget").removeClass("csaas-open"); }); jQuery(document).on("click", ".csaas-i-trigger:not(.single-channel)", function(){ jQuery(this).closest(".csass").removeClass("form-open"); jQuery(this).closest(".csaas-widget:not(.has-single)").toggleClass("csaas-open"); jQuery(".csaas-outer-forms").removeClass("active"); jQuery(".form-open").removeClass("form-open"); jQuery(".chaty-preview").height(234); }); jQuery(document).on("click", "#whatsapp_embedded_window_Whatsapp", function(){ change_custom_preview(); }); jQuery(document).on("click", "#cht_active", function(){ if(jQuery(this).is(":checked")) { jQuery("#chaty-turned-on").addClass("active"); jQuery("#chaty-turned-off").removeClass("active"); } else { jQuery("#chaty-turned-off").addClass("active"); jQuery("#chaty-turned-on").removeClass("active"); } }); jQuery(document).on("click", "a.csaas-whatsapp-form", function(e){ e.preventDefault(); // e.stopPropagation(); var dataForm = jQuery(this).data('form'); if(!isEmpty(dataForm)) { if(jQuery("#"+dataForm).length) { if(jQuery(this).closest(".csaas").hasClass("form-open")) { jQuery("#" + dataForm).removeClass("is-active"); jQuery(this).closest(".csaas-widget:not(.has-single)").addClass("csaas-open"); jQuery(this).closest(".csaas").removeClass("form-open"); jQuery("#" + dataForm).removeClass("active"); } else { var widgetSize = parseInt(jQuery("#custom-widget-size-input").val() * 2 / 3); var totalSize = parseInt(jQuery("#" + dataForm).height() / 2) + widgetSize + 20; if (totalSize > 234) { jQuery(".chaty-preview").height(totalSize + 10); } var buttonHtml = jQuery(this).closest(".csaas-widget").find(".csaas-cta-close").find("button").html(); jQuery("#" + dataForm).addClass("is-active"); jQuery(this).closest(".csaas-widget").removeClass("csaas-open"); jQuery(this).closest(".csaas").addClass("form-open"); jQuery("#" + dataForm).addClass("active"); jQuery(this).closest(".csaas-widget").find(".open-csaas-channel").html(buttonHtml); } } } }); jQuery(document).on("keyup", ".whatsapp-placeholder", function(){ jQuery("#csaas_whatsapp_input").attr("placeholder", jQuery(this).val()); }); jQuery(document).on("change", ".whatsapp-placeholder", function(){ jQuery("#csaas_whatsapp_input").attr("placeholder", jQuery(this).val()); }); jQuery(document).on("click", ".whatsapp-emoji", function(){ if(jQuery(this).is(":checked")) { jQuery(".csaas-whatsapp-field").addClass("has-emoji"); } else { jQuery(".csaas-whatsapp-field").removeClass("has-emoji"); } }); jQuery(document).on("click", ".csaas-close-button, .csaas-close-agent-list, .whatsapp-form-close-btn", function(e) { e.preventDefault(); e.stopPropagation(); jQuery(".csaas-outer-forms").removeClass("active"); jQuery("#csaas-widget-0").removeClass("form-open"); if(jQuery("#csaas-widget-0").find(".csaas-widget").hasClass("csaas-no-close-button")) { jQuery("#csaas-widget-0").find(".csaas-widget:not(.has-single)").addClass("csaas-open"); } jQuery(".chaty-preview").height(234); }); jQuery(document).on("click", "a.csaas-qr-code-form", function(e){ e.preventDefault(); var dataForm = jQuery(this).data('form'); if(!isEmpty(dataForm)) { if(jQuery("#"+dataForm).length) { var widgetSize = parseInt(jQuery("#custom-widget-size-input").val() * 2 / 3); var totalSize = parseInt(jQuery("#"+dataForm).height()/2) + widgetSize + 20; if(totalSize > 234) { jQuery(".chaty-preview").height(totalSize+10); } var buttonHtml = jQuery(this).closest(".csaas-widget").find(".csaas-cta-close").find("button").html(); jQuery(this).closest(".csaas-widget").removeClass("csaas-open"); jQuery(this).closest(".csaas").addClass("form-open"); jQuery("#"+dataForm).addClass("active"); jQuery(this).closest(".csaas-widget").find(".open-csaas-channel").html(buttonHtml); } } }); jQuery(document).on("click", "a.csaas-contact-us-form", function(e){ e.preventDefault(); // e.stopPropagation(); var dataForm = jQuery(this).data('form'); if(!isEmpty(dataForm)) { if(jQuery("#"+dataForm).length) { var widgetSize = parseInt(jQuery("#custom-widget-size-input").val() * 2 / 3); var totalSize = parseInt(jQuery("#"+dataForm).height()/2) + widgetSize + 20; if(totalSize > 234) { jQuery(".chaty-preview").height(totalSize+10); jQuery(".preview .page").height(totalSize+26); } var buttonHtml = jQuery(this).closest(".csaas-widget").find(".csaas-cta-close").find("button").html(); jQuery(this).closest(".csaas-widget").removeClass("csaas-open"); jQuery(this).closest(".csaas").addClass("form-open"); jQuery("#"+dataForm).addClass("active"); jQuery("#"+dataForm).find(".csaas-ajax-success-message").remove(); jQuery("#"+dataForm).find(".csaas-ajax-error-message").remove(); jQuery("#"+dataForm).find(".has-csaas-error").removeClass("has-csaas-error"); jQuery(this).closest(".csaas-widget").find(".open-csaas-channel").html(buttonHtml); } } }); jQuery(document).on("click", ".csaas-widget.has-single .csaas-i-trigger.single-channel .csaas-cta-close .csaas-cta-button", function(){ jQuery(this).closest(".csaas").removeClass("form-open"); jQuery(".csaas-outer-forms").removeClass("active"); }); jQuery(document).on("keyup", "#cht_social_message_Contact_Us_form_title", function(){ jQuery(".csaas-contact-form-title").text(jQuery(this).val().toHtmlEntities()); }); jQuery(document).on("keyup", "#button_text_for_Contact_Us", function(){ jQuery("#csaas-submit-button-0").text(jQuery(this).val().toHtmlEntities()); }); jQuery(document).on("keyup", "#cta_heading_text", function(){ jQuery(".csaas-view-header").text(jQuery(this).val().toHtmlEntities()); }); jQuery(document).on("keyup", "#cta_body_text", function(){ jQuery(".csaas-top-content").text(jQuery(this).val().toHtmlEntities()); }); jQuery(document).on("change", ".form-field-setting-col input[type='text'], .chaty-input-text", function(){ change_custom_preview(); }); jQuery(document).on("click", ".form-field-setting-col input[type='checkbox']", function(){ change_custom_preview(); }); jQuery(document).on("change", ".chaty-agent-name, #chaty_default_state, input[name='chaty_icons_view']:checked", function(){ change_custom_preview(); }); jQuery(document).on("keyup", "input[name='cht_close_button_text']", function(){ change_custom_preview(); }); jQuery(document).on("change", "input[name='cht_close_button_text']", function(){ change_custom_preview(); }); jQuery(document).on("click", ".chaty-preview input, .chaty-preview button", function(e){ e.preventDefault(); }); jQuery(document).on("click", ".csaas-channel.csaas-agent-button", function(e){ e.preventDefault(); // e.stopPropagation(); var dataForm = jQuery(this).data('form'); if(!isEmpty(dataForm)) { if(jQuery("#"+dataForm).length) { if(jQuery(this).closest(".csaas").hasClass("form-open")) { jQuery(this).closest(".csaas-widget:not(.has-single)").addClass("csaas-open"); jQuery(this).closest(".csaas").removeClass("form-open"); jQuery("#" + dataForm).removeClass("active"); } else { var widgetSize = parseInt(jQuery("#custom-widget-size-input").val() * 2 / 3); var totalSize = parseInt(jQuery("#" + dataForm).height() / 2) + widgetSize + 20; if (totalSize > 234) { jQuery(".chaty-preview").height(totalSize + 10); jQuery(".preview .page").height(totalSize + 26); } var buttonHtml = jQuery(this).closest(".csaas-widget").find(".csaas-cta-close").find("button").html(); jQuery("#" + dataForm).addClass("is-active"); jQuery(this).closest(".csaas-widget").removeClass("csaas-open"); jQuery(this).closest(".csaas").addClass("form-open"); jQuery("#" + dataForm).addClass("active"); jQuery(this).closest(".csaas-widget").find(".open-csaas-channel").html(buttonHtml); } } } }); jQuery(document).on("click", "#trigger_on_time, #chaty_trigger_on_scroll, #cht_close_button", function(){ change_custom_preview(); }); jQuery(".chaty-color-field.chaty-bg-color").trigger("change"); change_custom_preview(); }); jQuery(window).on("load", function(){ jQuery(".chaty-color-field.chaty-bg-color").trigger("change"); }); function change_custom_preview() { var socialString = []; jQuery("#channels-selected-list > li.chaty-channel").each(function () { socialString.push(jQuery(this).attr("data-id")); }); socialString = socialString.join(","); jQuery("#cht_numb_slug").val(socialString); if(jQuery(".main .channels-icons > .icon.custom-link").length != jQuery(".main .channels-icons > .icon.custom-link.active").length) { jQuery(".custom-channel-button").show(); } if(!jQuery("#trigger_on_time").is(":checked")){ jQuery("#chaty_trigger_time").prop("disabled", true); } else { jQuery("#chaty_trigger_time").prop("disabled", false); } if(!jQuery("#chaty_trigger_on_scroll").is(":checked")){ jQuery("#chaty_trigger_on_page_scroll").prop("disabled", true); } else { jQuery("#chaty_trigger_on_page_scroll").prop("disabled", false); } if(jQuery("#chaty_default_state").val() == "open" && jQuery("#channel-list > .icon.active").length > 1) { jQuery("#chaty_attention_effect").val(""); jQuery("#chaty_attention_effect, .test_textarea").attr("disabled", true); jQuery("#chaty_attention_effect option:first-child").text("Doesn't apply for the open state"); if(jQuery(".test_textarea").val() != "Doesn't apply for the open state") { jQuery(".test_textarea").attr("data-value", jQuery(".test_textarea").val().toHtmlEntities()); } jQuery(".test_textarea").val("Doesn't apply for the open state"); jQuery("#cht_number_of_messages").attr("disabled", true); jQuery("#cht_pending_messages").attr("disabled", true); jQuery(".disable-message").addClass("label-tooltip").addClass("icon"); jQuery("#cht_pending_messages").attr("checked", false); jQuery(".pending-message-items").removeClass("active"); jQuery("#cta-action input").attr("disabled", true); } else { jQuery("#chaty_attention_effect, .test_textarea").attr("disabled", false); jQuery("#chaty_attention_effect option:first-child").text("None"); jQuery(".test_textarea").attr("placeholder",""); if(jQuery(".test_textarea").val() == "Doesn't apply for the open state") { jQuery(".test_textarea").val(jQuery(".test_textarea").attr("data-value")); } jQuery("#cht_number_of_messages").attr("disabled", false); jQuery("#cht_pending_messages").attr("disabled", false); jQuery(".disable-message").removeClass("label-tooltip").removeClass("icon"); jQuery("#cta-action input").attr("disabled", false); } if(jQuery(".chaty-bg-color").length) { jQuery(".chaty-bg-color").each(function () { if(jQuery(this).closest(".chaty-channel").data("channel") == "Instagram") { if(jQuery(this).val() != "#ffffff") { jQuery(this).closest("li.chaty-channel").find(".chaty-main-svg").find(".color-element").attr("fill", jQuery(this).val()); } } else { jQuery(this).closest("li.chaty-channel").find(".chaty-main-svg").find(".color-element").attr("fill", jQuery(this).val()); } }); } if(jQuery(".agent-icon-color").length) { jQuery(".agent-icon-color").each(function () { if(jQuery(this).closest(".chaty-channel").data("channel") == "Instagram") { if(jQuery(this).val() != "#ffffff") { jQuery(this).closest("li.chaty-channel").find(".chaty-main-svg").find(".color-element").attr("fill", jQuery(this).val()); } } else { jQuery(this).closest("li.chaty-channel").find(".chaty-main-svg").find(".color-element").attr("fill", jQuery(this).val()); } }); } jQuery(".chaty-preview").height(234); jQuery(".chaty-preview").html(""); previewChannelList = []; var isDesktop = jQuery("#previewDesktop").is(":checked")?true:false; if(!isDesktop) { jQuery("#admin-preview .page").addClass("mobile"); } else { jQuery("#admin-preview .page").removeClass("mobile"); } if(jQuery("#channels-selected-list > li:not(.chaty-cls-setting)").length >= 2) { jQuery("#chaty-social-close").show(); } else { jQuery("#chaty-social-close").hide(); } jQuery(".csaas-outer-forms").remove(); if(jQuery("#chaty_default_state").val() == "open") { jQuery(".hide-show-button").addClass("active"); } else { jQuery(".hide-show-button").removeClass("active"); } if(jQuery("#channel-list .icon.active").length == 0) { jQuery(".channel-empty-state").addClass("active"); } else { jQuery(".channel-empty-state").removeClass("active"); } if(jQuery("#channels-selected-list > li").length > 0) { advanceCustomCSS = ""; var activeChannels = getActiveChannels(); if(activeChannels) { if(activeChannels <= 1 && jQuery("input[name='cta_type']:checked").val() != "chat-view") { jQuery('.chaty-widget-color').addClass('hidden'); } else { jQuery('.chaty-widget-color').removeClass('hidden'); } if(jQuery("#whatsapp_embedded_window_Whatsapp").length && jQuery("#whatsapp_embedded_window_Whatsapp").is(":checked")) { jQuery('.chaty-widget-color').removeClass('hidden'); } if(jQuery("#upload_qr_code_val-WeChat").length && jQuery("#upload_qr_code_val-WeChat").val() != "") { jQuery('.chaty-widget-color').removeClass('hidden'); } if(jQuery("#chaty-social-Contact_Us").length) { jQuery('.chaty-widget-color').removeClass('hidden'); } var widgetPosition = getWidgetPosition(); widgetPosition = (widgetPosition == "right") ? "right" : "left"; var toolTipPosition = getToolTipPosition(); if(jQuery("input[name='cta_type']:checked").val() == "chat-view") { var widgetHtml = "
" + "
" + "
" + "
" + "
" + "
" + "
"; jQuery(".chaty-preview").append(widgetHtml); makeChatyChatView(); } else { var widgetHtml = "
" + "
" + "
" + "
" + "
" + "
" + "
" + "
"; jQuery(".chaty-preview").append(widgetHtml); } if(previewChannelList.length == 1 && jQuery("input[name='cta_type']:checked").val() != "chat-view") { var channelHtml = getChannelSetting(previewChannelList[0], 0, toolTipPosition); jQuery("#csaas-widget-0 .csaas-i-trigger").html(channelHtml); jQuery("#csaas-widget-0 .csaas-i-trigger").addClass("single-channel"); jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel").addClass("single"); jQuery("#csaas-widget-0 .csaas-widget").addClass("has-single"); var ctaText = jQuery(".test_textarea").val(); if(!isEmpty(ctaText)) { ctaText = htmlDecode(ctaText); } if(!isEmpty(ctaText)) { jQuery("#csaas-widget-0 .csaas-tooltip").removeClass("csaas-tooltip"); jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel").attr("data-hover", ctaText.toHtmlEntities()); jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel").addClass("active").addClass("csaas-tooltip").addClass(toolTipPosition); jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel").addClass("active").addClass("csaas-tooltip").addClass("pos-"+toolTipPosition); jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel").append("
"+ctaText.toHtmlEntities()+"
").addClass("active").addClass("has-on-hover"); jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel a").append("
"+ctaText.toHtmlEntities()+"
").addClass("has-on-hover"); } var closeHtml = '
' + '
' + '
' + '
' + '
' + '
Hide csaas
' + '
' + '
' + '
'; jQuery("#csaas-widget-0 .csaas-i-trigger").append(closeHtml); } else { for(i=0; i
' + '
'+ctaText.toHtmlEntities()+'
' + '
' + '
' + widgetIcon + '
' + '
' + '
' + '
'; jQuery("#csaas-widget-0 .csaas-i-trigger").html(widgetButton); var closeButtonText = jQuery("input[name='cht_close_button_text']").val(); if(!isEmpty(closeButtonText)) { closeButtonText = htmlDecode(closeButtonText); } /* close button */ var closeHtml = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; jQuery("#csaas-widget-0 .csaas-i-trigger").append(closeHtml); } if(jQuery("#chaty_default_state").val() != "open" || previewChannelList.length == 1) { checkForPendingMessage(); checkForWidgetAnimation(); } var extraSpace = 0; /* check for close button */ if(jQuery("#chaty_default_state").val() == "open" && !jQuery("#cht_close_button").is(":checked") && jQuery("input[name='cta_type']:checked").val() == "simple-view") { jQuery("#csaas-widget-0 .csaas-widget").addClass("csaas-no-close-button"); extraSpace = 1; } /* check for State */ if(jQuery("#chaty_default_state").val() == "hover") { jQuery("#csaas-widget-0").addClass("open-on-hover"); } else if(jQuery("#chaty_default_state").val() == "open") { jQuery("#csaas-widget-0 .csaas-widget").addClass("default-open"); jQuery("#csaas-widget-0 .csaas-widget:not(.has-single)").addClass("csaas-open"); if(!jQuery("#cht_close_button").is(":checked")) { jQuery("#csaas-widget-0 .csaas-widget:not(.has-single)").addClass("csaas-open"); } } var widgetSize = parseInt(jQuery("#custom-widget-size-input").val() * 2 / 3); advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .custom-csaas-image {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .facustom-icon { width: "+widgetSize+"px; height: "+widgetSize+"px; line-height: "+widgetSize+"px; font-size:"+(parseInt(widgetSize/2))+"px; text-align: center; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel a img {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel a {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .csaas-custom-icon {display:block; width: "+widgetSize+"px; height: "+widgetSize+"px; line-height: "+widgetSize+"px; font-size: "+parseInt(widgetSize/2)+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel button {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .csaas-svg {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .custom-agent-image {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .facustom-icon {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .custom-agent-image img {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .csaas-svg img {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list .csaas-channel .csaas-svg .csaas-custom-channel-icon {width: "+widgetSize+"px; height: "+widgetSize+"px; line-height: "+widgetSize+"px; display: block; font-size:"+(parseInt(widgetSize/2))+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .custom-csaas-image {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .facustom-icon { width: "+widgetSize+"px; height: "+widgetSize+"px; line-height: "+widgetSize+"px; font-size:"+(parseInt(widgetSize/2))+"px; text-align: center; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel a img {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel a {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .csaas-custom-icon {display:block; width: "+widgetSize+"px; height: "+widgetSize+"px; line-height: "+widgetSize+"px; font-size: "+parseInt(widgetSize/2)+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel button {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .csaas-svg {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .custom-agent-image {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .facustom-icon {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .custom-agent-image img {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .csaas-svg img {width: "+widgetSize+"px; height: "+widgetSize+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channels .csaas-channel .csaas-svg .csaas-custom-channel-icon {width: "+widgetSize+"px; height: "+widgetSize+"px; line-height: "+widgetSize+"px; display: block; font-size:"+(parseInt(widgetSize/2))+"px; }"; var wp_bottom_size = widgetSize + 15 + 5; advanceCustomCSS += ".csaas-outer-forms.active { bottom: "+ wp_bottom_size +"px; }"; if(jQuery("input[name='chaty_icons_view']:checked").val() == "horizontal" && jQuery("input[name='cta_type']:checked").val() == "simple-view") { jQuery("#csaas-widget-0 .csaas-widget").addClass("hor-mode"); advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list {width: "+(activeChannels*(widgetSize+8))+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list {height: "+(widgetSize)+"px; }"; // customCSS += "#csaas-widget-0 .csaas-widget.left-position.hor-mode .csaas-channel-list {left: "+(widgetSize+8)+"px; }"; // customCSS += "#csaas-widget-0 .csaas-widget.right-position.hor-mode .csaas-channel-list {right: "+(widgetSize+8)+"px; }"; for(var i=0; i<=activeChannels; i++) { advanceCustomCSS += "#csaas-widget-0 .csaas-widget.left-position.hor-mode.csaas-open .csaas-channel-list .csaas-channel:nth-child("+(i+1)+") {-webkit-transform: translateX("+((widgetSize+8)*(activeChannels - i - extraSpace))+"px); transform: translateX("+((widgetSize+8)*(activeChannels - i - extraSpace))+"px);}"; advanceCustomCSS += "#csaas-widget-0 .csaas-widget.right-position.hor-mode.csaas-open .csaas-channel-list .csaas-channel:nth-child("+(i+1)+") {-webkit-transform: translateX(-"+((widgetSize+8)*(activeChannels - i - extraSpace))+"px); transform: translateX(-"+((widgetSize+8)*(activeChannels - i - extraSpace))+"px);}"; } } else { //customCSS += "#csaas-widget-"+widgetRecord.id+" .csaas-channel-list {bottom: "+(widgetSize+4)+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list {height: "+(activeChannels*(widgetSize+8))+"px; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-channel-list {width: "+(widgetSize+8)+"px; }"; for(var i=0; i<=activeChannels; i++) { advanceCustomCSS += "#csaas-widget-0 .csaas-open .csaas-channel-list .csaas-channel:nth-child("+(i+1)+") {-webkit-transform: translateY(-"+((widgetSize+8)*(activeChannels - i - extraSpace))+"px); transform: translateY(-"+((widgetSize+8)*(activeChannels - i - extraSpace))+"px);}"; } } /* set on hover text color */ advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip:after {background-color: "+jQuery("#cht_cta_bg_color").val()+"; color: "+jQuery("#cht_cta_text_color").val()+"}"; advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip.top:before {border-top-color: "+jQuery("#cht_cta_bg_color").val()+"; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip.left:before {border-left-color: "+jQuery("#cht_cta_bg_color").val()+"; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip.right:before {border-right-color: "+jQuery("#cht_cta_bg_color").val()+";}"; advanceCustomCSS += "#csaas-widget-0 .on-hover-text {background-color: "+jQuery("#cht_cta_bg_color").val()+"; color: "+jQuery("#cht_cta_text_color").val()+"}"; advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip.top .on-hover-text:before {border-top-color: "+jQuery("#cht_cta_bg_color").val()+"; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip.left .on-hover-text:before {border-left-color: "+jQuery("#cht_cta_bg_color").val()+"; }"; advanceCustomCSS += "#csaas-widget-0 .csaas-tooltip.right .on-hover-text:before {border-right-color: "+jQuery("#cht_cta_bg_color").val()+";}"; advanceCustomCSS += "#csaas-form-0-csaas-chat-view .csaas-view-header {background-color: "+jQuery("#cta_header_bg_color").val()+";}"; advanceCustomCSS += "#csaas-form-0-csaas-chat-view .csaas-view-header {color: "+jQuery("#cta_header_text_color").val()+";}"; advanceCustomCSS += "#csaas-form-0-csaas-chat-view .csaas-view-header .csaas-close-view-list svg {fill: "+jQuery("#cta_header_text_color").val()+";}"; /* Contact Us Button */ advanceCustomCSS += "#csaas-submit-button-0 {color: "+jQuery("#button_text_color_for_Contact_Us").val()+" !important; background: "+jQuery("#button_bg_color_for_Contact_Us").val()+" !important;}" advanceCustomCSS += ".csaas-contact-form-box .csaas-contact-form-title {background-color: "+ jQuery("#title_bg_color_for_Contact_Us").val() +";}"; updateWidgetViews(); jQuery("#custom-css").html(""); jQuery(".csaas-outer-forms, .csaas-chat-view").show(); jQuery(".csaas-outer-forms, .csaas-chat-view").addClass(widgetPosition); if(jQuery("#cht_widget_font").val() != "") { var fontFamily = jQuery("#cht_widget_font").val(); if(fontFamily == "System Stack") { fontFamily = "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"; } jQuery("#csaas-widget-0").css("font-family", fontFamily); } } } if(imageDataEvent != false && jQuery("#testUpload").val() != "" && jQuery("input[name='widget_icon']:checked").val() == "chat-image") { if(jQuery("#cta-image").length) { var output = document.getElementById('cta-image'); output.src = URL.createObjectURL(imageDataEvent.target.files[0]); output.onload = function () { URL.revokeObjectURL(output.src) // free memory //jQuery("#image-upload").addClass("has-custom-image"); } } } } function makeChatyChatView() { var widgetId = 0; var widgetIndex = 0 ; if (widgetIndex == null) { widgetIndex = -1; } var bodyMsg = htmlDecode(jQuery("#cta_body_text").val()); var headMsg = htmlDecode(jQuery("#cta_heading_text").val()); var iframeData = jQuery("#wp-cta_body_text-wrap").find("iframe"); bodyMsg = iframeData.contents().find("body").html(); var formHtml = ""; formHtml += "
"; formHtml += "
"; formHtml += "
"+headMsg; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += bodyMsg; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; jQuery("#csaas-widget-"+widgetId).append(formHtml); } function myCustomOnChangeHandler() { change_custom_preview(); } function htmlDecode(input) { var doc = new DOMParser().parseFromString(input, "text/html"); return doc.documentElement.textContent; } function updateWidgetViews() { jQuery("#csaas-widget-0").addClass("active"); } function checkForWidgetAnimation() { if(jQuery("#chaty_attention_effect").val() != "none" && jQuery("#chaty_attention_effect").val() != "") { jQuery("#csaas-widget-0").attr("data-animation", jQuery("#chaty_attention_effect").val()); if(jQuery("#csaas-widget-0 .csaas-widget").hasClass("has-single")) { jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel a").addClass("csaas-animation-"+jQuery("#chaty_attention_effect").val()); } else { jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-cta-main .csaas-cta-button").addClass("csaas-animation-"+jQuery("#chaty_attention_effect").val()); } } } function checkForPendingMessage() { if(jQuery("#cht_pending_messages").is(":checked") && jQuery("#cht_number_of_messages").val() != "") { var attention_effect = jQuery("#chaty_attention_effect").val(); if(jQuery("#csaas-widget-0 .csaas-widget").hasClass("has-single")) { if (attention_effect == "bounce" || attention_effect == "jump" || attention_effect == "waggle" || attention_effect == "pulse" || attention_effect == "pulse-icon" || attention_effect == "floating") { jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel a").append("
" + jQuery("#cht_number_of_messages").val() + "
"); } else { jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-channel a").after("
" + jQuery("#cht_number_of_messages").val() + "
"); } } else { if (attention_effect == "bounce" || attention_effect == "jump" || attention_effect == "waggle" || attention_effect == "pulse" || attention_effect == "pulse-icon" || attention_effect == "floating") { jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-cta-main .csaas-cta-button").append("
" + jQuery("#cht_number_of_messages").val() + "
"); } else { jQuery("#csaas-widget-0 .csaas-i-trigger .csaas-cta-main").append("
" + jQuery("#cht_number_of_messages").val() + "
"); } } jQuery(".ch-pending-msg").css("color", jQuery("#cht_number_color").val()); jQuery(".ch-pending-msg").css("background-color", jQuery("#cht_number_bg_color").val()); } } function getCTAWidgetIcon() { var widgetIcon = 'chat-base'; if(jQuery("input[name='widget_icon']:checked").val() != "") { widgetIcon = jQuery("input[name='widget_icon']:checked").val(); } if(widgetIcon == "chat-image") { if(jQuery("#elPreviewImage img").length) { return "
"; } widgetIcon = 'chat-base'; } return '
'+getSvgIcon(widgetIcon, jQuery("input[name='cht_color']:checked").val().toHtmlEntities())+"
"; } function getSvgIcon(iconName, widgetColor) { switch(iconName) { case"chat-smile": return '
'; case"chat-bubble": return '
'; case"chat-db": return '
'; default: return '
' } } function getChannelSetting(channel, widgetId, toolTipPosition) { var extraClass = ""; if(jQuery("#chaty-social-"+channel).hasClass("has-agent-view")) { createAgentList(channel, widgetId); channelIcon = getChannelIcon(channel, widgetId); channelLink = getChannelURL(channel, channelIcon, toolTipPosition, widgetId); return "
" + channelLink + "
"; } else { var channelIcon = getChannelIcon(channel, widgetId); var channelLink = getChannelURL(channel, channelIcon, toolTipPosition, widgetId); return "
" + channelLink + "
"; } } function createAgentList(channel, widgetId) { var isDesktop = jQuery("#previewDesktop").is(":checked")?true:false; var formHtml = ""; var widgetIndex = 0; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; if(!isEmpty(jQuery("#cht_social_agent_title_"+channel).val())) { formHtml += "
"+jQuery("#cht_social_agent_title_"+channel).val().toHtmlEntities()+"
"; } if(!isEmpty(jQuery("#cht_social_agent_sub_title_"+channel).val())) { formHtml += "
"+jQuery("#cht_social_agent_sub_title_"+channel).val().toHtmlEntities()+"
"; } formHtml += "
"; if(jQuery("#chaty-social-"+channel+" .chaty-agent-list .agent-list .agent-channel-setting").length) { jQuery("#chaty-social-"+channel+" .chaty-agent-list .agent-list .agent-channel-setting").each(function(){ var thisIndex = jQuery(this).data("item"); //if((isDesktop && jQuery("#"+channel+"Desktop-"+thisIndex).is(":checked")) || (!isDesktop && jQuery("#"+channel+"Mobile-"+thisIndex).is(":checked"))) { var agentIcon = jQuery("#image_agent_data_" + channel + "-" + thisIndex).html(); if (jQuery("#image_agent_data_" + channel + "-" + thisIndex).hasClass("img-active")) { agentIcon = "
" + agentIcon + "
"; } else if (jQuery("#image_agent_data_" + channel + "-" + thisIndex).hasClass("icon-active")) { agentIcon = "
" + agentIcon + "
"; } else { agentIcon = "
" + agentIcon + "
"; } var agentLink = getAgentURL(channel, widgetId, thisIndex, agentIcon, jQuery("#agent-" + channel + "-" + thisIndex + " .chaty-agent-name").val().toHtmlEntities()); formHtml += "
" + agentLink + "
"; //} }); } formHtml += "
"; formHtml += "
"; formHtml += "
"; jQuery(".chaty-preview").append(formHtml); jQuery(".csaas-agent-header.agent-info-"+widgetId+"-"+channel).css("background", jQuery("#agent_head_bg_color_"+channel).val()); jQuery(".csaas-agent-header.agent-info-"+widgetId+"-"+channel).css("color", jQuery("#agent_head_text_color_"+channel).val()); } function getAgentURL(channel, widgetId, key, agentIcon, agentTitle) { return "
"+agentIcon+"
"+agentTitle+"
"; } function getChannelIcon(channel, widgetId) { if(!jQuery("#chaty-social-"+channel).hasClass("has-agent-view")) { if (jQuery("#chaty_image_" + channel).length) { var widgetIcon = jQuery("#chaty_image_" + channel).html(); if (jQuery("#chaty_image_" + channel).hasClass("icon-active")) { return "
" + widgetIcon + "
"; } else if (jQuery("#chaty_image_" + channel).hasClass("img-active")) { return "
" + widgetIcon + "
"; } return "
" + widgetIcon + "
"; } } else { if (jQuery("#image_agent_data_agent-" + channel).length) { var widgetIcon = jQuery("#image_agent_data_agent-" + channel).html(); if (jQuery("#image_agent_data_agent-" + channel).hasClass("icon-active")) { return "
" + widgetIcon + "
"; } else if (jQuery("#image_agent_data_agent-" + channel).hasClass("img-active")) { return "
" + widgetIcon + "
"; } return "
" + widgetIcon + "
"; } } } function getChannelURL(channel, channelIcon, toolTipPosition, widgetId) { var extraClass = ""; if(!jQuery("#chaty-social-"+channel).hasClass("has-agent-view")) { if (channel == "Whatsapp") { if (jQuery("#chaty-social-"+channel+" .embedded_window-checkbox").is(":checked") &&jQuery("#chaty-social-"+channel+" .chaty-whatsapp-setting-textarea").val() != "") { extraClass += " has-csaas-box csaas-whatsapp-form"; startMakingWhatsAppPopup(channel, widgetId); } } else if(channel == "WeChat") { if(jQuery(".remove-qr-code-"+channel).hasClass("active")) { extraClass += " has-csaas-box csaas-qr-code-form"; startMakingWeChatChannel(channel, 0); } } else if(channel == "Contact_Us") { extraClass += " has-csaas-box csaas-contact-us-form"; startMakingContactForm(channel, 0); } } if(!jQuery("#chaty-social-"+channel).hasClass("has-agent-view")) { return "
" + channelIcon + "
"; } else { return "
" + channelIcon + "
"; } } /** * Convert a string to HTML entities */ String.prototype.toHtmlEntities = function() { return this.replace(/./gm, function(s) { // return "" + s.charCodeAt(0) + ";"; return (s.match(/[a-z0-9\s]+/i)) ? s : "" + s.charCodeAt(0) + ";"; }); }; /** * Create string from HTML entities */ String.fromHtmlEntities = function(string) { return (string+"").replace(/\d+;/gm,function(s) { return String.fromCharCode(s.match(/\d+/gm)[0]); }) }; function startMakingContactForm(channel, widgetId) { var formHtml = ""; var widgetIndex = 0; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; //formHtml += "
"; formHtml += "
"; formHtml += "
"+jQuery("#cht_social_message_"+channel+"_form_title").val().toHtmlEntities()+"
"; formHtml += "
"; // if(jQuery("#field_for_Contact_Us_name").is(":checked")) { // formHtml += "
"; // formHtml += "
"; // formHtml += "
"; // } // if(jQuery("#field_for_Contact_Us_email").is(":checked")) { // formHtml += "
"; // formHtml += "
"; // formHtml += "
"; // } // if(jQuery("#field_for_Contact_Us_phone").is(":checked")) { // formHtml += "
"; // formHtml += "
"; // formHtml += "
"; // } // if(jQuery("#field_for_Contact_Us_message").is(":checked")) { // formHtml += "
"; // formHtml += "
</textarea>"; // formHtml += "
"; // } jQuery("#chaty-social-Contact_Us .contact_form_custom_value").each(function (){ if(jQuery(this).closest(".field-setting-col").find(".chaty-switch input[type='checkbox']").is(":checked")) { formHtml += "
"; formHtml += "
"+jQuery(this).closest(".field-setting-col").find(".label-input input").val()+"
" formHtml += "
"; formHtml += "
" if (jQuery(this).data("type") == "textarea") { formHtml += "
</textarea>"; } else if (jQuery(this).data("type") == "select") { formHtml += "
"+ jQuery(this).find("option:first-child").text() +"
" } else { formHtml += "
"; } formHtml += "
"; } }); /*$.each(channel.contact_fields, function (key, contactField) { formHtml += "
"; var isRequired = isTrue(contactField.is_required)?"is-required":""; if(contactField.type == "textarea") { formHtml += "
</textarea>" } else { formHtml += "
" } formHtml += "
"; });*/ formHtml += "
"+jQuery("#button_text_for_"+channel).val().toHtmlEntities()+"
"; formHtml += "
"; // csaas-contact-inputs formHtml += "
"; // csaas-contact-form-body //formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; jQuery(".chaty-preview").append(formHtml); } function startMakingWeChatChannel(channel, widgetId) { var formHtml = ""; var widgetIndex = 0; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; jQuery(".chaty-preview").append(formHtml); } function startMakingWhatsAppPopup(channel, widgetId) { const currentDate = new Date(); var currentMinute = (currentDate.getMinutes() < 10) ? "0"+currentDate.getMinutes() : currentDate.getMinutes(); var currentHour = (currentDate.getHours() < 10) ? "0"+currentDate.getHours() : currentDate.getHours(); const time = currentHour + ":" + currentMinute; var formHtml = ""; var widgetIndex = widgetId; var formAction = ""; var formTarget = ""; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += "
"; formHtml += '
'; formHtml += "
"; formHtml += "
"; formHtml += jQuery("#wp_popup_headline").val().toHtmlEntities(); formHtml += "
"; formHtml += "
"; formHtml += '
'; formHtml += "
"; formHtml += "
"; formHtml += "
"; if(jQuery("#wp_popup_profile").val() != "") { formHtml += "
"; formHtml += "
" formHtml += "
"; } formHtml += "
"; formHtml += "
"+jQuery("#wp_popup_nickname").val().toHtmlEntities()+"
"; formHtml += "
"; formHtml += "
"+time+"
" formHtml += "
"; formHtml += "
"; formHtml += ""; formHtml += "
"; formHtml += "
"; jQuery(".chaty-preview").append(formHtml); jQuery("#csaas-form-"+widgetId+"-"+channel+" .csaas-whatsapp-message .csaas-whatsapp-message-content").html(jQuery(".chaty-whatsapp-setting-textarea").val()); var preSetMessage = jQuery(".pre-set-message-whatsapp").val(); if(!isEmpty(preSetMessage)) { var preSetMessage = jQuery(".pre-set-message-whatsapp").val().toHtmlEntities(); jQuery("#csaas-form-"+widgetId+"-"+channel+" .csass-whatsapp-input").val(preSetMessage); } if(isEmpty(jQuery(".chaty-whatsapp-setting-textarea").val())) { jQuery("#csaas-form-"+widgetId+"-"+channel+" .wp-profile-img").remove(); jQuery("#csaas-form-"+widgetId+"-"+channel+" .csaas-whatsapp-message").remove(); } jQuery("#chaty-form-"+widgetId+"-"+channel).show(); jQuery("#csaas_whatsapp_input").attr("placeholder", jQuery(".whatsapp-placeholder").val()); if(jQuery(".whatsapp-emoji").is(":checked")) { jQuery(".csaas-whatsapp-field").addClass("has-emoji"); } else { jQuery(".csaas-whatsapp-field").removeClass("has-emoji"); } } function isEmpty(varVal) { if(varVal == null || varVal == "" || jQuery.trim(varVal) == "" ) { return true } return false; } function getWidgetPosition() { if(jQuery("input[name='cht_position']:checked").val() == "custom") { if(jQuery("input[name='positionSide']:checked").val() == "left") { return "left"; } } else if(jQuery("input[name='cht_position']:checked").val() == "left") { return "left"; } return "right"; } function getToolTipPosition() { var widgetPos = getWidgetPosition(); if(jQuery("input[name='chaty_icons_view']:checked").val() == "vertical") { return (widgetPos == "right")?"left":"right"; } else if(previewChannelList.length > 1) { return "top"; } return (widgetPos == "right")?"left":"right"; } function getActiveChannels() { var channelCount = 0; if(jQuery("#channels-selected-list > li:not(.chaty-cls-setting)").length) { var isDesktop = jQuery("#previewDesktop").is(":checked")?true:false; jQuery("#channels-selected-list > li:not(.csaas-cls-setting)").each(function(){ if(jQuery(this).hasClass("has-agent-view")) { if(isDesktop && jQuery(this).find(".agent-desktop-device").is(":checked")) { previewChannelList.push(jQuery(this).data("id")); channelCount++; } else if(!isDesktop && jQuery(this).find(".agent-mobile-device").is(":checked")) { channelCount++; previewChannelList.push(jQuery(this).data("id")); } } else { if(isDesktop && jQuery(this).find(".js-chanel-desktop").is(":checked")) { channelCount++; previewChannelList.push(jQuery(this).data("id")); } else if(!isDesktop && jQuery(this).find(".js-chanel-mobile").is(":checked")) { channelCount++; previewChannelList.push(jQuery(this).data("id")); } } }); } return channelCount; }