1(function (factory) { 2 "use strict"; 3 if (typeof define === 'function' && define.amd) { 4 define(['jquery'], factory); 5 } else if (typeof module !== 'undefined' && module.exports) { 6 module.exports = factory(require('jquery')); 7 } else { 8 factory(jQuery); 9 } 10}(function ($, undefined) { 11 var widgetData = []; 12 var clientCountry = ''; 13 var isChatyInMobile = (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.
13substr(0, 4))) ? 1 : 0; 14 var defaultFontFamily = ["System Stack", "Arial", "Tahoma", "Verdana", "Helvetica", "Times New Roman", "Trebuchet MS", "Georgia", "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"]; 15 var chatyEnv = 'dev'; // change it to 'app' to remove log from console 16 var isBoatUser = false; 17 /** 18 * 19 * Trigger Variables 20 * 21 **/ 22 var chatyHasTimeDelay = false; 23 var chatyMaxTimeInterval = 0; 24 var chatyHasPageScroll = false; 25 var chatyHasExitIntent = false; 26 var chatyPageScrolls = []; 27 var chatyTimeInterval; 28 var chatyIntervalTime = 0; 29 var lastScrollPer = 0; 30 var customExtraCSS = ""; 31 var chatyHideTimeInterval; 32 var chatyHideIntervalTime = 0; 33 var ariaLabel = ""; 34 35 function checkForChatySettings() { 36 chatyInterval = setInterval(function () { 37 if (typeof(chaty_settings) == "object") { 38 clearInterval(chatyInterval); 39 if (typeof chaty_settings == "object" && chaty_settings.data_analytics_settings != "on" || chaty_settings.data_analytics_settings == "off") { 40 isBoatUser = true; 41 } 42 widgetData = chaty_settings.chaty_widgets; 43 checkForCountry(); 44 } 45 }, 1000) 46 } 47 48 49 $(document).ready(function () { 50 var botPattern = "(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)"; 51 var re = new RegExp(botPattern, 'i'); 52 var userAgent = navigator.userAgent; 53 if (re.test(userAgent)) { 54 isBoatUser = true; 55 } 56 57 if(isChatyInMobile) { 58 $("body").addClass("cht-in-mobile"); 59 } else { 60 $("body").addClass("cht-in-desktop"); 61 } 62 63 if (typeof chaty_settings == "undefined") { 64 console.log("Chaty settings doesn't exists"); 65 // check for chaty settings in case of JS Deferred 66 checkForChatySettings() 67 } else if (chaty_settings.chaty_widgets.length == 0) { 68 console.log("Chaty widget doesn't exists"); 69 } else { 70 widgetData = chaty_settings.chaty_widgets; 71 checkForCountry(); 72 73 if (typeof chaty_settings == "object" && chaty_settings.data_analytics_settings != "on" || chaty_settings.data_analytics_settings == "off") { 74 isBoatUser = true; 75 } 76 } 77 78 if($(window).height() > $(window).width()) { 79 $("body").addClass("cht-portrait").removeClass("cht-landscape"); 80 } else { 81 $("body").addClass("cht-landscape").removeClass("cht-portrait"); 82 } 83 84 $(document).on("click", "html, body", function (e) { 85 if($(".chaty-popup-whatsapp-form.active").length) { 86 $(".chaty-popup-whatsapp-form.active").each(function(){ 87 var widgetId = $(this).data("widget"); 88 var clickStatus = checkChatyCookieExpired(widgetId, "c-Whatsapp"); 89 if ((!isEmpty(widgetId) || widgetId == 0) && clickStatus) { 90 saveChatyCookieString(widgetId, "c-Whatsapp"); 91 } 92 }) 93 } 94 $(".form-open").removeClass("form-open"); 95 $(".chaty-outer-forms").removeClass("active"); 96 $(".chaty .chaty-widget.chaty-no-close-button:not(.has-single)").addClass("chaty-open"); 97 if($(".chaty .chaty-widget").hasClass("chaty-open")) { 98 $(".chaty .chaty-widget:not(.chaty-no-close-button)").removeClass("chaty-open"); 99 $("body").removeClass("add-bg-blur-effect"); 100 } 101 $("body").removeClass("add-bg-blur-effect"); 102 chatySetCookie("hide-bg-blur-effect", true, 365); 103 hideDefaultOpenWidgets(); 104 }); 105 106 $(document).on("click", ".chaty, .chaty-outer-forms", function (e) { 107 e.stopPropagation(); 108 }); 109 110 $(document).on("click", ".chaty.form-open .chaty-i-trigger.single-channel a", function (e) { 111 $("body").removeClass("add-bg-blur-effect"); 112 }); 113 114 $(document).on("click", ".chaty.form-open .chaty-i-trigger.single-channel .chaty-cta-close", function (e) { 115 $("body").removeClass("add-bg-blur-effect"); 116 }); 117 118 $(document).on("click", ".chaty-close-view-list", function(){ 119 $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open"); 120 $("body").removeClass("add-bg-blur-effect"); 121 chatySetCookie("hide-bg-blur-effect", true, 365); 122 hideDefaultOpenWidgets(); 123 }); 124 125 $(document).on("submit", ".whatsapp-chaty-form", function () { 126 if ($(this).hasClass("form-google-analytics")) { 127 var widgetChannel = "Whatsapp"; 128 if (window.hasOwnProperty("gtag")) { 129 gtag("event", "chaty_" + widgetChannel, { 130 eventCategory: "chaty_" + widgetChannel, 131 event_action: "chaty_" + widgetChannel, 132 method: "chaty_" + widgetChannel 133 }); 134 } 135 if (window.hasOwnProperty("ga")) { 136 var ga_settings = window.ga.getAll()[0]; 137 ga_settings && ga_settings.send("event", "click", { 138 eventCategory: "chaty_" + widgetChannel, 139 eventAction: "chaty_" + widgetChannel, 140 method: "chaty_" + widgetChannel 141 }) 142 } 143 } 144 var widgetId = $(this).data('widget'); 145 var chatyChannel = $(this).data('channel'); 146 var clickStatus = checkChatyCookieExpired(widgetId, "c-" + chatyChannel); 147 148 if ((!isEmpty(widgetId) || widgetId == 0) && clickStatus) { 149 saveChatyCookieString(widgetId, "c-" + chatyChannel); 150 var widgetNonce = $("#chaty-widget-" + widgetId).data("nonce"); 151 if (!isBoatUser) { 152 $.ajax({
153 url: chaty_settings.ajax_url, 154 data: { 155 widgetId: widgetId, 156 userId: widgetId, 157 isMobile: isChatyInMobile, 158 channel: chatyChannel, 159 nonce: widgetNonce, 160 action: 'update_chaty_channel_click' 161 }, 162 dataType: 'json', 163 method: 'post', 164 }); 165 } 166 } 167 168 if ($("#chaty-widget-" + widgetId).length) { 169 $("#chaty-widget-" + widgetId).removeClass("form-open"); 170 $(this).closest(".chaty-outer-forms").removeClass("active"); 171 if ($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("cssas-no-close-button")) { 172 $("#chaty-widget-" + widgetId).find(".chaty-widget:not(.has-single)").addClass("chaty-open") 173 } 174 } 175 if($("body").hasClass("add-bg-blur-effect")) { 176 $("body").removeClass("add-bg-blur-effect"); 177 hideDefaultOpenWidgets(); 178 } 179 }); 180 181 $(document).on("click", ".chaty-close-button, .chaty-close-agent-list, .whatsapp-form-close-btn", function (e) { 182 e.preventDefault(); 183 e.stopPropagation(); 184 var widgetId = $(this).closest(".chaty-outer-forms").data('widget'); 185 if (!isEmpty(widgetId) || widgetId == 0) { 186 if ($("#chaty-widget-" + widgetId).length) { 187 $("#chaty-widget-" + widgetId).removeClass("form-open"); 188 $(this).closest(".chaty-outer-forms").removeClass("active"); 189 if ($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("chaty-no-close-button")) { 190 $("#chaty-widget-" + widgetId).find(".chaty-widget:not(.has-single)").addClass("chaty-open"); 191 } 192 } 193 if ($(this).closest(".chaty-whatsapp-btn-form").length) { 194 var dataChannel = $(this).closest(".chaty-outer-forms").data('channel'); 195 if (!isEmpty(dataChannel)) { 196 var clickStatus = checkChatyCookieExpired(widgetId, "c-" + dataChannel); 197 if (clickStatus) { 198 saveChatyCookieString(widgetId, "c-" + dataChannel); 199 } 200 } 201 var visibleStatus = checkChatyCookieExpired(widgetId, 'v-widget'); 202 if (visibleStatus) { 203 updateWidgetViews(widgetId); 204 } 205 } 206 207 if($(this).hasClass("whatsapp-form-close-btn")) { 208 clickStatus = checkChatyCookieExpired(widgetId, "c-Whatsapp"); 209 if ((!isEmpty(widgetId) || widgetId == 0) && clickStatus) { 210 saveChatyCookieString(widgetId, "c-Whatsapp"); 211 } 212 } 213 } 214 $("body").removeClass("add-bg-blur-effect"); 215 }); 216 217 $(document).on("keypress", '.chaty-contact-input input[type="tel"]', function(e) { 218 var charCode = (e.which) ? e.which : e.keyCode; 219 // ascii code for 0-9 digits and comma 220 if(charCode == 43 && $(this).val() == "") { 221 return true; 222 } 223 if(charCode >= 48 && charCode <= 57) { 224 return true; 225 } 226 return false; 227 }); 228 229 $(document).on("change", '.chaty-contact-input input[type="tel"]', function (){ 230 var regex = new RegExp(/^(\+)?\d*$/); 231 var phone_number = $(this).val(); 232 233 if (!regex.test(phone_number)) { 234 $(this).val(""); 235 } 236 }); 237 238 $(document).on("click", "a.chaty-qr-code-form", function (e) { 239 e.preventDefault(); 240 // e.stopPropagation(); 241 var dataForm = $(this).data('form'); 242 if (!isEmpty(dataForm)) { 243 if ($("#" + dataForm).length) { 244 var buttonHtml = $(this).html(); 245 246 if($("#" + dataForm).hasClass("active")) { 247 $(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open"); 248 $(this).closest(".chaty").removeClass("form-open"); 249 $("#" + dataForm).removeClass("active"); 250 $("body").removeClass("add-bg-blur-effect"); 251 } else { 252 $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open"); 253 $(this).closest(".chaty").addClass("form-open"); 254 $("#" + dataForm).addClass("active"); 255 buttonHtml = $(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html(); 256 $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml); 257 } 258 } 259 } 260 }); 261 262 $(document).on("click", "a.chaty-contact-us-form", function (e) { 263 e.preventDefault(); 264 // e.stopPropagation(); 265 var dataForm = $(this).data('form'); 266 if (!isEmpty(dataForm)) { 267 if ($("#" + dataForm).length) { 268 269 if(googleV3Token != "") { 270 googleV3Token = ""; 271 refreshG3Token(); 272 } 273 274 if($("#" + dataForm).hasClass("active")) { 275 $(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open"); 276 $(this).closest(".chaty").removeClass("form-open"); 277 $("#" + dataForm).removeClass("active"); 278 $("body").removeClass("add-bg-blur-effect"); 279 280 } else { 281 $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open"); 282 $(this).closest(".chaty").addClass("form-open"); 283 $("#" + dataForm).addClass("active"); 284 $("#" + dataForm).find(".chaty-ajax-success-message").remove(); 285 $("#" + dataForm).find(".chaty-ajax-error-message").remove(); 286 $("#" + dataForm).find(".has-chaty-error").removeClass("has-chaty-error"); 287 buttonHtml = $(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html(); 288 $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml); 289 } 290 } 291 } 292 }); 293 294 $(document).on("click", "a.chaty-whatsapp-btn-form", function (e) { 295 e.preventDefault(); 296 // e.stopPropagation(); 297 var dataForm = $(this).data('form'); 298 if (!isEmpty(dataForm)) { 299 if ($("#" + dataForm).length) { 300 //$("#" + dataForm).addClass("is-active"); 301 if($("#" + dataForm).hasClass("active")) { 302 $(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open"); 303 $(this).closest(".chaty").removeClass("form-open"); 304 $("#" + dataForm).removeClass("active"); 305 $("body").removeClass("add-bg-blur-effect"); 306 setTimeout(function(){ 307 $("body").removeClass("add-bg-blur-effect"); 308 }, 100); 309 } else { 310 $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open"); 311 $(this).closest(".chaty").addClass("form-open"); 312 $("#" + dataForm).addClass("active"); 313 var buttonHtml = $(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html(); 314 $(this).closest(".chaty").find(".chaty-widget").find(".open-chaty-channel").html(buttonHtml); 315 } 316 setTimeout(function(){ 317 $(".chaty-whatsapp-btn-form.active .chaty-whatsapp-input").focus(); 318 }, 100); 319 } 320 } 321 }); 322 323 $(document).on("click", ".chaty-channel.chaty-agent-button", function (e) { 324 e.preventDefault(); 325 // e.stopPropagation(); 326 var dataForm = $(this).data('form'); 327 if (!isEmpty(dataForm)) { 328 if ($("#" + dataForm).length) { 329 if (!$(this).closest(".chaty").find(".chaty-widget").hasClass("has-single")) { 330 var buttonHtml = $(this).html(); 331 $("#" + dataForm).addClass("is-active"); 332 333 $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open"); 334 $(this).closest(".chaty").addClass("form-open"); 335 $("#" + dataForm).addClass("active"); 336 buttonHtml = $(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html(); 337 $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml); 338 } else { 339 if ($(this).closest(".chaty").hasClass("form-open")) { 340 $(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open"); 341 $(this).closest(".chaty").removeClass("form-open"); 342 $("#" + dataForm).removeClass("active"); 343 $("body").removeClass("add-bg-blur-effect"); 344 } else { 345 buttonHtml = $(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html(); 346 $("#" + dataForm).addClass("is-active"); 347 348 $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open"); 349 $(this).closest(".chaty").addClass("form-open"); 350 $("#" + dataForm).addClass("active"); 351 352 $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml); 353 } 354 } 355 } 356 } 357 358 }); 359 360 /* track google analytics event */ 361 $(document).on("click", ".chaty-channel a.has-gae", function (e) { 362 var widgetChannel = $(this).closest(".chaty-channel").data("channel"); 363 if (widgetChannel !== undefined && widgetChannel != "" && widgetChannel != null) { 364 if (window.hasOwnProperty("gtag")) { 365 gtag("event", "chaty_" + widgetChannel, { 366 eventCategory: "chaty_" + widgetChannel, 367 event_action: "chaty_" + widgetChannel, 368 method: "chaty_" + widgetChannel 369 }); 370 } 371 if (window.hasOwnProperty("ga")) { 372 var ga_settings = window.ga.getAll()[0]; 373 ga_settings && ga_settings.send("event", "click", { 374 eventCategory: "chaty_" + widgetChannel, 375 eventAction: "chaty_" + widgetChannel, 376 method: "chaty_" + widgetChannel 377 }) 378 } 379 } 380 }); 381 382 $(document).on("mouseover", ".chaty-widget.has-single .chaty-channel a.has-on-hover[data-hover]", function () { 383 $(this).find(".on-hover-text").html($(this).data("hover")); 384 }).on("mouseleave", ".chaty-widget.has-single .chaty-channel a.has-on-hover[data-text]", function () { 385 $(this).find(".on-hover-text").html($(this).data("text")); 386 }); 387 388 $(document).on("submit", ".whatsapp-chaty-form.has-form-gae", function(){ 389 var widget_id = $(this).data("widget"); 390 var widgetChannel = $("#Whatsapp-"+ widget_id +"-channel").data("channel"); 391 if (widgetChannel !== undefined && widgetChannel != "" && widgetChannel != null) { 392 if (window.hasOwnProperty("gtag")) { 393 gtag("event", "chaty_whatsapp_redirect", { 394 eventCategory: "chaty_whatsapp_redirect", 395 event_action: "chaty_whatsapp_redirect", 396 method: "chaty_whatsapp_redirect" 397 }); 398 } 399 if (window.hasOwnProperty("ga")) { 400 var ga_settings = window.ga.getAll()[0]; 401 ga_settings && ga_settings.send("event", "click", { 402 eventCategory: "chaty_whatsapp_redirect", 403 eventAction: "chaty_whatsapp_redirect", 404 method: "chaty_whatsapp_redirect" 405 }) 406 } 407 } 408 }); 409 410 /* toggle widget on CTA button click */ 411 $(document).on("click", ".chaty-i-trigger:not(.single-channel)", function () { 412 if ($(this).closest(".chaty").hasClass("form-open")) { 413 $(this).closest(".chaty").removeClass("form-open"); 414 $(this).closest(".chaty-widget:not(.has-single)").addClass("chaty-open"); 415 416 } else { 417 $(this).closest(".chaty-widget").toggleClass("chaty-open"); 418 } 419 $(".chaty-outer-forms.active").each(function(){ 420 $(this).removeClass("active"); 421 var widgetID = $(this).data("widget"); 422 $("#chaty-widget-"+widgetID).removeClass("form-open"); 423 }); 424 if ($(this).closest(".chaty").find(".chaty-widget").hasClass("chaty-no-close-button")) { 425 $(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open"); 426 } 427 }); 428 429 $(document).on("click", ".chaty-i-trigger.single-channel .chaty-cta-close", function () { 430 if ($(this).closest(".chaty").hasClass("form-open")) { 431 $(this).closest(".chaty").removeClass("form-open"); 432 433 var chatyWidgetId = $(this).closest(".chaty").data("id"); 434 if($("#chaty-form-"+chatyWidgetId+"-Whatsapp").length && $("#chaty-form-"+chatyWidgetId+"-Whatsapp").hasClass("active")) { 435 clickStatus = checkChatyCookieExpired(chatyWidgetId, "c-Whatsapp"); 436 if ((!isEmpty(chatyWidgetId) || chatyWidgetId == 0) && clickStatus) { 437 saveChatyCookieString(chatyWidgetId, "c-Whatsapp"); 438 } 439 } 440 } 441 $(".chaty-outer-forms.active").each(function(){ 442 $(this).removeClass("active"); 443 var widgetID = $(this).data("widget"); 444 $("#chaty-widget-"+widgetID).removeClass("form-open"); 445 }); 446 }); 447 448 /* Open widget on hover */ 449 if (!isChatyInMobile) { 450 $(document).on("mouseover", "body:not(.chaty-in-mobile) .chaty.open-on-hover .chaty-i-trigger:not(.single-channel)", function () { 451 if (!$(this).closest(".chaty-widget").hasClass("chaty-open") && !$(this).closest(".chaty-widget").hasClass("on-chaty-widget")) { 452 $(this).closest(".chaty-widget").addClass("on-chaty-widget"); 453 $(this).find(".chaty-cta-main").trigger("click"); 454 } 455 }).on("mouseleave", "body:not(.chaty-in-mobile) .chaty.open-on-hover .chaty-i-trigger:not(.single-channel)", function () { 456 if (!$(this).closest(".chaty-widget").hasClass("chaty-open")) { 457 $(this).closest(".chaty-widget").removeClass("on-chaty-widget") 458 } 459 }); 460 } 461 462 /* Remove active class for CTA button */ 463 $(document).on("click", ".chaty-channel.single a", function(){ 464 var chatyWidgetId = $(this).closest(
464".chaty").data("id"); 465 if($(this).closest(".chaty").hasClass("first_click")) { 466 //saveChatyCookieString(chatyWidgetId, "c-widget"); 467 $(this).closest(".chaty-channel").removeClass("active"); 468 } 469 removeChatyAnimation(chatyWidgetId); 470 }); 471 472 /* check for channel or widget click event */ 473 $(document).on("click", ".chaty-channel a, .chaty-channel button", function (e) { 474 // return; 475 var clickStatus; 476 var chatyChannel; 477 var chatyChannels = []; 478 var isSingle = 0; 479 var chatyWidgetIdentifier; 480 var chatyWidgetId = $(this).closest(".chaty").data("id"); 481 if (typeof chatyWidgetId != 'undefined') { 482 chatyWidgetIdentifier = $("#chaty-widget-" + chatyWidgetId).data("identifier"); 483 if (typeof chatyWidgetIdentifier != 'undefined') { 484 var userId = $("#chaty-widget-" + chatyWidgetId).data("user"); 485 removeChatyAnimation(chatyWidgetId); 486 if ($(this).closest(".chaty-channel").hasClass("chaty-cta-main") || $(this).closest(".chaty-channel").hasClass("chaty-cta-close")) { 487 if($("#chaty-form-"+chatyWidgetId+"-Whatsapp").length && $("#chaty-form-"+chatyWidgetId+"-Whatsapp").hasClass("active")) { 488 clickStatus = checkChatyCookieExpired(chatyWidgetId, "c-Whatsapp"); 489 if ((!isEmpty(chatyWidgetId) || chatyWidgetId == 0) && clickStatus) { 490 saveChatyCookieString(chatyWidgetId, "c-Whatsapp"); 491 } 492 } 493 clickStatus = checkChatyCookieExpired(chatyWidgetId, 'c-widget'); 494 $("#chaty-widget-" + chatyWidgetId).find(".ch-pending-msg").remove(); 495 if (clickStatus) { 496 saveChatyCookieString(chatyWidgetId, "c-widget"); 497 if ($(this).closest(".chaty-channel").hasClass("chaty-cta-main")) { 498 chatyChannels = []; 499 if($("#chaty-widget-" + chatyWidgetId).hasClass("chaty-has-chat-view")) { 500 $(".chaty-chat-view.chaty-chat-view-" + chatyWidgetId + " .chaty-view-channels").find(".chaty-channel").each(function () { 501 chatyChannel = $(this).data("channel"); 502 clickStatus = checkChatyCookieExpired(chatyWidgetId, "v-" + chatyChannel); 503 if (clickStatus && typeof chatyChannel != 'undefined') { 504 saveChatyCookieString(chatyWidgetId, "v-" + chatyChannel); 505 chatyChannels.push(chatyChannel); 506 } 507 }); 508 } else { 509 $("#chaty-widget-" + chatyWidgetId + " .chaty-channel-list").find(".chaty-channel").each(function () { 510 chatyChannel = $(this).data("channel"); 511 clickStatus = checkChatyCookieExpired(chatyWidgetId, "v-" + chatyChannel); 512 if (clickStatus && typeof chatyChannel != 'undefined') { 513 saveChatyCookieString(chatyWidgetId, "v-" + chatyChannel); 514 chatyChannels.push(chatyChannel); 515 } 516 }); 517 } 518 var widgetNonce = $("#chaty-widget-" + chatyWidgetId).data("nonce"); 519 if (!isBoatUser) { 520 $.ajax({
521 url: chaty_settings.ajax_url, 522 data: { 523 widgetId: chatyWidgetId, 524 userId: userId, 525 isMobile: isChatyInMobile, 526 channels: chatyChannels, 527 isSingle: 0, 528 nonce: widgetNonce, 529 action: 'update_chaty_widget_click' 530 }, 531 dataType: 'json', 532 method: 'post', 533 }); 534 } 535 } 536 } 537 if ($("#chaty-widget-" + chatyWidgetId).hasClass("first_click")) { 538 $("#chaty-widget-" + chatyWidgetId + " .chaty-cta-main").removeClass("active"); 539 $("#chaty-widget-" + chatyWidgetId + " .chaty-cta-main").removeClass("chaty-tooltip"); 540 } 541 } else if ($(this).closest(".chaty-channel").hasClass("single")) { 542 $("#chaty-widget-" + chatyWidgetId).find(".ch-pending-msg").remove(); 543 clickStatus = checkChatyCookieExpired(chatyWidgetId, 'c-widget'); 544 var widgetNonce = $("#chaty-widget-" + chatyWidgetId).data("nonce") 545 if (clickStatus) { 546 saveChatyCookieString(chatyWidgetId, 'c-widget'); 547 isSingle = 0; 548 chatyChannels = []; 549 chatyChannel = $(this).closest(".chaty-channel").data("channel"); 550 clickStatus = checkChatyCookieExpired(chatyWidgetId, "c-" + chatyChannel); 551 if (clickStatus) { 552 chatyChannels.push(chatyChannel); 553 isSingle = 1; 554 } 555 if (!isBoatUser) { 556 $.ajax({
557 url: chaty_settings.ajax_url, 558 data: { 559 widgetId: chatyWidgetId, 560 userId: userId, 561 isMobile: isChatyInMobile, 562 channels: chatyChannels, 563 isSingle: isSingle, 564 nonce: widgetNonce, 565 action: 'update_chaty_widget_click' 566 }, 567 dataType: 'json', 568 method: 'post', 569 }); 570 } 571 } 572 573 /* checking for CTA status */ 574 if ($("#chaty-widget-" + chatyWidgetId).hasClass("first_click")) { 575 $("#chaty-widget-" + chatyWidgetId + " .chaty-tooltip").removeClass("chaty-tooltip"); 576 $("#chaty-widget-" + chatyWidgetId + " .single-channel a").addClass("chaty-tooltip"); 577 } 578 } else if ($(this).hasClass("chaty-link")) { 579 chatyChannel = $(this).closest(".chaty-channel").data("channel"); 580 console.log(chatyChannel) 581 clickStatus = checkChatyCookieExpired(chatyWidgetId, "c-" + chatyChannel); 582 if (clickStatus) { 583 saveChatyCookieString(chatyWidgetId, "c-" + chatyChannel); 584 var widgetNonce = $("#chaty-widget-" + chatyWidgetId).data("nonce"); 585 if (!isBoatUser) { 586 $.ajax({
587 url: chaty_settings.ajax_url, 588 data: { 589 widgetId: chatyWidgetId, 590 userId: userId, 591 isMobile: isChatyInMobile, 592 channel: chatyChannel, 593 nonce: widgetNonce, 594 action: 'update_chaty_channel_click' 595 }, 596 dataType: 'json', 597 method: 'post', 598 }); 599 } 600 } 601 } 602 } 603 } 604 }); 605 606 $(document).on("submit", ".chaty-ajax-contact-form", function (e) { 607 e.preventDefault(); 608 var inputErrorCounter = 0; 609 $(this).find(".has-chaty-error").each(function () { 610 $(this).removeClass("has-chaty-error"); 611 }); 612 $(this).find(".chaty-error-msg").remove(); 613 $(this).find(".chaty-ajax-error-message").remove(); 614 $(this).find(".chaty-ajax-success-message").remove(); 615 $(this).find(".is-required").each(function () { 616 if (jQuery.trim($(this).val()) == "") { 617 inputErrorCounter++; 618 $(this).addClass("has-chaty-error"); 619 if($(this).hasClass("chaty-text-block")) { 620 $(this).closest(".chaty-contact-input").find(".mce-tinymce").addClass("mce-error"); 621 } 622 } 623 }); 624 if (inputErrorCounter == 0) { 625 var $form = $(this); 626 var form = $form[0]; 627 var data = new FormData(form); 628 $(".chaty-submit-button").attr("disabled", true); 629 $("#chaty-submit-button-"+ $form.data("index") + " .chaty-loader").addClass("active"); 630 jQuery.ajax({ 631 url: chaty_settings.ajax_url, 632 enctype: 'multipart/form-data', 633 data: data, 634 type: 'post', 635 dataType: 'json', 636 cache: false, 637 contentType: false, 638 processData: false, 639 success: function (response) { 640 if(googleV3Token != "") { 641 googleV3Token = ""; 642 refreshG3Token(); 643 } 644 $(".chaty-ajax-error-message").remove(); 645 $(".chaty-ajax-success-message").remove(); 646 $(".chaty-submit-button").attr("disabled", false); 647 if (response.status == 1) { 648 $("#chaty-submit-button-"+ $form.data("index") + " .chaty-loader").removeClass("active"); 649 $(".chaty-contact-inputs").append("<div class='chaty-ajax-success-message'>" + response.message + "</div>"); 650 $(".chaty-ajax-contact-form").find(".chaty-contact-input .mce-tinymce").removeClass("mce-error"); 651 $(".field-name, .field-email, .field-message, .field-phone").val(""); 652 $(".chaty-ajax-contact-form").find(".chaty-input-field").val(""); 653 $(".chaty-ajax-contact-form").find(".chaty-textarea-field").val(""); 654 $("#"+$form.find(".chaty-text-block").attr("id")+"_ifr").contents().find("body").html(""); 655 if (response.redirect_action == "yes") { 656 if (response.link_in_new_tab == "yes") { 657 var openInNewTab = window.open(response.redirect_link, '_blank'); 658 if(openInNewTab == null) { 659 window.open(response.redirect_link); 660 } 661 } else { 662 window.location = response.redirect_link; 663 } 664 } 665 if (response.close_form_after == "yes") { 666 setTimeout(function () { 667 if ($(".chaty-outer-forms.active").length) { 668 var widgetId = $(".chaty-outer-forms.active").data('widget'); 669 if (!isEmpty(widgetId) || widgetId == 0) { 670 if ($("#chaty-widget-" + widgetId).length) { 671 $("#chaty-widget-" + widgetId).removeClass("form-open"); 672 $("body").removeClass("add-bg-blur-effect"); 673 $(".chaty-outer-forms.active").removeClass("active"); 674 if ($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("chaty-no-close-button")) { 675 $("#chaty-widget-" + widgetId).find(".chaty-widget:not(.has-single)").addClass("chaty-open") 676 } 677 } 678 } 679 } 680 }, parseInt(response.close_form_after_seconds) * 1000); 681 } 682 } else if (response.error == 1) { 683 if (response.errors.length) { 684 for (var i = 0; i < response.errors.length; i++) { 685 $("." + response.errors[i].field).addClass("has-chaty-error"); 686 $("." + response.errors[i].field).after("<span class='chaty-error-msg'>" + response.errors[i].message + "</span>"); 687 } 688 } 689 $(".chaty-loader").removeClass("active"); 690 } else if(response.status == 0) { 691 $(".chaty-contact-inputs").append("<div class='chaty-ajax-error-message'>" + response.message + "</div>"); 692 $(".chaty-loader").removeClass("active"); 693 } 694 $(".email_suggestion").html(''); 695 } 696 }); 697 } else { 698 $(".has-chaty-error:first").focus(); 699 } 700 return false; 701 }); 702 703 $(document).on('blur','.chaty-contact-form-box .field-email', function(event) { 704 var widget_id = $(this).closest(".chaty-contact-form-box").data("widget"); 705 $(this).mailcheck({ 706 suggested: function(element, suggestion) { 707 // callback code 708 $('#email_suggestion'+widget_id).html("Did you mean <b><i>" + suggestion.full + "</b></i>?"); 709 }, 710 empty: function(element) { 711 // callback code 712 $('#email_suggestion'+widget_id).html(''); 713 } 714 }); 715 }); 716 717 if($(".chaty-contact-form-box .field-email").length) { 718 $(".chaty-contact-form-box .field-email").emailautocomplete({ 719 domains: ["protonmail.com", "yahoo.com", "gmail.com"] //add your own domains 720 }); 721 } 722 723 $(document).on("click", ".email_suggestion i", function (){ 724 $(this).closest(".chaty-contact-form-box").find(".field-email").val($(this).text()).focus(); 725 jQuery(this).closest(".email_suggestion").html(''); 726 }); 727 728 /* Click function for Call */ 729 $(document).on("click", ".chaty-widget.has-single .chaty-i-trigger .chaty-channel:not(.chaty-agent-button).Phone-channel", function () { 730 window.location = $(this).find("a").prop("href"); 731 }); 732 733 $(document).on("click", ".chaty-widget.has-single .chaty-i-trigger .chaty-channel:not(.chaty-agent-button).Phone-channel a, .picmo__popupContainer", function (e) { 734 e.stopPropagation(); 735 e.stopImmediatePropagation(); 736 }); 737 738 $(document).on("click", ".chaty-wp-emoji-input", function (){ 739 if($(".picmo__popupContainer").length) { 740 } else { 741 const {createPopup} = window.picmoPopup; 742 const trig = document.querySelector("#chaty_whatsapp_input"); 743 744 const picker = createPopup({}, { 745 referenceElement: trig, 746 triggerElement: trig, 747 position: 'top', 748 hideOnEmojiSelect: false 749 }); 750
751 picker.toggle(); 752 753 picker.addEventListener('emoji:select', (selection) => { 754 $('.chaty-whatsapp-input').val($(".chaty-whatsapp-input").val() + selection.emoji); 755 }); 756 } 757 }); 758 759 $(document).on("click", "#chaty_whatsapp_input", function (){ 760 if($(".picmo__popupContainer").length) { 761 $(".picmo__popupContainer").remove(); 762 } 763 }); 764 765 }); 766 767 function setChatyEditor() { 768 if($(".chaty-text-block:not(.editor-loaded)").length) { 769 $(".chaty-text-block:not(.editor-loaded)").each(function(){ 770 text_id = $(this).attr("id"); 771 wp.editor.initialize( 772 text_id, 773 { 774 tinymce: { 775 wpautop: false, 776 toolbar1: 'bold italic underline', 777 }, 778 quicktags: false 779 } 780 ); 781 }) 782 } 783 } 784 785 /** 786 * 787 * add class to body to check dimension 788 * Added On: 08/17/2022 789 * Added By: Chirag Thummar 790 * 791 * */ 792 $(window).resize(function(){ 793 if($(window).height() > $(window).width()) { 794 $("body").addClass("cht-portrait").removeClass("cht-landscape"); 795 } else { 796 $("body").addClass("cht-landscape").removeClass("cht-portrait"); 797 } 798 }); 799 800 /** 801 * 802 * To remove animation when widget is clicked 803 * Added On: 09/29/2021 804 * Added By: Chirag Thummar 805 * 806 * */ 807 function removeChatyAnimation(widgetId) { 808 if ($("#chaty-widget-" + widgetId).data("animation") != undefined && $("#chaty-widget-" + widgetId).data("animation") != "none") { 809 var animationClass = "chaty-animation-" + $("#chaty-widget-" + widgetId).data("animation"); 810 $("#chaty-widget-" + widgetId + " ." + animationClass).removeClass(animationClass); 811 } 812 $("#chaty-widget-" + widgetId+ " .ch-pending-msg").remove(); 813 } 814 815 function checkForCountry() { 816 var hasCountryFilter = false; 817 if (widgetData.length) { 818 $.each(widgetData, function (key, widgetRecord) { 819 if (isTrue(widgetRecord.triggers.has_countries) && !isEmpty(widgetRecord.triggers.countries) && widgetRecord.triggers.countries.length) { 820 hasCountryFilter = true; 821 } 822 }); 823 } 824 if (hasCountryFilter) { 825 clientCountry = getUserCountry(); 826 if (clientCountry != '') { 827 startMakingWidgets(); 828 } else { 829 getClientCountry(); 830 } 831 } else { 832 startMakingWidgets(); 833 } 834 } 835 836 /** 837 * 838 * Get client country from cloudflare API 839 * Added On: 10/21/2021 840 * Added By: Chirag Thummar 841 * 842 * */ 843 844 function getClientCountry() { 845 var $ipurl = 'https://www.cloudflare.com/cdn-cgi/trace'; 846 $.get($ipurl, function (cloudflaredata) { 847 var currentCountry = cloudflaredata.match("loc=(.*)"); 848 if (currentCountry.length > 1) { 849 currentCountry = currentCountry[1]; 850 if (currentCountry) { 851 currentCountry = currentCountry.toUpperCase(); 852 if (currentCountry == "") { 853 currentCountry = "-"; 854 } 855 setUserCountry(currentCountry); 856 startMakingWidgets(); 857 } 858 } 859 }); 860 } 861 862 /** 863 * 864 * Creating widgets from API response 865 * Added On: 10/21/2021 866 * Added By: Chirag Thummar 867 * 868 * */ 869 function startMakingWidgets() { 870 if (widgetData.length) { 871 $("body").append('<svg width="39" height="39" viewBox="0 0 39 39" class="hide-cht-svg-bg" fill="none" xmlns="http://www.w3.org/2000/svg"><defs> <linearGradient id="linear-gradient" x1="0.892" y1="0.192" x2="0.128" y2="0.85" gradientUnits="objectBoundingBox"> <stop offset="0" stop-color="#4a64d5"/> <stop offset="0.322" stop-color="#9737bd"/> <stop offset="0.636" stop-color="#f15540"/> <stop offset="1" stop-color="#fecc69"/> </linearGradient> </defs>'); 872 $.each(widgetData, function (key, widgetRecord) { 873
874 var customCSS = ""; 875 var advanceCustomCSS = ""; 876 var activeChannels = 0; 877 var channelSetting = {}; 878 879 /* check for country filter */ 880 var widgetStatus = checkForUserCountry(widgetRecord); 881 widgetStatus = widgetStatus && checkForTimeSchedule(widgetRecord); 882 widgetStatus = widgetStatus && checkForDayAndTimeSchedule(widgetRecord); 883 884 $.each(widgetRecord.channels, function (key, channel) { 885 var channelStatus = checkForChannel(channel); 886 if (channelStatus) { 887 activeChannels++; 888 channelSetting = channel; 889 } 890 }); 891 892 if (widgetRecord.settings.default_state == "open" && activeChannels == 1 && widgetRecord.settings.cta_type != "chat-view") { 893 widgetRecord.settings.default_state = "click"; 894 widgetData[key].settings.default_state = "click"; 895 } 896 897 if (widgetStatus && activeChannels > 0 && !$("#chaty-widget-" + widgetRecord.id).length) { 898 var widgetPosition = getWidgetPosition(widgetRecord.settings); 899 widgetPosition = (widgetPosition == "right") ? "right" : "left"; 900 var toolTipPosition = getToolTipPosition(widgetRecord); 901 if(widgetRecord.settings.cta_type == "chat-view") { 902 var widgetHtml = "<div style='display: none' class='chaty chaty-has-chat-view chaty-id-" + widgetRecord.id + " chaty-widget-" + widgetRecord.id + " chaty-key-" + key + "' id='chaty-widget-" + widgetRecord.id + "' data-key='" + key + "' data-id='" + widgetRecord.id + "' data-identifier='" + widgetRecord.identifier + "' data-nonce='" + widgetRecord.settings.widget_token + "' >" + 903 "<div class='chaty-widget " + widgetPosition + "-position'>" + 904 "<div class='chaty-channels'>" + 905 "<div class='chaty-i-trigger'></div>" + 906 "</div>" + 907 "</div>" + 908 "</div>"; 909 $("body").append(widgetHtml); 910 911 makeChatyChatView(widgetRecord); 912 } else { 913 var widgetHtml = "<div style='display: none' class='chaty chaty-id-" + widgetRecord.id + " chaty-widget-" + widgetRecord.id + " chaty-key-" + key + "' id='chaty-widget-" + widgetRecord.id + "' data-key='" + key + "' data-id='" + widgetRecord.id + "' data-identifier='" + widgetRecord.identifier + "' data-nonce='" + widgetRecord.settings.widget_token + "' >" + 914 "<div class='chaty-widget " + widgetPosition + "-position'>" + 915 "<div class='chaty-channels'>" + 916 "<div class='chaty-channel-list'></div>" + 917 "<div class='chaty-i-trigger'></div>" + 918 "</div>" + 919 "</div>" + 920 "</div>"; 921 $("body").append(widgetHtml); 922 } 923 924 if (isTrue(widgetRecord.triggers.auto_hide_widget) && parseInt(widgetRecord.triggers.hide_after) > 0) { 925 $("#chaty-widget-" + widgetRecord.id).addClass("auto-hide-chaty"); 926 $("#chaty-widget-" + widgetRecord.id).attr("data-time", widgetRecord.triggers.hide_after); 927 } 928 929 var clickStatus = checkChatyCookieExpired(widgetRecord.id, 'c-widget'); 930 $("#chaty-widget-" + widgetRecord.id).addClass(widgetRecord.settings.show_cta); 931 if (activeChannels == 1 && widgetRecord.settings.cta_type != "chat-view") { 932 if (widgetRecord.settings.icon_view != "vertical") { 933 toolTipPosition = (widgetPosition != "right") ? "right" : "left"; 934 } 935 var channelHtml = getChannelSetting(channelSetting, widgetRecord.id, toolTipPosition); 936 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").html(channelHtml); 937 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").addClass("single-channel"); 938 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel").addClass("single"); 939 940 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("has-single"); 941 942 var ctaText = widgetRecord.settings.cta_text; 943 if(!isEmpty(ctaText)) { 944 ctaText = htmlDecode(ctaText); 945 } 946 if (widgetRecord.settings.show_cta == "first_click") { 947 if (clickStatus) { 948 $("#chaty-widget-" + widgetRecord.id + " .chaty-tooltip").removeClass("chaty-tooltip"); 949 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel").addClass("active").addClass("chaty-tooltip").addClass("pos-"+toolTipPosition); 950 951 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel").append("<span class='on-hover-text'>"+ctaText+"</span>").addClass("active").addClass("has-on-hover"); 952 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").append("<span class='on-hover-text'>"+ctaText+"</span>").addClass("has-on-hover"); 953 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").attr("data-text", ctaText); 954 } else { 955 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").append("<span class='on-hover-text'>"+ctaText+"</span>").removeClass("active").addClass("has-on-hover"); 956 } 957 } 958 if (widgetRecord.settings.show_cta == "all_time") { 959 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-tooltip").append("<span class='on-hover-text'>"+ctaText+"</span>").addClass("active").addClass("has-on-hover"); 960 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger.single-channel .chaty-channel a").attr("data-text", ctaText); 961 } 962 963 var channel = channelSetting; 964 if (channel.channel_type != "Instagram" || (channel.icon_color != "#ffffff" && channel.icon_color != "#fff")) { 965 customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}"; 966 customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}"; 967 } 968 969 customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-custom-icon { background-color: " + channel.icon_color + "; }"; 970 customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-svg { background-color: " + channel.icon_color + ";}"; 971 customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .chaty-svg { background-color: " + channel.icon_color + ";}"; 972 973 if(channel.channel_type == "Contact_Us") { 974 customCSS += ".chaty-contact-form-box #chaty-submit-button-" + widgetRecord.id + " {background-color: "+channel.contact_form_settings.button_bg_color+"; color: "+channel.contact_form_settings.button_text_color+";} "; 975 customCSS += "#chaty-form-" + widgetRecord.id + "-Contact_Us .chaty-contact-form-title {background-color: "+channel.contact_form_settings.title_bg_color+"; } "; 976 } 977 978 var closeHtml = '<div class="chaty-channel chaty-cta-close chaty-tooltip pos-' + toolTipPosition + '" data-hover="' + widgetRecord.settings.close_text + '">' + 979 '<div class="chaty-cta-button"><button type="button">' + 980 '<span class="chaty-svg">' + 981 '<svg viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg"><ellipse cx="26" cy="26" rx="26" ry="26" fill="' + widgetRecord.settings.widget_color + '"></ellipse><rect width="27.1433" height="3.89857" rx="1.94928" transform="translate(18.35 15.6599) scale(0.998038 1.00196) rotate(45)" fill="' + widgetRecord.settings.widget_icon_color + '"></rect><rect width="27.1433" height="3.89857" rx="1.94928" transform="translate(37.5056 18.422) scale(0.998038 1.00196) rotate(135)" fill="' + widgetRecord.settings.widget_icon_color + '"></rect></svg>
981' + 982 '</span>' + 983 '<span class="sr-only">Hide chaty</span>' + 984 '</button>' + 985 '</div>' + 986 '</div>'; 987 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").append(closeHtml); 988 } else { 989 $.each(widgetRecord.channels, function (key, channel) { 990 var channelStatus = checkForChannel(channel); 991 if (channelStatus) { 992 if (isValueEmpty(channel.channel_type)) { 993 channel.channel_type = channel.channel; 994 } 995 996 if(widgetRecord.settings.cta_type == "chat-view") { 997 var channelHtml = getChannelSetting(channel, widgetRecord.id, "top"); 998 $(".chaty-chat-view-" + widgetRecord.id + " .chaty-view-channels").append(channelHtml); 999 } else { 1000 var channelHtml = getChannelSetting(channel, widgetRecord.id, toolTipPosition); 1001 $("#chaty-widget-" + widgetRecord.id + " .chaty-channel-list").append(channelHtml); 1002 } 1003 1004 if (channel.channel_type != "Instagram" || (channel.icon_color != "#ffffff" && channel.icon_color != "#fff")) { 1005 customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}"; 1006 customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}"; 1007 } 1008 1009 customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-custom-icon { background-color: " + channel.icon_color + "; }"; 1010 customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-svg { background-color: " + channel.icon_color + ";}"; 1011 customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .chaty-svg { background-color: " + channel.icon_color + ";}"; 1012 1013 customCSS += ".chaty-chat-view-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-custom-icon { background-color: " + channel.icon_color + "; }"; 1014 customCSS += ".chaty-chat-view-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-svg { background-color: " + channel.icon_color + ";}"; 1015 customCSS += ".chaty-chat-view-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .chaty-svg { background-color: " + channel.icon_color + ";}"; 1016 1017 if(channel.channel_type == "Contact_Us") { 1018 customCSS += ".chaty-contact-form-box #chaty-submit-button-" + widgetRecord.id + " {background-color: "+channel.contact_form_settings.button_bg_color+"; color: "+channel.contact_form_settings.button_text_color+";} "; 1019 customCSS += "#chaty-form-" + widgetRecord.id + "-Contact_Us .chaty-contact-form-title {background-color: "+channel.contact_form_settings.title_bg_color+"; } "; 1020 } 1021 } 1022 }); 1023 1024 var widgetIcon = getWidgetIcon(widgetRecord.settings, widgetRecord.id); 1025 /* check for widget CTA button */ 1026 var ctaText = widgetRecord.settings.cta_text; 1027 if (widgetRecord.settings.show_cta == "first_click") { 1028 if (!clickStatus) { 1029 ctaText = ""; 1030 } 1031 } 1032 1033 var ctaToolTipPosition = toolTipPosition; 1034 if (widgetRecord.settings.icon_view == "horizontal") { 1035 if (widgetPosition == "left") { 1036 ctaToolTipPosition = "right"; 1037 } else { 1038 ctaToolTipPosition = "left"; 1039 } 1040 } 1041 1042 if(!isEmpty(ctaText)) { 1043 ctaText = htmlDecode(ctaText); 1044 } 1045 1046 var widgetButton = '<div class="chaty-channel chaty-cta-main chaty-tooltip has-on-hover pos-' + ctaToolTipPosition + ' active" data-widget="' + widgetRecord.id + '" >' + 1047 '<span class="on-hover-text">'+ctaText+'</span>' + 1048 '<div class="chaty-cta-button">' + 1049 '<button type="button" class="open-chaty">' + 1050 widgetIcon + 1051 '<span class="sr-only">Open chaty</span>' + 1052 '</button>' + 1053 '<button type="button" class="open-chaty-channel"><span class="sr-only">chaty buttons</span></button>' + 1054 '</div>' + 1055 '</div>'; 1056 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").html(widgetButton); 1057 1058 /* close button */ 1059 var closeHtml = '<div class="chaty-channel chaty-cta-close chaty-tooltip pos-' + toolTipPosition + '" data-hover="' + widgetRecord.settings.close_text + '">' + 1060 '<div class="chaty-cta-button"><button type="button">' + 1061 '<span class="chaty-svg">' + 1062 '<svg viewBox="0 0 52 52" fill="none" xmlns="http://www.w3.org/2000/svg"><ellipse cx="26" cy="26" rx="26" ry="26" fill="' + widgetRecord.settings.widget_color + '"></ellipse><rect width="27.1433" height="3.89857" rx="1.94928" transform="translate(18.35 15.6599) scale(0.998038 1.00196) rotate(45)" fill="' + widgetRecord.settings.widget_icon_color + '"></rect><rect width="27.1433" height="3.89857" rx="1.94928" transform="translate(37.5056 18.422) scale(0.998038 1.00196) rotate(135)" fill="' + widgetRecord.settings.widget_icon_color + '"></rect></svg>
1062' + 1063 '</span>' + 1064 '<span class="sr-only">Hide chaty</span>' + 1065 '</button>' + 1066 '</div>' + 1067 '</div>'; 1068 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").append(closeHtml); 1069 } 1070 1071 /* check for State */ 1072 $.each(widgetRecord.channels, function (key, channel) { 1073 if(channel.channel_type == "Contact_Us" && channel.hide_recaptcha_badge == "yes") { 1074 customCSS += ".grecaptcha-badge {visibility: hidden;}"; 1075 } 1076 }); 1077 1078 1079 if(widgetRecord.settings.cta_type == "chat-view") { 1080 widgetRecord.settings.show_close_button == "yes"; 1081 } 1082 1083 1084 var clickStatus = checkChatyCookieExpired(widgetRecord.id, 'c-widget'); 1085 if (clickStatus && (widgetRecord.settings.default_state != "open" || activeChannels == 1)) { 1086 checkForPendingMessage(widgetRecord.settings, widgetRecord.id); 1087 checkForWidgetAnimation(widgetRecord.settings, widgetRecord.id); 1088 } 1089 1090 var extraSpace = 0; 1091 /* check for close button */ 1092 if (widgetRecord.settings.default_state == "open" && !isTrue(widgetRecord.settings.show_close_button)) { 1093 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("chaty-no-close-button").addClass("chaty-open"); 1094 extraSpace = 1; 1095 } 1096 1097 /* checking for google analytics */ 1098 if (isTrue(widgetRecord.settings.is_google_analytics_enabled)) { 1099 $("#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel > a").addClass("has-gae"); 1100 $("#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-channel > a").addClass("has-gae"); 1101 $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger.single-channel .chaty-channel > a").addClass("has-gae"); 1102 1103 $(".chaty-outer-forms.chaty-whatsapp-btn-form.chaty-form-" + widgetRecord.id + " form.add-analytics").addClass("form-google-analytics"); 1104 $(".whatsapp-chaty-form-" + widgetRecord.id).addClass("has-form-gae"); 1105 } 1106 1107 /* checking for custom CSS */ 1108 if (isTrue(widgetRecord.settings.has_custom_css) && !isEmpty(widgetRecord.settings.custom_css)) { 1109 advanceCustomCSS += widgetRecord.settings.custom_css; 1110 } 1111 1112 /* check for State */ 1113 if (widgetRecord.settings.default_state == "hover") { 1114 $("#chaty-widget-" + widgetRecord.id).addClass("open-on-hover"); 1115 } else if (widgetRecord.settings.default_state == "open") { 1116 1117 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("default-open"); 1118 if (clickStatus || !isTrue(widgetRecord.settings.show_close_button)) { 1119 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget:not(.has-single)").addClass("chaty-open"); 1120 } 1121 if(!clickStatus) { 1122 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").removeClass("default-open"); 1123 } 1124 } 1125 1126 if($("#chaty-widget-" + widgetRecord.id + " .chaty-widget:not(.has-single):not(.chaty-no-close-button)").hasClass("default-open")) { 1127 if (isTrue(widgetRecord.settings.bg_blur_effect)) { 1128 $("body").addClass("add-bg-blur-effect"); 1129 } 1130 } else { 1131 $("body").removeClass("add-bg-blur-effect"); 1132 } 1133 1134 if (isTrue(widgetRecord.settings.bg_blur_effect)) { 1135 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget:not(.chaty-no-close-button)").addClass("has-bg-blur-effect"); 1136 } 1137 1138 /* set widget channel height */ 1139 var widgetSize = getWidgetSize(widgetRecord.settings.widget_size, widgetRecord.settings.custom_widget_size); 1140 widgetSize = parseInt(widgetSize); 1141 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1142 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel > a {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1143 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel > a .chaty-custom-icon {display:block; width: " + widgetSize + "px; height: " + widgetSize + "px; line-height: " + widgetSize + "px; font-size: " + parseInt(widgetSize / 2) + "px; }"; 1144 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel button {width: " + widgetSize + "px; height: " + widgetSize + "px; margin: 0; padding:0; outline: none; border-radius: 50%;}"; 1145 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel .chaty-svg {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1146 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel .chaty-svg img {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1147 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel span.chaty-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1148 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel a {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1149 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel .chaty-svg .chaty-custom-c
1149hannel-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; line-height: " + widgetSize + "px; display: block; font-size:" + (parseInt(widgetSize / 2)) + "px; }"; 1150 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-cta-button {background-color: " + widgetRecord.settings.widget_color + "; }"; 1151 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-cta-button button {background-color: " + widgetRecord.settings.widget_color + "; }"; 1152 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1153 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel > a {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1154 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel > a .chaty-custom-icon {display:block; width: " + widgetSize + "px; height: " + widgetSize + "px; line-height: " + widgetSize + "px; font-size: " + parseInt(widgetSize / 2) + "px; }"; 1155 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel button {width: " + widgetSize + "px; height: " + widgetSize + "px; margin: 0; padding:0; outline: none; border-radius: 50%;}"; 1156 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel .chaty-svg {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1157 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel .chaty-svg img {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1158 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel span.chaty-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1159 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a {width: " + widgetSize + "px; height: " + widgetSize + "px; }"; 1160 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel .chaty-svg .chaty-custom-channel-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; line-height: " + widgetSize + "px; display: block; font-size:" + (parseInt(widgetSize / 2)) + "px; }"; 1161 1162 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .ch-pending-msg {background-color: " + widgetRecord.settings.pending_mesg_count_bgcolor + "; color: " + widgetRecord.settings.pending_mesg_count_color + "; }"; 1163 1164 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel .chaty-svg .widget-fa-icon {line-height: " + widgetSize + "px; font-size:" + (parseInt(widgetSize / 2)) + "px; }"; 1165 1166 if (widgetRecord.settings.icon_view == "vertical") { 1167 //customCSS += "#chaty-widget-"+widgetRecord.id+" .chaty-channel-list {bottom: "+(widgetSize+4)+"px; }"; 1168 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {height: " + (activeChannels * (widgetSize + 8)) + "px; }"; 1169 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {width: " + (widgetSize + 8) + "px; }"; 1170 1171 for (var i = 0; i <= activeChannels; i++) { 1172 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-open .chaty-channel-list .chaty-channel:nth-child(" + (i + 1) + ") {-webkit-transform: translateY(-" + ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px); transform: translateY(-" + ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px);}"; 1173 } 1174 } else { 1175 $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("hor-mode"); 1176 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {width: " + (activeChannels * (widgetSize + 8)) + "px; }"; 1177 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {height: " + (widgetSize) + "px; }"; 1178 // customCSS += "#chaty-widget-"+widgetRecord.id+" .chaty-widget.left-position.hor-mode .chaty-channel-list {left: "+(widgetSize+8)+"px; }"; 1179 // customCSS += "#chaty-widget-"+widgetRecord.id+" .chaty-widget.right-position.hor-mode .chaty-channel-list {right: "+(widgetSize+8)+"px; }"; 1180 1181 for (var i = 0; i <= activeChannels; i++) { 1182 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget.left-position.hor-mode.chaty-open .chaty-channel-list .chaty-channel:nth-child(" + (i + 1) + ") {-webkit-transform: translateX("
1182+ ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px); transform: translateX(" + ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px);}"; 1183 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget.right-position.hor-mode.chaty-open .chaty-channel-list .chaty-channel:nth-child(" + (i + 1) + ") {-webkit-transform: translateX(-" + ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px); transform: translateX(-" + ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px);}"; 1184 } 1185 } 1186 1187 1188 /* set widget position */ 1189 var bottomSpacing = widgetRecord.settings.bottom_spacing; 1190 var sideSpacing = widgetRecord.settings.side_spacing; 1191 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget {bottom: "+(bottomSpacing)+"px}"; 1192 1193 if (widgetPosition == "left") { 1194 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget {left: " + sideSpacing + "px; right: auto;}"; 1195 customCSS += ".chaty-outer-forms.pos-left.chaty-form-" + widgetRecord.id + " {left: " + sideSpacing + "px}"; 1196 $(".chaty-form-" + widgetRecord.id).addClass("pos-left"); 1197 } else { 1198 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget {right: " + sideSpacing + "px; left:auto;}"; 1199 $(".chaty-form-" + widgetRecord.id).addClass("pos-right"); 1200 customCSS += ".chaty-outer-forms.pos-right.chaty-form-" + widgetRecord.id + " {right: " + sideSpacing + "px; left:auto;}"; 1201 } 1202 $(".chaty-form-" + widgetRecord.id).show(); 1203 1204 var formBottomPos = widgetSize + 15 + parseInt(bottomSpacing) 1205 customCSS += ".chaty-outer-forms.active.chaty-form-" + widgetRecord.id + " {-webkit-transform: translateY(-"+formBottomPos+"px); transform: translateY(-"+formBottomPos+"px)} "; 1206 customCSS += "#chaty-widget-"+widgetRecord.id+".chaty:not(.form-open) .chaty-widget.chaty-open + .chaty-chat-view {-webkit-transform: translateY(-"+formBottomPos+"px); transform: translateY(-"+formBottomPos+"px)} "; 1207 1208 /* set on hover text color */ 1209 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip:after {background-color: " + widgetRecord.settings.cta_bg_color + "; color: " + widgetRecord.settings.cta_text_color + "}"; 1210 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-top:before {border-top-color: " + widgetRecord.settings.cta_bg_color + "; }"; 1211 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-left:before {border-left-color: " + widgetRecord.settings.cta_bg_color + "; }"; 1212 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-right:before {border-right-color: " + widgetRecord.settings.cta_bg_color + ";}"; 1213 customCSS += "#chaty-widget-" + widgetRecord.id + " .on-hover-text {background-color: " + widgetRecord.settings.cta_bg_color + "; color: " + widgetRecord.settings.cta_text_color + "}"; 1214 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-top .on-hover-text:before {border-top-color: " + widgetRecord.settings.cta_bg_color + "; }"; 1215 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-left .on-hover-text:before {border-left-color: " + widgetRecord.settings.cta_bg_color + "; }"; 1216 customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-right .on-hover-text:before {border-right-color: " + widgetRecord.settings.cta_bg_color + ";}"; 1217 1218 /* Custom CSS for Agents */ 1219 var agentMaxHeight = formBottomPos + 72 + widgetSize; 1220 if (agentMaxHeight > 0) { 1221 customCSS += ".chaty-outer-forms.chaty-form-" + widgetRecord.id + " .chaty-agent-body {max-height: calc(100vh - " + agentMaxHeight + "px); overflow-y: auto; } "; 1222 } 1223 1224 customCSS += "#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-view-header {background-color: " + widgetRecord.settings.cta_head_bg_color + ";}"; 1225 customCSS += "#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-view-header {color: " + widgetRecord.settings.cta_head_text_color + ";}"; 1226 customCSS += "#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-view-header svg {fill : " + widgetRecord.settings.cta_head_text_color + ";}"; 1227 1228 /* Custom CSS for WhatsApp */ 1229 var whatsAppMaxHeight = formBottomPos + 72 + widgetSize; 1230 if (whatsAppMaxHeight > 0) { 1231 // customCSS += ".chaty-outer-forms.chaty-whatsapp-btn-form.chaty-form-" + widgetRecord.id + " .chaty-whatsapp-content {max-height: calc(100vh - " + whatsAppMaxHeight + "px); overflow-y: auto; } "; 1232 } 1233 1234 /* Custom CSS for Contact Form */ 1235 var contactFormMaxHeight = formBottomPos + 82 + widgetSize; 1236 if (contactFormMaxHeight > 0) { 1237 customCSS += ".chaty-outer-forms.chaty-contact-form-box.chaty-form-" + widgetRecord.id + " .chaty-contact-inputs {max-height: calc(100vh - " + contactFormMaxHeight + "px); overflow-y: auto; } "; 1238 } 1239 1240 if(bottomSpacing != 25 || sideSpacing != 25) { 1241 $(".chaty-outer-forms.chaty-form-" + widgetRecord.id).addClass("custom-cht-pos"); 1242 $("#chaty-widget-"+widgetRecord.id).addClass("has-custom-pos"); 1243 } 1244 1245 var total_wp_form_size = parseInt($("#chaty-form-" + widgetRecord.id + "-Whatsapp .chaty-whatsapp-header").outerHeight()) + parseInt($("#chaty-form-" + widgetRecord.id + "-Whatsapp .chaty-whatsapp-footer").outerHeight()) + parseInt(widgetSize) + parseInt(bottomSpacing) + 20; 1246 customCSS += "#chaty-form-" + widgetRecord.id + "-Whatsapp .chaty-whatsapp-body { max-height: calc(100vh - "+total_wp_form_size+"px); overflow-y: auto; }"; 1247 1248 /* checking for triggers */ 1249 var visibleStatus = checkChatyCookieExpired(widgetRecord.id, 'v-widget'); 1250 1251 if (visibleStatus) { 1252 if (isTrue(widgetRecord.triggers.exit_intent) || isTrue(widgetRecord.triggers.has_time_delay) || isTrue(widgetRecord.triggers.has_display_after_page_scroll) > 0) { 1253 /* checking for time delay */ 1254 1255 if ((isTrue(widgetRecord.triggers.has_time_delay) && parseInt(widgetRecord.triggers.time_delay) == 0)) { 1256 updateWidgetViews(widgetRecord.id); 1257 $("#chaty-widget-" + widgetRecord.id).addClass("active"); 1258 } else if ((isTrue(widgetRecord.triggers.has_time_delay) && parseInt(widgetRecord.triggers.time_delay) > 0)) {
1259 chatyHasTimeDelay = true; 1260 if (parseInt(widgetRecord.triggers.time_delay) > chatyMaxTimeInterval) { 1261 chatyMaxTimeInterval = widgetRecord.triggers.time_delay; 1262 } 1263 $("#chaty-widget-" + widgetRecord.id).addClass("on-chaty-delay"); 1264 $("#chaty-widget-" + widgetRecord.id).addClass("delay-time-" + parseInt(widgetRecord.triggers.time_delay)); 1265 $("#chaty-widget-" + widgetRecord.id).attr("data-time", parseInt(widgetRecord.triggers.time_delay)); 1266 } 1267 1268 /* checking for page scroll */ 1269 if ((isTrue(widgetRecord.triggers.has_display_after_page_scroll) && parseInt(widgetRecord.triggers.display_after_page_scroll) == 0)) { 1270 updateWidgetViews(widgetRecord.id); 1271 $("#chaty-widget-" + widgetRecord.id).addClass("active"); 1272 } else if ((isTrue(widgetRecord.triggers.has_display_after_page_scroll) && parseInt(widgetRecord.triggers.display_after_page_scroll) > 0)) { 1273 chatyHasPageScroll = true; 1274 $("#chaty-widget-" + widgetRecord.id).addClass("on-chaty-scroll"); 1275 $("#chaty-widget-" + widgetRecord.id).addClass("page-scroll-" + parseInt(widgetRecord.triggers.display_after_page_scroll)); 1276 $("#chaty-widget-" + widgetRecord.id).attr("data-scroll", parseInt(widgetRecord.triggers.display_after_page_scroll)); 1277 } 1278 1279 /* checking for exit intent */ 1280 if (isTrue(widgetRecord.triggers.exit_intent)) { 1281 chatyHasExitIntent = true; 1282 $("#chaty-widget-" + widgetRecord.id).addClass("on-chaty-exit-intent"); 1283 } 1284 } else { 1285 // saveChatyCookieString(widgetRecord.id, 'v-widget'); 1286 updateWidgetViews(widgetRecord.id); 1287 $("#chaty-widget-" + widgetRecord.id).addClass("active"); 1288 } 1289 } else { 1290 updateWidgetViews(widgetRecord.id); 1291 $("#chaty-widget-" + widgetRecord.id).addClass("active"); 1292 } 1293 1294 /* check for font family */ 1295 if (!isEmpty(widgetRecord.settings.font_family) && widgetRecord.settings.font_family != "none") { 1296 1297 /* check for default browser font */ 1298 var fontFamily = widgetRecord.settings.font_family; 1299 if ($.inArray(fontFamily, defaultFontFamily) != -1) { 1300 if (fontFamily == "System Stack") { 1301 fontFamily = "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"; 1302 } 1303 } else { 1304 /* load fonts from google */ 1305 $('head').append('<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=' + fontFamily + '&display=swap">'); 1306 $('head').append('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=' + fontFamily + '&display=swap">'); 1307 } 1308 customCSS += "#chaty-widget-" + widgetRecord.id + ", #chaty-widget-" + widgetRecord.id + " .chaty-tooltip:after {font-family: " + fontFamily + "}"; 1309 } 1310 } 1311 1312 if(chatyHasExitIntent) { 1313 bindExitIntentFunction(); 1314 } 1315 1316 /* set dynamic CSS for widget */ 1317 if (customCSS != "") { 1318 if (!$("#custom-chaty-css").length) { 1319 $("head").append("<style id='custom-chaty-css'></style>"); 1320 }
1321 $("#custom-chaty-css").append(customCSS); 1322 } 1323 1324 /* set dynamic CSS for widget */ 1325 if (advanceCustomCSS != "") { 1326 if (!$("#custom-advance-chaty-css").length) { 1327 $("head").append("<style id='custom-advance-chaty-css'></style>"); 1328 } 1329 $("#custom-advance-chaty-css").append(advanceCustomCSS); 1330 } 1331 1332 if (key == (widgetData.length - 1)) { 1333 1334 } 1335 1336 if($(".chaty-sms-channel").length) { 1337 $(".chaty-sms-channel").each(function(){ 1338 var thisLink = $(this).attr("href"); 1339 thisLink = thisLink.replace(/{title}/g, getPageTitle()); 1340 thisLink = thisLink.replace(/{url}/g, window.location.href); 1341 $(this).attr("href", thisLink); 1342 }); 1343 } 1344 1345 $(document).on("click", "#chaty-widget-"+widgetRecord.id+" .chaty-i-trigger .chaty-channel", function (){ 1346 if($(this).closest(".chaty-widget").hasClass("has-single")) { 1347 if ($(this).closest(".chaty").hasClass("form-open")) { 1348 if (isTrue(widgetRecord.settings.bg_blur_effect)) { 1349 $("body").addClass("add-bg-blur-effect"); 1350 } else { 1351 $("body").removeClass("add-bg-blur-effect"); 1352 } 1353 } 1354 } else { 1355 if ($(this).closest(".chaty-widget").hasClass("chaty-open")) { 1356 $("body").removeClass("add-bg-blur-effect"); 1357 } else { 1358 if (!$(this).closest(".chaty-widget").hasClass("chaty-no-close-button")) { 1359 if (isTrue(widgetRecord.settings.bg_blur_effect)) { 1360 $("body").addClass("add-bg-blur-effect"); 1361 } 1362 } 1363 } 1364 } 1365 }); 1366 1367 }); 1368 if (!$("#custom-advance-chaty-css").length) { 1369 $("head").append("<style id='custom-advance-chaty-css'></style>"); 1370 } 1371 $("#custom-advance-chaty-css").append(customExtraCSS); 1372 if(($(".v3_site_key").length && !isEmpty($(".v3_site_key").val())) || ($(".v2_site_key").length && !isEmpty($(".v2_site_key").val()))) { 1373 LoadChatyGoogleRecaptcha(); 1374 } 1375 } 1376 removeEmptyTooltip(); 1377 checkForChatyTriggers(); 1378 } 1379 1380 1381 function getPageTitle() { 1382 return $("title").length?$("title").text():""; 1383 } 1384 1385 1386 function makeChatyChatView(widgetRecord) { 1387 var widgetId = widgetRecord.id; 1388 var widgetIndex = getWidgetIndex(widgetId); 1389 if (widgetIndex == null) { 1390 widgetIndex = -1; 1391 } 1392 var bodyMsg = widgetRecord.settings.cta_body; 1393 var headMsg = widgetRecord.settings.cta_head; 1394 var pageTitle = $("title").text(); 1395 if(!isEmpty(pageTitle)) { 1396 bodyMsg = bodyMsg.replace(/{title}/g, pageTitle); 1397 headMsg = headMsg.replace(/{title}/g, pageTitle); 1398 } else { 1399 bodyMsg = bodyMsg.replace(/{title}/g, ''); 1400 headMsg = headMsg.replace(/{title}/g, ''); 1401 } 1402 bodyMsg = bodyMsg.replace(/{url}/g, "<a target='_blank' href='"+window.location.href+"'>"+window.location.href+"</a>"); 1403 headMsg = headMsg.replace(/{url}/g, "<a target='_blank' href='"+window.location.href+"'>"+window.location.href+"</a>"); 1404 var formHtml = ""; 1405 formHtml += "<div style='display:none;' class='chaty-chat-view chaty-chat-view-"+widgetId+" chaty-form-" + widgetId + "' data-channel='chaty-chat-view' id='chaty-form-" + widgetId + "-chaty-chat-view' data-widget='" + widgetId + "' data-index='" + widgetIndex + "'>"; 1406 formHtml += "<div class='chaty-view-body'>"; 1407 formHtml += "<div class='chaty-view-header'>"+headMsg; 1408 formHtml += "<div role='button' class='chaty-close-view-list'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 330 330'><path d='M325.607 79.393c-5.857-5.857-15.355-5.858-21.213.001l-139.39 139.393L25.607 79.393c-5.857-5.857-15.355-5.858-21.213.001s-5.858 15.355 0 21.213l150.004 150a15 15 0 0 0 21.212-.001l149.99
14086-150c5.859-5.857 5.859-15.355.001-21.213z'/></svg></div>"; 1409 formHtml += "</div>"; 1410 formHtml += "<div class='chaty-view-content'>"; 1411 formHtml += "<div class='chaty-top-content'>"; 1412 formHtml += bodyMsg; 1413 formHtml += "</div>"; 1414 formHtml += "<div class='chaty-view-channels'>"; 1415 formHtml += "</div>"; 1416 formHtml += "</div>"; 1417 formHtml += "</div>"; 1418 formHtml += "</div>"; 1419 $("#chaty-widget-"+widgetId).append(formHtml); 1420 } 1421 1422 1423 /** 1424 * 1425 * To Esc HTML Tags 1426 * Added On: 07/14/2022 1427 * Added By: Chirag Thummar 1428 * 1429 * */ 1430 function htmlDecode(input) { 1431 var doc = new DOMParser().parseFromString(input, "text/html"); 1432 return doc.documentElement.textContent; 1433 } 1434 1435 1436 /** 1437 * 1438 * Checking for Channel (is normal chhanel or agent channel) 1439 * Added On: 10/19/2021 1440 * Added By: Chirag Thummar 1441 * 1442 * */ 1443 function checkForChannel(channel) { 1444 if (isTrue(channel.is_agent)) { 1445 if (channel.agent_data.length) { 1446 if (((!isChatyInMobile && isTrue(channel.is_agent_desktop)) || (isChatyInMobile && isTrue(channel.is_agent_mobile)))) { 1447 return true; 1448 } 1449 } 1450 } else { 1451 if (((!isChatyInMobile && isTrue(channel.is_desktop)) || (isChatyInMobile && isTrue(channel.is_mobile))) && (channel.value != '' || channel.channel == "Contact_Us")) { 1452 return true; 1453 } 1454 } 1455 return false; 1456 } 1457 1458 /** 1459 * 1460 * Update widget views 1461 * Added On: 10/19/2021 1462 * Added By: Chirag Thummar 1463 * 1464 * */ 1465 1466 function updateWidgetViews(widgetId) { 1467 if ($("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open").length) { 1468 // $(".chaty-outer-forms").show(); 1469 var dataForm = $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open a.chaty-whatsapp-btn-form").data('form'); 1470 if (!isEmpty(dataForm)) { 1471 var clickStatus = checkChatyCookieExpired(widgetId, "c-" + $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open").data('channel')); 1472 if (clickStatus) { 1473 $("#" + dataForm).addClass("is-active"); 1474 if ($("#" + dataForm).length) { 1475 var buttonHtml = $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open a.chaty-whatsapp-btn-form").html()+"<span class='hide-cht-svg-bg'>"+chaty_settings.lang.hide_whatsapp_form+"</span>"; 1476 1477 removeChatyAnimation(widgetId); 1478 $("#chaty-widget-" + widgetId ).find(".ch-pending-msg").remove(); 1479 $("#chaty-widget-" + widgetId + " .chaty-widget").removeClass("chaty-open"); 1480 $("#chaty-widget-" + widgetId).addClass("form-open"); 1481 $("#" + dataForm).addClass("active"); 1482 if($("#chaty-widget-" + widgetId + " .chaty-widget:not(.chaty-no-close-button)").hasClass("has-bg-blur-effect")) { 1483 $("body").addClass("add-bg-blur-effect"); 1484 } 1485 setTimeout(function(){ 1486 $(".chaty-whatsapp-btn-form.active .chaty-whatsapp-input").focus(); 1487 }, 100); 1488 1489 $("#chaty-widget-" + widgetId + " .open-chaty-channel").html(buttonHtml); 1490 $("#chaty-widget-" + widgetId).addClass("active"); 1491 1492 $("#chaty-widget-" + widgetId).addClass("active"); 1493 if ($("#chaty-widget-" + widgetId).hasClass("auto-hide-chaty")) { 1494 var hideAfter = parseInt($("#chaty-widget-" + widgetId).data("time")); 1495 if (hideAfter > 0) { 1496 hideAfter = hideAfter + chatyHideIntervalTime; 1497 $("#chaty-widget-" + widgetId).addClass("hide-after-" + hideAfter); 1498 } 1499 } 1500 1501 if (chaty_settings.data_analytics_settings == "on") { 1502 var widgetChannels = []; 1503 var widgetChannel = $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open").data('channel'); 1504 var viewChannelStatus = checkChatyCookieExpired(widgetId, "v-" + widgetChannel); 1505 1506 if (viewChannelStatus && typeof widgetChannel != 'undefined') { 1507 saveChatyCookieString(widgetId, "v-" + widgetChannel); 1508 widgetChannels.push(widgetChannel); 1509 } 1510 1511 if (!isBoatUser && widgetChannels.length) { 1512 var widgetNonce = $("#chaty-widget-" + widgetId).data("nonce"); 1513 $.ajax({
1514 url: chaty_settings.ajax_url, 1515 data: { 1516 widgetId: widgetId, 1517 channels: widgetChannels, 1518 userId: widgetId, 1519 isMobile: isChatyInMobile, 1520 widgetNonce: widgetNonce, 1521 action: 'update_chaty_channel_views', 1522 }, 1523 type: 'post', 1524 dataType: 'json', 1525 success: function (response) { 1526 1527 }, 1528 error: function (XMLHttpRequest, textStatus, errorThrown) { 1529 monitorErrorLog(XMLHttpRequest, textStatus, errorThrown); 1530 } 1531 }); 1532 } 1533 } 1534 return; 1535 } 1536 } 1537 } 1538 } 1539 1540 $("#chaty-widget-" + widgetId).addClass("active"); 1541 if ($("#chaty-widget-" + widgetId).hasClass("auto-hide-chaty")) { 1542 var hideAfter = parseInt($("#chaty-widget-" + widgetId).data("time")); 1543 if (hideAfter > 0) { 1544 hideAfter = hideAfter + chatyHideIntervalTime; 1545 $("#chaty-widget-" + widgetId).addClass("hide-after-" + hideAfter); 1546 } 1547 } 1548 1549 var blur_effrct = chatyGetCookie("hide-bg-blur-effect"); 1550 if(blur_effrct) { 1551 $("body").removeClass("add-bg-blur-effect"); 1552 } 1553 1554 var viewStatus = checkChatyCookieExpired(widgetId, "v-widget"); 1555 if (viewStatus) { 1556 saveChatyCookieString(widgetId, 'v-widget'); 1557 var userId = $("#chaty-widget-" + widgetId).data("user"); 1558 var widgetChannels = []; 1559 var isSingle = 0; 1560 var isDefaultOpen = 0; 1561 var widgetChannel; 1562 var widgetKey = $("#chaty-widget-" + widgetId).data("key"); 1563 if (typeof widgetData[widgetKey] != undefined) { 1564 var activeWidgets = chatyGetCookie("activechatyWidgets"); 1565 if (activeWidgets != null) { 1566 activeWidgets = activeWidgets.split(","); 1567 if ($.inArray(widgetId, activeWidgets) == -1) { 1568 activeWidgets.push(widgetId); 1569 activeWidgets = activeWidgets.join(","); 1570 chatySetCookie("activechatyWidgets", activeWidgets, 1); 1571 } 1572 } else { 1573 activeWidgets = widgetId; 1574 chatySetCookie("activechatyWidgets", activeWidgets, 1); 1575 } 1576 } 1577 if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("has-single")) { 1578 isSingle = 1; 1579 widgetChannel = $("#chaty-widget-" + widgetId + " .chaty-channel").data("channel"); 1580 var viewChannelStatus = checkChatyCookieExpired(widgetId, "v-" + widgetChannel); 1581 if (viewChannelStatus && typeof widgetChannel != 'undefined') { 1582 saveChatyCookieString(widgetId, "v-" + widgetChannel); 1583 widgetChannels.push(widgetChannel); 1584 } 1585 } else if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("chaty-open")) { 1586 isDefaultOpen = 1; 1587 if($("#chaty-widget-" + widgetId).hasClass("chaty-has-chat-view")) { 1588 $(".chaty-chat-view.chaty-chat-view-" + widgetId + " .chaty-view-channels").find(".chaty-channel").each(function () { 1589 chatyChannel = $(this).data("channel"); 1590 clickStatus = checkChatyCookieExpired(widgetId, "v-" + chatyChannel); 1591 if (clickStatus && typeof chatyChannel != 'undefined') { 1592 saveChatyCookieString(widgetId, "v-" + chatyChannel); 1593 widgetChannels.push(chatyChannel); 1594 } 1595 }); 1596 } else { 1597 $("#chaty-widget-" + widgetId + " .chaty-channel-list .chaty-channel").each(function () { 1598 widgetChannel = $(this).data("channel"); 1599 var viewChannelStatus = checkChatyCookieExpired(widgetId, "v-" + widgetChannel); 1600 if (viewChannelStatus && typeof widgetChannel != 'undefined') { 1601 saveChatyCookieString(widgetId, "v-" + widgetChannel); 1602 widgetChannels.push(widgetChannel); 1603 } 1604 }); 1605 } 1606 } 1607 if (viewStatus && !isBoatUser) { 1608 var widgetNonce = $("#chaty-widget-" + widgetId).data("nonce"); 1609 if (!isBoatUser) { 1610 $.ajax({
1611 url: chaty_settings.ajax_url, 1612 data: { 1613 widgetId: widgetId, 1614 channels: widgetChannels, 1615 userId: widgetId, 1616 isMobile: isChatyInMobile, 1617 isOpen: isDefaultOpen, 1618 isSingle: isSingle, 1619 widgetNonce: widgetNonce, 1620 action: 'update_chaty_widget_views', 1621 }, 1622 type: 'post', 1623 dataType: 'json', 1624 success: function (response) { 1625 1626 }, 1627 error: function (XMLHttpRequest, textStatus, errorThrown) { 1628 monitorErrorLog(XMLHttpRequest, textStatus, errorThrown); 1629 } 1630 }); 1631 } 1632 } 1633 } 1634 } 1635 1636 /** 1637 * 1638 * check for visitor status and update it if required 1639 * Added On: 10/04/2021 1640 * Added By: Chirag Thummar 1641 * 1642 * */ 1643 function updateVisitorCount(widgetId) { 1644 var userId = $("#chaty-widget-" + widgetId).data("user"); 1645 var isOldUser = chatySaasCheckCookie("triggeredFor" + userId); 1646 if (!isOldUser) { 1647 chatySetCookie("triggeredFor" + userId, widgetId, 2); 1648 /*$.ajax({ 1649 url: VISITOR_COUNT_API, 1650 data: { 1651 widgetId: widgetId, 1652 channels: [], 1653 userId: userId 1654 }, 1655 type: 'post', 1656 success: function (response) { 1657 1658 }, 1659 error: function (XMLHttpRequest, textStatus, errorThrown) { 1660 monitorErrorLog(XMLHttpRequest, textStatus, errorThrown); 1661 } 1662 });*/ 1663 } 1664 } 1665 1666 /** 1667 * 1668 * Check for Triggers if exists 1669 * Added On: 10/04/2021 1670 * Added By: Chirag Thummar 1671 * 1672 * */ 1673 1674 function getWidgetSize(widgetSize, customSize) { 1675 return widgetSize; 1676 } 1677 1678 /** 1679 * 1680 * To get widget CTA icon by it's key 1681 * Added On: 09/29/2021 1682 * Added By: Chirag Thummar 1683 * 1684 * */ 1685 function getSvgIcon(iconName, widgetColor, iconColor, widgetId) { 1686 switch (iconName) { 1687 case"chat-smile": 1688 return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-496.8 507.1 54 54" style="enable-background-color:new -496.8 507.1 54 54;" xml:space="preserve"><style type="text/css">.chaty-sts1-'+widgetId+'{fill:'+ iconColor +';} .chaty-sts2{fill:none;stroke:#808080;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;}</style><g><circle cx="-469.8" cy="534.1" r="27" fill="' + widgetColor + '"/></g><path class="chaty-sts1-'+ widgetId +'" d="M-459.5,523.5H-482c-2.1,0-3.7,1.7-3.7,3.7v13.1c0,2.1,1.7,3.7,3.7,3.7h19.3l5.4,5.4c0.2,0.2,0.4,0.2,0.7,0.2c0.2,0,0.2,0,0.4,0c0.4-0.2,0.6-0.6,0.6-0.9v-21.5C-455.8,525.2-457.5,523.5-459.5,523.5z"/><path class="chaty-sts2" d="M-476.5,537.3c2.5,1.1,8.5,2.1,13-2.7"/><path class="chaty-sts2" d="M-460.8,534.5c-0.1-1.2-0.8-3.4-3.3-2.8"/></svg>'; 1689 case"chat-bubble": 1690 return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-496.9 507.1 54 54" style="enable-background-color:new -496.9 507.1 54 54;" xml:space="preserve"><style type="text/css">.chaty-sts2-'+widgetId+'{fill:'+ iconColor +';}</style><g><circle cx="-469.9" cy="534.1" r="27" fill="' + widgetColor + '"/></g><path class="chaty-sts2-'+ widgetId +'" d="M-472.6,522.1h5.3c3,0,6,1.2,8.1,3.4c2.1,2.1,3.4,5.1,3.4,8.1c0,6-4.6,11-10.6,11.5v4.4c0,0.4-0.2,0.7-0.5,0.9 c-0.2,0-0.2,0-0.4,0c-0.2,0-0.5-0.2-0.7-0.4l-4.6-5c-3,0-6-1.2-8.1-3.4s-3.4-5.1-3.4-8.1C-484.1,527.2-478.9,522.1-472.6,522.1z M-462.9,535.3c1.1,0,1.8-0.7,1.8-1.8c0-1.1-0.7-1.8-1.8-1.8c-1.1,0-1.8,0.7-1.8,1.8C-464.6,534.6-463.9,535.3-462.9,535.3z M-469.9,535.3c1.1,0,1.8-0.7,1.8-1.8c0-1.1-0.7-1.8-1.8-1.8c-1.1,0-1.8,0.7-1.8,1.8C-471.7,534.6-471,535.3-469.9,535.3z M-477,535.3c1.1,0,1.8-0.7,1.8-1.8c0-1.1-0.7-1.8-1.8-1.8c-1.1,0-1.8,0.7-1.8,1.8C-478.8,534.6-478.1,535.3-477,535.3z"/></svg>'; 1691 case"chat-db": 1692 return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-496 507.1 54 54" style="enable-background-color:new -496 507.1 54 54;" xml:space="preserve"><style type="text/css">.chaty-sts3-'+widgetId+'{fill:'+ iconColor +';}</style><g><circle cx="-469" cy="534.1" r="27" fill="' + widgetColor + '"/></g><path class="chaty-sts3-'+ widgetId +'" d="M-464.6,527.7h-15.6c-1.9,0-3.5,1.6-3.5,3.5v10.4c0,1.9,1.6,3.5,3.5,3.5h12.6l5,5c0.2,0.2,0.3,0.2,0.7,0.2c0.2,0,0.2,0,0.3,0c0.3-0.2,0.5-0.5,0.5-0.9v-18.2C-461.1,529.3-462.7,527.7-464.6,527.7z"/><path class="chaty-sts3-'+ widgetId +'" d="M-459.4,522.5H-475c-1.9,0-3.5,1.6-3.5,3.5h13.9c2.9,0,5.2,2.3,5.2,5.2v11.6l1.9,1.9c0.2,0.2,0.3,0.2,0.7,0.2c0.2,0,0.2,0,0.3,0c0.3-0.2,0.5-0.5,0.5-0.9v-18C-455.9,524.1-457.5,522.5-459.4,522.5z"/></svg>'; 1693 default: 1694 return '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-496 507.7 54 54" style="enable-background-color:new -496 507.7 54 54;" xml:space="preserve"><style type="text/css">.chaty-sts4-'+widgetId+'{fill: '+ iconColor +';}.chaty-st0{fill: #808080;}</style><g><circle cx="-469" cy="534.7" r="27" fill="' + widgetColor + '"/></g><path class="chaty-sts4-'+ widgetId +'" d="M-459.9,523.7h-20.3c-1.9,0-3.4,1.5-3.4,3.4v15.3c0,1.9,1.5,3.4,3.4,3.4h11.4l5.9,4.9c0.2,0.2,0.3,0.2,0.5,0.2 h0.3c0.3-0.2,0.5-0.5,0.5-0.8v-4.2h1.7c1.9,0,3.4-1.5,3.4-3.4v-15.3C-456.5,525.2-458,523.7-459.9,523.7z"/>
1694<path class="chaty-st0" d="M-477.7,530.5h11.9c0.5,0,0.8,0.4,0.8,0.8l0,0c0,0.5-0.4,0.8-0.8,0.8h-11.9c-0.5,0-0.8-0.4-0.8-0.8l0,0C-478.6,530.8-478.2,530.5-477.7,530.5z"/><path class="chaty-st0" d="M-477.7,533.5h7.9c0.5,0,0.8,0.4,0.8,0.8l0,0c0,0.5-0.4,0.8-0.8,0.8h-7.9c-0.5,0-0.8-0.4-0.8-0.8l0,0C-478.6,533.9-478.2,533.5-477.7,533.5z"/></svg>' 1695 } 1696 } 1697 1698 /** 1699 * 1700 * To get channel settings 1701 * Added On: 10/01/2021 1702 * Added By: Chirag Thummar 1703 * 1704 * */ 1705 1706 function getChannelSetting(channel, widgetId, toolTipPosition) { 1707 var extraClass = ""; 1708 if (isTrue(channel.is_agent)) { 1709 if (channel.agent_data.length) { 1710 var activeAgents = 0; 1711 var activeAgent = []; 1712 $.each(channel.agent_data, function (key, agent) { 1713 if (agent.value != "") { 1714 activeAgents++; 1715 activeAgent = agent; 1716 } 1717 }); 1718 if (activeAgents > 0) { 1719 var channelIcon, channelLink; 1720 var widgetIndex = getWidgetIndex(widgetId); 1721 if (widgetIndex == null) { 1722 widgetIndex = -1; 1723 } 1724 createAgentList(channel, widgetId); 1725 channelIcon = getChannelIcon(channel, widgetId); 1726 channelLink = getChannelURL(channel, channelIcon, toolTipPosition, widgetId); 1727 1728 if (channel.channel != "Instagram" || (channel.icon_color != "#ffffff" && channel.icon_color != "#fff")) { 1729 customExtraCSS += ".chaty-agent-" + widgetId + "-" + channel.channel + " .color-element {fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}"; 1730 } 1731 customExtraCSS += ".chaty-agent-" + widgetId + "-" + channel.channel + " .chaty-custom-icon { background-color: " + channel.icon_color + ";}"; 1732 customExtraCSS += ".chaty-agent-" + widgetId + "-" + channel.channel + " .chaty-svg-img { background-color: " + channel.icon_color + ";}"; 1733 return "<div data-form='chaty-form-" + widgetId + "-" + channel.channel_type + "' class='chaty-channel chaty-agent-button chaty-agent-" + widgetId + "-" + channel.channel + " " + channel.channel + "-channel" + extraClass + "' id='" + channel.channel + "-" + widgetId + "-channel' data-id='" + channel.channel_type + "-" + widgetId + "' data-widget='" + widgetId + "' data-channel='" + channel.channel + "'>" + channelLink + "</div>"; 1734 1735 } 1736 } 1737 } else { 1738 if (isValueEmpty(channel.channel_type)) { 1739 channel.channel_type = channel.channel; 1740 } 1741 var channelIcon = getChannelIcon(channel, widgetId); 1742 var channelLink = getChannelURL(channel, channelIcon, toolTipPosition, widgetId); 1743 if (channel.channel_type == "Contact_Us") { 1744 extraClass += " has-chaty-box chaty-contact-form"; 1745 } else if (channel.channel_type == "Whatsapp") { 1746 if (isTrue(channel.is_default_open)) { 1747 var clickStatus = checkChatyCookieExpired(widgetId, "c-" + channel.channel_type); 1748 if (clickStatus) { 1749 extraClass += " chaty-default-open" 1750 } 1751 } 1752 } 1753 return "<div class='chaty-channel " + channel.channel + "-channel" + extraClass + "' id='" + channel.channel + "-" + widgetId + "-channel' data-id='" + channel.channel_type + "-" + widgetId + "' data-widget='" + widgetId + "' data-channel='" + channel.channel + "'>" + channelLink + "</div>"; 1754 } 1755 } 1756 1757 1758 function createAgentList(channel, widgetId) { 1759 var formHtml = ""; 1760 var widgetIndex = getWidgetIndex(widgetId); 1761 if (widgetIndex == null) { 1762 widgetIndex = -1; 1763 } 1764 formHtml += "<div style='display:none;' class='chaty-outer-forms chaty-agent-data chaty-agent-data-" + widgetId + " chaty-form-" + widgetId + "' data-channel='" + channel.channel_type + "' id='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-widget='" + widgetId + "' data-index='" + widgetIndex + "'>"; 1765 formHtml += "<div class='chaty-form'>"; 1766 formHtml += "<div class='chaty-form-body'>"; 1767 formHtml += "<div role='button' class='chaty-close-agent-list'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 330 330'><path d='M325.607 79.393c-5.857-5.857-15.355-5.858-21.213.001l-139.39 139.393L25.607 79.393c-5.857-5.857-15.355-5.858-21.213.001s-5.858 15.355 0 21.213l150.004 150a15 15 0 0 0 21.212-.001l149.99
17676-150c5.859-5.857 5.859-15.355.001-21.213z'/></svg></div>"; 1768 formHtml += "<div class='chaty-agent-header agent-info-" + widgetId + "-" + channel.channel + "'>"; 1769 if (!isEmpty(channel.header_text)) { 1770 formHtml += "<div class='agent-main-header'>" + channel.header_text + "</div>"; 1771 } 1772 if (!isEmpty(channel.header_sub_text)) { 1773 formHtml += "<div class='agent-sub-header'>" + channel.header_sub_text + "</div>"; 1774 } 1775 formHtml += "</div>"; 1776 formHtml += "<div class='chaty-agent-body agents-body-" + widgetId + " agent-body-" + widgetId + "-" + channel.channel + "'>"; 1777 $.each(channel.agent_data, function (key, agent) { 1778 if (agent.value != "") { 1779 var agentIcon = agent.svg_icon; 1780 if (!isEmpty(agent.agent_image)) { 1781 agentIcon = "<img class='chaty-agent-img' src='" + agent.agent_image + "' alt='" + agent.agent_title + "' />" 1782 } 1783 var agentLink = getAgentURL(agent, channel, widgetId, key, agentIcon, agent.agent_title); 1784 formHtml += "<div class='chaty-agent agent-info-" + widgetId + "-" + channel.channel + " agent-info-" + key + "'>" + agentLink + "</div>"; 1785 } 1786 customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + ".agent-info-" + key + " .chaty-agent-icon img { background-color: " + agent.agent_bg_color + "; } "; 1787 if (channel.channel != "Instagram" || (agent.agent_bg_color != "#ffffff" && agent.agent_bg_color != "#fff")) { 1788 customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + ".agent-info-" + key + " .chaty-agent-icon .color-element { fill: " + agent.agent_bg_color + "; } "; 1789 } 1790 customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + ".agent-info-" + key + " .chaty-custom-icon { background-color: " + agent.agent_bg_color + "; } "; 1791 }); 1792 formHtml += "</div>"; 1793 formHtml += "</div>"; 1794 formHtml += "</div>"; 1795 formHtml += "</div>"; 1796 customExtraCSS += ".chaty-agent-header.agent-info-" + widgetId + "-" + channel.channel + " { background-color: " + channel.header_bg_color + "; color: " + channel.header_text_color + " } "; 1797 customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + " .chaty-close-agent-list svg { fill: " + channel.header_text_color + " } "; 1798 $("body").append(formHtml); 1799 } 1800 1801 function getAgentChannelURL(channel, agent, widgetId, channelIcon, toolTipPosition) { 1802 var agentURL = agent.value; 1803 var agentTarget = "_blank"; 1804 if (channel.channel_type == "Whatsapp") { 1805 var whatsAppNumber = getWhatsAppNumber(agent.value); 1806 if (isChatyInMobile) { 1807 agentTarget = ""; 1808 agentURL = "https://wa.me/" + whatsAppNumber; 1809 } else { 1810 agentTarget = "_blank"; 1811 agentURL = "https://web.whatsapp.com/send?phone=" + whatsAppNumber; 1812 } 1813 } else if (channel.channel_type == "WeChat") { 1814 agentTarget = ""; 1815 agentURL = "javascript:;"; 1816 } else if (channel.channel_type == "Email") { 1817 agentTarget = ""; 1818 agentURL = "mailto:" + agent.value; 1819 } else if (channel.channel_type == "Facebook_Messenger") { 1820 if (isChatyInMobile) { 1821 agentTarget = ""; 1822 } else { 1823 agentTarget = "_blank"; 1824 } 1825 } else if (channel.channel_type == "SMS") { 1826 agentTarget = ""; 1827 agentURL = "sms:" + agent.value; 1828 } else if (channel.channel_type == "Telegram") { 1829 agentURL = trimChar(agent.value, "@"); 1830 agentURL = "https://telegram.me/" + agentURL; 1831 agentTarget = "_blank"; 1832 } else if (channel.channel_type == "Twitter") { 1833 agentURL = "https://twitter.com/" + $.trim(agent.value); 1834 } else if (channel.channel_type == "Phone") { 1835 agentTarget = ""; 1836 agentURL = "tel:" + $.trim(agent.value); 1837 } else if (channel.channel_type == "Skype") { 1838 agentTarget = ""; 1839 agentURL = "skype:" + $.trim(agent.value) + "?chat"; 1840 } else if (channel.channel_type == "Snapchat") { 1841 agentURL = "https://www.snapchat.com/add/" + $.trim(agent.value); 1842 } else if (channel.channel_type == "Vkontakte") { 1843 agentURL = "https://vk.me/" + $.trim(agent.value); 1844 } else if (channel.channel_type == "Linkedin") { 1845 if (agent.link_type == "personal") { 1846 agentURL = "https://www.linkedin.com/in/" + $.trim(agent.value); 1847 } else { 1848 agentURL = "https://www.linkedin.com/company/" + $.trim(agent.value); 1849 } 1850 } else if (channel.channel_type == "Viber") { 1851 if(agent.viber_url != "") { 1852 agentURL = "viber://pa?chatURI=" + agent.value; 1853 } else { 1854 agentURL = trimChar(agent.value, "+"); 1855 if (!isNaN(agentURL)) { 1856 agentURL = agentURL.replace("+", ""); 1857 if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { 1858 agentURL = "+" + agentURL; 1859 } 1860 agentURL = "viber://chat?number=" + agentURL; 1861 } 1862 } 1863 agentTarget = ""; 1864 } else if (channel.channel_type == "TikTok") { 1865 agentURL = trimChar($.trim(agent.value), "@"); 1866 agentURL = "https://www.tiktok.com/@" + agentURL; 1867 agentTarget = ""; 1868 } 1869 return "<a href='" + agentURL + "' target='" + agentTarget + "' class='chaty-tooltip pos-" + toolTipPosition + "' data-form='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-hover='" + channel.hover_text + "'>" + channelIcon + "</a>"; 1870 } 1871 1872 function getAgentURL(agent, channel, widgetId, key, agentIcon, agentTitle) { 1873 var agentURL = agent.value; 1874 var agentTarget = "_blank"; 1875 if (channel.channel_type == "Whatsapp") { 1876 var whatsAppNumber = getWhatsAppNumber(agent.value); 1877 1878 var preSetMessage = ""; 1879 if (!isEmpty(agent.pre_set_message)) { 1880 preSetMessage = decodeURI(agent.pre_set_message); 1881 var pageTitle = $("title").text(); 1882 if (!isEmpty(pageTitle)) { 1883 preSetMessage = preSetMessage.replace(/{title}/g, pageTitle); 1884 } else { 1885 preSetMessage = preSetMessage.replace(/{title}/g, ''); 1886 } 1887 preSetMessage = preSetMessage.replace(/{url}/g, window.location); 1888 preSetMessage = encodeURIComponent(preSetMessage); 1889 } 1890 if (isChatyInMobile) { 1891 agentTarget = ""; 1892 agentURL = "https://wa.me/" + whatsAppNumber + "?text=" + preSetMessage; 1893 } else { 1894 agentTarget = "_blank"; 1895 if (isTrue(agent.use_whatsapp_web)) {
1896 agentURL = "https://web.whatsapp.com/send?phone=" + whatsAppNumber + "&text=" + preSetMessage; 1897 } else { 1898 agentURL = "https://wa.me/" + whatsAppNumber + "?text=" + preSetMessage; 1899 } 1900 } 1901 } else if (channel.channel_type == "WeChat") { 1902 agentTarget = ""; 1903 agentURL = "javascript:;"; 1904 } else if (channel.channel_type == "Email") { 1905 agentTarget = ""; 1906 agentURL = "mailto:" + agent.value; 1907 } else if (channel.channel_type == "Facebook_Messenger") { 1908 if (isChatyInMobile) { 1909 agentTarget = ""; 1910 } else { 1911 agentTarget = "_blank"; 1912 } 1913 } else if (channel.channel_type == "SMS") { 1914 agentTarget = ""; 1915 agentURL = "sms:" + agent.value; 1916 } else if (channel.channel_type == "Telegram") { 1917 agentURL = trimChar(agent.value, "@"); 1918 agentURL = "https://telegram.me/" + agentURL; 1919 agentTarget = "_blank"; 1920 } else if (channel.channel_type == "Twitter") { 1921 agentURL = "https://twitter.com/" + $.trim(agent.value); 1922 } else if (channel.channel_type == "Instagram") { 1923 agentURL = "https://www.instagram.com/" + trimChar(agent.value, "@"); 1924 } else if (channel.channel_type == "Phone") { 1925 agentTarget = ""; 1926 agentURL = "tel:" + $.trim(agent.value); 1927 } else if (channel.channel_type == "Skype") { 1928 agentTarget = ""; 1929 agentURL = "skype:" + $.trim(agent.value) + "?chat"; 1930 } else if (channel.channel_type == "Snapchat") { 1931 agentURL = "https://www.snapchat.com/add/" + $.trim(agent.value); 1932 } else if (channel.channel_type == "Vkontakte") { 1933 agentURL = "https://vk.me/" + $.trim(agent.value); 1934 } else if (channel.channel_type == "Linkedin") { 1935 if (agent.link_type == "personal") { 1936 agentURL = "https://www.linkedin.com/in/" + $.trim(agent.value); 1937 } else { 1938 agentURL = "https://www.linkedin.com/company/" + $.trim(agent.value); 1939 } 1940 } else if (channel.channel_type == "Viber") { 1941 if(agent.viber_url != "") { 1942 agentURL = "viber://pa?chatURI=" + agent.value; 1943 } else { 1944 agentURL = trimChar(agent.value, "+"); 1945 if (!isNaN(agentURL)) { 1946 agentURL = agentURL.replace("+", ""); 1947 if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { 1948 agentURL = "+" + agentURL; 1949 } 1950 agentURL = "viber://chat?number=" + agentURL; 1951 } 1952 } 1953 agentTarget = ""; 1954 } else if (channel.channel_type == "TikTok") { 1955 agentURL = trimChar($.trim(agent.value), "@"); 1956 agentURL = "https://www.tiktok.com/@" + agentURL; 1957 agentTarget = ""; 1958 } 1959 return "<a href='" + agentURL + "' target='" + agentTarget + "'><span class='chaty-agent-icon'>" + agentIcon + "</span><span class='chaty-agent-title'>" + agentTitle + "</span></a>"; 1960 } 1961 1962 function getWhatsAppNumber(phoneNumber) { 1963 phoneNumber = trimChar(phoneNumber, "+"); 1964 phoneNumber = phoneNumber.replace(/ /g, ""); 1965 phoneNumber = phoneNumber.replace(/-/g, ""); 1966 phoneNumber = phoneNumber.replace(/_/g, ""); 1967 return phoneNumber; 1968 } 1969 1970 1971 function trimChar(string, charToRemove) { 1972 string = $.trim(string); 1973 while (string.charAt(0) == charToRemove) { 1974 string = string.substring(1); 1975 } 1976 1977 while (string.charAt(string.length - 1) == charToRemove) { 1978 string = string.substring(0, string.length - 1); 1979 } 1980 1981 return string; 1982 } 1983 1984 1985 /** 1986 * 1987 * To get channel URL 1988 * Added On: 10/01/2021 1989 * Added By: Chirag Thummar 1990 * 1991 * */ 1992 function getChannelURL(channel, channelIcon, toolTipPosition, widgetId) { 1993 var extraClass = ""; 1994 if (isTrue(channel.is_agent)) { 1995 channel.url = "javascript:;"; 1996 channel.target = ""; 1997 } else { 1998 if (channel.channel_type == "Whatsapp") { 1999 if (isTrue(channel.has_welcome_message)) { 2000 channel.url = "javascript:;"; 2001 channel.target = ""; 2002 extraClass += " has-chaty-box chaty-whatsapp-btn-form"; 2003 startMakingWhatsAppPopup(channel, widgetId); 2004 } else { 2005 var preSetMessage = ""; 2006 if (!isEmpty(channel.pre_set_message)) { 2007 preSetMessage = decodeURI(channel.pre_set_message); 2008 var pageTitle = $("title").text(); 2009 if (!isEmpty(pageTitle)) { 2010 preSetMessage = preSetMessage.replace(/{title}/g, pageTitle); 2011 } else { 2012 preSetMessage = preSetMessage.replace(/{title}/g, ''); 2013 } 2014 preSetMessage = preSetMessage.replace(/{url}/g, window.location); 2015 preSetMessage = encodeURIComponent(preSetMessage); 2016 } 2017 if (isChatyInMobile) { 2018 channel.target = ""; 2019 channel.url = "https://wa.me/" + channel.value + "?text=" + preSetMessage; 2020 } else { 2021 channel.target = "_blank"; 2022 if (isTrue(channel.is_use_web_version)) { 2023 channel.url = "https://web.whatsapp.com/se
2023nd?phone=" + channel.value + "&text=" + preSetMessage; 2024 } else { 2025 channel.url = "https://wa.me/" + channel.value + "?text=" + preSetMessage; 2026 } 2027 } 2028 } 2029 } else if (channel.channel_type == "WeChat") { 2030 if (!isEmpty(channel.qr_code_image_url)) { 2031 startMakingWeChatChannel(channel, widgetId); 2032 channel.url = "javascript:;"; 2033 channel.target = ""; 2034 extraClass += " has-chaty-box chaty-qr-code-form"; 2035 } 2036 } else if (channel.channel_type == "Contact_Us") { 2037 startMakingContactForm(channel, widgetId); 2038 channel.url = "javascript:;"; 2039 channel.target = ""; 2040 extraClass += " has-chaty-box chaty-contact-us-form"; 2041 } else if (channel.channel_type == "Email") { 2042 if (!isEmpty(channel.mail_subject)) { 2043 var mailSubject = decodeURI(channel.mail_subject); 2044 var pageTitle = $("title").text(); 2045 if (!isEmpty(pageTitle)) { 2046 mailSubject = mailSubject.replace(/{title}/g, pageTitle); 2047 } else { 2048 mailSubject = mailSubject.replace(/{title}/g, ''); 2049 } 2050 mailSubject = mailSubject.replace(/{url}/g, window.location); 2051 mailSubject = encodeURIComponent(mailSubject); 2052 channel.url += "?subject=" + mailSubject; 2053 } 2054 } else if (channel.channel_type == "Viber") { 2055 if(channel.viber_url != "") { 2056 channel.url = "viber://pa?chatURI=" + channel.value; 2057 } else { 2058 channel.value = trimChar(channel.value, "+"); 2059 if (isChatyInMobile && !isNaN(channel.value)) { 2060 // channel.value = channel.value.replace("+", ""); 2061 if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { 2062 channel.value = "+" + channel.value; 2063 } 2064 } 2065 channel.url = "viber://chat?number=" + channel.value; 2066 } 2067 channel.target = ""; 2068 } else if (channel.channel_type == "Vkontakte") { 2069 channel.url = "https://vk.me/" + $.trim(channel.value); 2070 } 2071 } 2072 if(channel.channel == "Link" || channel.channel == "Custom_Link" || channel.channel == "Custom_Link_3" || channel.channel == "Custom_Link_4" || channel.channel == "Custom_Link_5") { 2073 if(!isEmpty(channel.hover_text)) { 2074 ariaLabel = channel.hover_text; 2075 } else { 2076 ariaLabel = channel.channell 2077 } 2078 }else { 2079 ariaLabel = channel.channel; 2080 } 2081 2082 var onClickFn = ""; 2083 if (!isEmpty(channel.click_event)) { 2084 onClickFn = 'onclick="' + channel.click_event + '"'; 2085 channel.target = ""; 2086 channel.url = "javascript:;"; 2087 } 2088 return "<a href='" + channel.url + "' " + onClickFn + " target='" + channel.target + "' rel='nofollow noopener' aria-label='" + ariaLabel + "' class='chaty-tooltip chaty-link chaty-"+(channel.channel_type).toLowerCase()+"-channel pos-" + toolTipPosition + extraClass + "' data-form='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-hover='" + channel.hover_text + "'>" + channelIcon + "</a>"; 2089 } 2090 2091 function startMakingContactForm(channel, widgetId) { 2092 var formHtml = ""; 2093 var widgetIndex = getWidgetIndex(widgetId); 2094 if (widgetIndex == null) { 2095 widgetIndex = -1; 2096 } 2097 formHtml += "<div style='display:none;' class='chaty-outer-forms chaty-contact-form-box chaty-form-" + widgetId + "' data-channel='" + channel.channel_type + "' id='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-widget='" + widgetId + "' data-index='" + widgetIndex + "'>"; 2098 formHtml += "<div class='chaty-form'>"; 2099 formHtml += "<div class='chaty-form-body'>";
2100 formHtml += "<div role='button' class='close-chaty-form'>" + 2101 "<div aria-hidden='true' class='chaty-close-button'></div>" + 2102 "<span class='hide-cht-svg-bg'>"+chaty_settings.lang.hide_whatsapp_form+"</span>" + 2103 "</div>"; 2104 formHtml += "<form class='chaty-ajax-contact-form' id='chaty-ajax-contact-form-" + widgetIndex + "' method='post' data-channel='" + channel.channel_type + "' data-widget='" + widgetId + "' data-token='" + channel.widget_token + "' data-index='" + channel.widget_index + "' enctype='multipart/form-data'>"; 2105 formHtml += "<div class='chaty-contact-form-body'>"; 2106 formHtml += "<div class='chaty-contact-form-title'>" + 2107 "<div class='form-title'>" + channel.contact_form_settings.contact_form_title + "</div>" + 2108 "<div aria-hidden='true' class='chaty-close-button'>" + 2109 "<span class='hide-cht-svg-bg'>"+chaty_settings.lang.hide_whatsapp_form+"</span>" + 2110 "<svg width='15' height='9' viewBox='0 0 15 9' fill='none' xmlns='http://www.w3.org/2000/svg'> <path d='M1 1L7.31429 8L14 1' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'></path></svg>" + 2111 "</div>" + 2112 "</div>"; 2113 formHtml += "<div class='chaty-contact-inputs'>"; 2114 2115 $.each(channel.contact_fields, function (key, contactField) { 2116 formHtml += "<div class='chaty-contact-input'>"; 2117 var isRequired = isTrue(contactField.is_required) ? "is-required" : ""; 2118 var required_indicator = ""; 2119 if(isTrue(contactField.is_required)) { 2120 required_indicator = "<span class='required_indicate'>*</span>" 2121 } 2122 if (isTrue(contactField.is_custom)) { 2123 formHtml += "<label class='chaty-form-label' for='" + contactField.field_dropdown + "-" + key + "'>" + contactField.field_label + " " + required_indicator + "</label>"; 2124 formHtml += "<input type='hidden' name='custom_fields[" + key + "][label_" + contactField.field_dropdown + "]' value='" + contactField.field_label + "'>"; 2125 formHtml += "<input type='hidden' name='custom_fields[" + key + "][slug]' value='" + contactField.field_dropdown + "'>"; 2126 2127 if (contactField.field_dropdown == 'text' || contactField.field_dropdown == 'url' || contactField.field_dropdown == 'date') { 2128 formHtml += "<input type='" + contactField.field_dropdown + "' class='chaty-input-field " + isRequired + " field-" + contactField.field_dropdown + "' placeholder='" + contactField.placeholder + "' name='custom_fields[" + key + "][" + contactField.field_dropdown + "]' id='" + contactField.field_dropdown + "-" + key + "' />" 2129 } else if (contactField.field_dropdown == "file") { 2130 formHtml += "<input type='file' class='chaty-input-field " + isRequired + " field-" + contactField.field_dropdown + "' name='custom_fields[" + key + "][" + contactField.field_dropdown + "]' id='" + contactField.field_dropdown + "-" + key + "' accept='.jpg,.jpeg,.png,.gif,.pdf,.doc,.docx,.ppt,.pptx,.pps,.ppsx,.odt,.xls,.xlsx,.mp3,.mp4,.wav,.mpg,.avi,.mov,.wmv,.3gp,.ogv' multiple/>" 2131 } else if (contactField.field_dropdown == "textarea") { 2132 formHtml += "<textarea class='chaty-textarea-field " + isRequired + " field-" + contactField.field_dropdown + "' placeholder='" + contactField.placeholder + "' name='custom_fields[" + key + "][" + contactField.field_dropdown + "]' id='" + contactField.field_dropdown + "-" + key + "' ></textarea>" 2133 } else if (contactField.field_dropdown == "dropdown") { 2134 formHtml += "<select name='custom_fields[" + key + "][" + contactField.field_dropdown + "]' class='chaty-input-field " + isRequired + "'>"; 2135 if (contactField.dropdown_placeholder) { 2136 formHtml += "<option value=''>" + contactField.dropdown_placeholder + "</option>"; 2137 } 2138 $.each(contactField.dropdown_option, function (key, val) { 2139 if (val) { 2140 formHtml += "<option value='"+val+"'>" + val + "</option>"; 2141 } 2142 }); 2143 formHtml += "</select>"; 2144 } else if (contactField.field_dropdown == "textblock") { 2145 formHtml += contactField.placeholder; 2146 } else if (contactField.field_dropdown == 'number') { 2147 formHtml += "<input type='tel' class='chaty-input-field " + isRequired + " field-" + contactField.field_dropdown + "' placeholder='" + contactField.placeholder + "' name='custom_fields[" + key + "][" + contactField.field_dropdown + "]' id='" + contactField.field_dropdown + "-" + key + "' />" 2148 } 2149 } else { 2150 if (contactField.type == "textarea") { 2151 if (!isEmpty(contactField.title)) { 2152 formHtml += "<label class='chaty-form-label' for='" + contactField.field + "-" + widgetId + "'>" + contactField.title + " " + required_indicator + "</label>"; 2153 } else { 2154 formHtml += "<label class='sr-only' for='" + contactField.field + "-" + widgetId + "'>" + contactField.field + "</label>"; 2155 } 2156 formHtml += "<textarea type='" + contactField.type + "' class='chaty-textarea-field " + isRequired + " field-" + contactField.field + "' placeholder='" + contactField.placeholder + "' name='" + contactField.field + "' id='" + contactField.field + "-" + widgetId + "' ></textarea>" 2157 } else { 2158 if (!isEmpty(contactField.title)) { 2159 formHtml += "<label class='chaty-form-label' for='" + contactField.field + "-" + widgetId + "'>" + contactField.title + " " + required_indicator + "</label>"; 2160 } else { 2161 formHtml += "<label class='sr-only' for='" + contactField.field + "-" + widgetId + "'>" + contactField.field + "</label>"; 2162 } 2163 formHtml += "<input type='" + contactField.type + "' class='chaty-input-field " + isRequired + " field-" + contactField.field + "' placeholder='" + contactField.placeholder + "' name='" + contactField.field + "' id='" + contactField.field + "-" + widgetId + "' />" 2164 if (contactField.field == "email") { 2165 formHtml += '<p id="email_suggestion' + widgetId + '" class="email_suggestion"></p>'; 2166 } 2167 } 2168 } 2169 formHtml += "</div>"; 2170 2171 }); 2172 2173 2174 if(isTrue(channel.enable_recaptcha)) { 2175 if (!isEmpty(channel.v2_site_key)) { 2176 formHtml += "<div class='chaty-contact-input'>"; 2177 formHtml += "<div class='front-google-captcha' id='front_recaptcha_" + widgetIndex + "'></div>"; 2178 formHtml += "</div>"; 2179 } 2180 if (!isEmpty(channel.v3_site_key)) { 2181 formHtml += "<div class='chaty-contact-input'>"; 2182 formHtml += "<div class='front-google-captcha' id='front_recaptcha_" + widgetIndex + "'></div>"; 2183 formHtml += "</div>"; 2184 } 2185 } 2186 formHtml += "</div>"; // chaty-contact-inputs 2187 formHtml += "<div class='chaty-contact-form-button'><button type='submit' id='chaty-submit-button-" + widgetId + "' class='chaty-submit-button'>" + channel.contact_form_settings.button_text + "<span class='chaty-loader'><span class='dashicons dashicons-update'></span></span></button></div>"; 2188 formHtml += "</div>"; // chaty-contact-form-body 2189 formHtml += "<input type='hidden' name='nonce' value='"+channel.widget_token+"'>"; 2190 formHtml += "<input type='hidden' name='action' value='chaty_front_form_save_data'>"; 2191 formHtml += '<input type="hidden" name="channel" value="'+channel.channel_type+'">'; 2192 formHtml += '<input type="hidden" name="widget" value="'+widgetId+'">'; 2193 formHtml += '<input type="hidden" name="ref_url" value="'+window.location.href+'">'; 2194 formHtml += '<input type="hidden" name="token" value="'+googleV3Token+'">'; 2195 formHtml += '<input type="hidden" name="page_id" value="'+chaty_settings.page_id+'">'; 2196 formHtml += '<input type="hidden" name="page_title" value="'+getPageTitle()+'">'; 2197
2198 var v2_captcha_response = $(".g-recaptcha-response").length ? $(".g-recaptcha-response").val() : ""; 2199 formHtml += '<input type="hidden" name="v2token" value="'+v2_captcha_response+'">'; 2200 if(isTrue(channel.enable_recaptcha)) { 2201 if (!isEmpty(channel.v2_site_key)) { 2202 formHtml += "<input type='hidden' id='v2_site_key' class='v2_site_key' value='" + channel.v2_site_key + "'>"; 2203 } 2204 if (!isEmpty(channel.v3_site_key)) { 2205 formHtml += "<input type='hidden' id='v3_site_key' class='v3_site_key' value='" + channel.v3_site_key + "'>"; 2206 } 2207 } 2208 formHtml += "</form>"; 2209 formHtml += "</div>"; 2210 formHtml += "</div>"; 2211 formHtml += "</div>"; 2212 $("body").append(formHtml); 2213 2214 // setChatyEditor(); 2215 2216 } 2217 2218 /** 2219 * 2220 * to make WhatsApp popup form 2221 * Added On: 11/01/2021 2222 * Added By: Chirag Thummar 2223 * 2224 * */ 2225 function startMakingWhatsAppPopup(channel, widgetId) { 2226 const currentDate = new Date(); 2227 var currentMinute = (currentDate.getMinutes() < 10) ? "0"+currentDate.getMinutes() : currentDate.getMinutes(); 2228 var currentHour = (currentDate.getHours() < 10) ? "0"+currentDate.getHours() : currentDate.getHours(); 2229 const time = currentHour + ":" + currentMinute; 2230 var formHtml = ""; 2231 var widgetIndex = getWidgetIndex(widgetId); 2232 if (widgetIndex == null) { 2233 widgetIndex = -1; 2234 } 2235 var formAction = "https://web.whatsapp.com/send"; 2236 var formTarget = ""; 2237 if (!isChatyInMobile) { 2238 if (isTrue(channel.is_use_web_version)) { 2239 formAction = "https://web.whatsapp.com/send"; 2240 } else { 2241 formAction = "https://wa.me/" + channel.value; 2242 } 2243 formTarget = "_blank"; 2244 } else { 2245 formAction = "https://wa.me/" + channel.value; 2246 } 2247 formHtml += "<div style='display:none;' class='chaty-outer-forms chaty-popup-whatsapp-form chaty-whatsapp-btn-form chaty-form-" + widgetId + "' data-channel='" + channel.channel_type + "' id='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-widget='" + widgetId + "' data-index='" + widgetIndex + "'>"; 2248 formHtml += "<div class='chaty-whatsapp-form'>"; 2249 2250 var headerTitle = !isEmpty(channel.wp_popup_headline)?channel.wp_popup_headline:""; 2251 formHtml += "<div class='chaty-whatsapp-header'>"; 2252 formHtml += "<div class='header-wp-icon'>"; 2253 formHtml += '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="33" viewBox="0 0 32 33" fill="none"> <g filter="url(#filter0_f_9477_7201)"> <path d="M9.95924 25.2858L10.3674 25.5276C12.0818 26.545 14.0475 27.0833 16.052 27.0842H16.0562C22.2122 27.0842 27.2221 22.0753 27.2247 15.919C27.2258 12.9357 26.0652 10.1303 23.9565 8.01998C22.9223 6.97924 21.6919 6.15397 20.3365 5.59195C18.9812 5.02992 17.5278 4.74231 16.0606 4.74576C9.89989 4.74576 4.88975 9.75407 4.88756 15.91C4.88453 18.0121 5.47648 20.0722 6.59498 21.852L6.86071 22.2742L5.73223 26.394L9.95924 25.2858ZM2.50586 29.5857L4.41235 22.6249C3.23657 20.5878 2.618 18.2768 2.61873 15.9091C2.62183 8.50231 8.64941 2.47656 16.0564 2.47656C19.6508 2.47839 23.0245 3.87717 25.5618 6.41629C28.0991 8.95542 29.4952 12.3305 29.4939 15.9199C29.4906 23.3262 23.4621 29.353 16.0562 29.353H16.0504C13.8016 29.3521 11.592 28.788 9.62923 27.7177L2.50586 29.5857Z" fill="#B3B3B3"/> </g> <path d="M2.36719 29.447L4.27368 22.4862C3.09587 20.4442 2.47721 18.1278 2.48005 15.7705C2.48316 8.36364 8.51074 2.33789 15.9177 2.33789C19.5121 2.33972 22.8859 3.73849 25.4232 6.27762C27.9605 8.81675 29.3565 12.1918 29.3552 15.7812C29.3519 23.1875 23.3234 29.2143 15.9175 29.2143H15.9117C13.663 29.2134 11.4533 28.6493 9.49056 27.5791L2.36719 29.447Z" fill="white"/> <path d="M15.715 3.84769C9.17146 3.84769 3.85 9.16696 3.84767 15.7051C3.84445 17.9377 4.47318 20.1257 5.66119 22.016L5.94343 22.4646L4.48888 27.2525L9.23469 25.663L9.66824 25.9199C11.4891 27.0005 13.5769 27.5719 15.7061 27.5731H15.7105C22.249 27.5731 27.5705 22.2532 27.573 15.7146C27.5779 14.1562 27.2737 12.6123 26.6778 11.1722C26.082 9.73214 25.2064 8.42458 24.1017 7.3252C23.0032 6.21981 21.6963 5.34329 20.2567 4.74637C18.8171 4.14946 17.2734 3.844 15.715 3.84769Z" fill="#25D366"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M12.0858 9.60401C11.8138 9.00922 11.5276 8.99717 11.2692 8.98687L10.5736 8.97852C10.3316 8.97852 9.93846 9.0679 9.60608 9.42544C9.27369 9.78297 8.33594 10.6471 8.33594 12.4046C8.33594 14.1622 9.63628 15.8605 9.81747 16.0991C9.99866 16.3377 12.3277 20.0594 16.
22530162 21.4913C19.0813 22.6813 19.705 22.4446 20.3706 22.3852C21.0361 22.3257 22.5175 21.521 22.8197 20.6869C23.1219 19.8527 23.1221 19.138 23.0315 18.9886C22.9409 18.8391 22.6989 18.7503 22.3357 18.5716C21.9725 18.3928 20.1888 17.5287 19.8562 17.4094C19.5236 17.2901 19.2818 17.2308 19.0396 17.5883C18.7975 17.9459 18.1029 18.7501 17.8911 18.9886C17.6793 19.227 17.4679 19.2569 17.1047 19.0783C16.7416 18.8998 15.5731 18.5224 14.1867 17.3054C13.108 16.3585 12.3799 15.1892 12.1679 14.8318C11.9559 14.4745 12.1454 14.2809 12.3274 14.1029C12.4902 13.9428 12.6901 13.6858 12.8719 13.4773C13.0537 13.2688 13.1135 13.1197 13.2343 12.8817C13.3551 12.6437 13.2949 12.4346 13.2041 12.256C13.1133 12.0774 12.4083 10.3105 12.0858 9.60401Z" fill="white"/> <defs> <filter id="filter0_f_9477_7201" x="1.21611" y="1.18682" width="29.5678" height="29.6889" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB"> <feFlood flood-opacity="0" result="BackgroundImageFix"/> <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/> <feGaussianBlur stdDeviation="0.644873" result="effect1_foregroundBlur_9477_7201"/> </filter> </defs> </svg>'; 2254 formHtml += "</div>"; 2255 formHtml += "<div class='header-wp-title'>"; 2256 formHtml += headerTitle; 2257 formHtml += "</div>"; 2258 formHtml += "<div class='whatsapp-form-close-btn'>"; 2259 formHtml += '<svg width="15" height="9" viewBox="0 0 15 9" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 1L7.31429 8L14 1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </svg>'; 2260 formHtml += "</div>"; 2261 formHtml += "</div>"; 2262 2263 2264 formHtml += "<div class='chaty-whatsapp-body'>"; 2265 if(!isEmpty(channel.chat_welcome_message)) { 2266 if (channel.wp_popup_profile != "") { 2267 formHtml += "<div class='chaty-whatsapp-content has-content'>"; 2268 formHtml += "<div class='wp-profile-img'>"; 2269 formHtml += "<img src='" + channel.wp_popup_profile + "'>" 2270 formHtml += "</div>"; 2271 } else { 2272 formHtml += "<div class='chaty-whatsapp-content'>"; 2273 } 2274 formHtml += "<div class='chaty-whatsapp-message'>"; 2275 formHtml += "<div class='chaty-whatsapp-message-nickname'>" + channel.wp_popup_nickname + "</div>"; 2276 formHtml += "<div class='chaty-whatsapp-message-content'></div>"; 2277 formHtml += "<div class='chaty-whatsapp-message-time'>" + time + "</div>" 2278 formHtml += "</div>"; 2279 formHtml += "</div>"; 2280 } 2281 formHtml += "</div>"; 2282 formHtml += "<div class='chaty-whatsapp-footer'>"; 2283 formHtml += "<form action='" + formAction + "' target='" + formTarget + "' class='whatsapp-chaty-form-" + widgetId + " whatsapp-chaty-form " + (isTrue(channel.is_default_open) ? "add-analytics" : "") + "' data-widget='" + widgetId + "' data-channel='" + channel.channel_type + "' autocomplete='off'>"; 2284 formHtml += "<div class='chaty-whatsapp-data'>"; 2285 formHtml += `<div class='chaty-whatsapp-field ${(isTrue(channel.emoji_picker))?"has_emoji":""}'>`; 2286 if(isTrue(channel.emoji_picker)) { 2287 formHtml += '<button type="button" class="chaty-wp-emoji-input"><span class="hide-cht-svg-bg">"+chaty_settings.lang.emoji_picker+"</span><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M12 2C6.47 2 2 6.5 2 12C2 14.6522 3.05357 17.1957 4.92893 19.0711C5.85752 19.9997 6.95991 20.7362 8.17317 21.2388C9.38642 21.7413 10.6868 22 12 22C14.6522 22 17.1957 20.9464 19.0711 19.0711C20.9464 17.1957 22 14.6522 22 12C22 10.6868 21.7413 9.38642 21.2388 8.17317C20.7362 6.95991 19.9997 5.85752 19.0711 4.92893C18.1425 4.00035 17.0401 3.26375 15.8268 2.7612C14.6136 2.25866 13.3132 2 12 2ZM15.5 8C15.8978 8 16.2794 8.15804 16.5607 8.43934C16.842 8.72064 17 9.10218 17 9.5C17 9.89782 16.842 10.2794 16.5607 10.5607C16.2794 10.842 15.8978 11 15.5 11C15.1022 11 14.7206 10.842 14.4393 10.5607C14.158 10.2794 14 9.89782 14 9.5C14 9.10218 14.158 8.72064 14.4393 8.43934C14.7206 8.15804 15.1022 8 15.5 8ZM8.5 8C8.89782 8 9.27936 8.15804 9.56066 8.43934C9.84196 8.72064 10 9.10218 10 9.5C10 9.89782 9.84196 10.2794 9.56066 10.5607C9.27936 10.842 8.89782 11 8.5 11C8.10218 11 7.72064 10.842 7.43934 10.5607C7.15804 10.2794 7 9.89782 7 9.5C7 9.10218 7.
228715804 8.72064 7.43934 8.43934C7.72064 8.15804 8.10218 8 8.5 8ZM12 17.5C9.67 17.5 7.69 16.04 6.89 14H17.11C16.3 16.04 14.33 17.5 12 17.5Z" fill="#CDD9E2"/> </svg></button>'; 2288 } 2289 formHtml += "<input name='text' type='text' id='chaty_whatsapp_input' class='chaty-whatsapp-input' />"; 2290 formHtml += "<button type='submit' class='chaty-whatsapp-button-button' >"; 2291 formHtml += "<span class='hide-cht-svg-bg'>"+chaty_settings.lang.whatsapp_button+"</span>"; 2292 formHtml += '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none"><g clip-path="url(#clip0_9452_6982)"><path d="M18.5703 9.99996L2.66037 17.6603L5.60665 9.99996L2.66037 2.33963L18.5703 9.99996Z" fill="white" stroke="white" stroke-width="1.6625" stroke-linecap="round" stroke-linejoin="round"></path><path d="M8.24069 9.99947L3.07723 9.99992" stroke="#C6D7E3" stroke-width="1.6625" stroke-linecap="round" stroke-linejoin="round"></path></g><defs><clipPath id="clip0_9452_6982"><rect width="20" height="20" fill="white"></rect></clipPath></defs></svg>'; 2293 formHtml += "</button>"; 2294 formHtml += "</div>"; 2295 formHtml += "</div>"; 2296 if (!isChatyInMobile && isTrue(channel.is_use_web_version)) { 2297 formHtml += "<input type='hidden' name='phone' value='" + channel.value + "' />"; 2298 } 2299 formHtml += "</form>"; 2300 formHtml += "</div>"; 2301 formHtml += "</div>"; 2302 formHtml += "</div>"; 2303 $("body").append(formHtml); 2304 $("#chaty-form-" + widgetId + "-" + channel.channel_type + " .chaty-whatsapp-message .chaty-whatsapp-message-content").html(channel.chat_welcome_message); 2305 if (!isEmpty(channel.pre_set_message)) { 2306 var preSetMessage = channel.pre_set_message; 2307 var pageTitle = $("title").text(); 2308 if (!isEmpty(pageTitle)) { 2309 preSetMessage = preSetMessage.replace(/{title}/g, pageTitle); 2310 } else { 2311 preSetMessage = preSetMessage.replace(/{title}/g, ''); 2312 } 2313 preSetMessage = preSetMessage.replace(/{url}/g, window.location); 2314 $("#chaty-form-" + widgetId + "-" + channel.channel_type + " .chaty-whatsapp-input").val(preSetMessage); 2315 } 2316 $("#chaty-form-" + widgetId + "-" + channel.channel_type + " .chaty-whatsapp-input").attr("placeholder", channel.input_placeholder); 2317 $("#chaty-form-" + widgetId + "-" + channel.channel_type).show(); 2318 $("#chaty-form-" + widgetId + "-" + channel.channel_type+" .chaty-whatsapp-header").css("background-color", channel.wp_popup_head_bg_color); 2319 2320 } 2321 2322 2323 /** 2324 * 2325 * To decode HTML Tag 2326 * Added On: 07/17/2022 2327 * Added By: Chirag Thummar 2328 * 2329 * */ 2330 2331 function htmlDecode(input) { 2332 var doc = new DOMParser().parseFromString(input, "text/html"); 2333 return doc.documentElement.textContent; 2334 } 2335 2336 /** 2337 * 2338 * To get widget index 2339 * Added On: 11/01/2021 2340 * Added By: Chirag Thummar 2341 * 2342 * */ 2343 function getWidgetIndex(widgetId) { 2344 var widgetIndex = null; 2345 if (widgetData.length) { 2346 $.each(widgetData, function (key, widgetRecord) { 2347 if (widgetRecord.id == widgetId) { 2348 widgetIndex = key; 2349 } 2350 }); 2351 } 2352 return widgetIndex; 2353 } 2354 2355 /** 2356 * 2357 * to make WhatsApp popup form 2358 * Added On: 11/02/2021 2359 * Added By: Chirag Thummar 2360 * 2361 * */ 2362 function startMakingWeChatChannel(channel, widgetId) { 2363 var formHtml = ""; 2364 var widgetIndex = getWidgetIndex(widgetId); 2365 if (widgetIndex == null) { 2366 widgetIndex = -1; 2367 } 2368 var qrCodeTitle = !isEmpty(channel.wechat_header)?(channel.wechat_header+": "):""; 2369 qrCodeTitle += channel.value; 2370 formHtml += "<div style='display:none;' class='chaty-outer-forms chaty-wechat-form chaty-form-" + widgetId + "' data-channel='" + channel.channel_type + "' id='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-widget='" + widgetId + "' data-index='" + widgetIndex + "'>"; 2371 formHtml += "<div class='chaty-form'>"; 2372 formHtml += "<div class='chaty-form-body qr-code-body'>"; 2373 formHtml += '<div class="qr-code-header"><div class="qr-code-head-title"><svg width="25" height="22" viewBox="0 0 25 22" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M17.2315 6.81844C17.6918 6.81844 18.1403 6.85385 18.5769 6.91286C17.7744 3.40752 14.092 0.751953 9.66605 0.751953C4.64999 0.751953 0.578125 4.15108 0.578125 8.34096C0.578125 10.7605 1.93541 12.8967 4.04806 14.2894L2.85601 16.6853L6.1135 15.2808C6.80985 15.5287 7.5416 15.7293 8.32057 15.8356C8.21435 15.3753 8.15533 14.9032 8.15533 14.4075C8.14353 10.2294 12.2154 6.81844 17.2315 6.81844ZM12.6875 4.16288C12.8363 4.16288 12.9836 4.19218 13.1211 4.24912C13.2586 4.30607 13.3835 4.38952 13.4887 4.49474C13.5939 4.59995 13.6773 4.72486 13.7343 4.86232C13.7912 4.99979
237313.8205 5.14712 13.8205 5.29592C13.8205 5.44471 13.7912 5.59205 13.7343 5.72951C13.6773 5.86698 13.5939 5.99189 13.4887 6.0971C13.3835 6.20231 13.2586 6.28577 13.1211 6.34271C12.9836 6.39965 12.8363 6.42896 12.6875 6.42896C12.387 6.42896 12.0988 6.30958 11.8863 6.0971C11.6738 5.88461 11.5545 5.59642 11.5545 5.29592C11.5545 4.99542 11.6738 4.70722 11.8863 4.49474C12.0988 4.28225 12.387 4.16288 12.6875 4.16288ZM6.63281 6.44076C6.33231 6.44076 6.04412 6.32139 5.83163 6.1089C5.61914 5.89641 5.49977 5.60822 5.49977 5.30772C5.49977 5.00722 5.61914 4.71903 5.83163 4.50654C6.04412 4.29405 6.33231 4.17468 6.63281 4.17468C6.93331 4.17468 7.2215 4.29405 7.43399 4.50654C7.64648 4.71903 7.76585 5.00722 7.76585 5.30772C7.76585 5.60822 7.64648 5.89641 7.43399 6.1089C7.2215 6.32139 6.93331 6.44076 6.63281 6.44076Z" fill="white"/> <path d="M24.7978 14.4102C24.7978 11.0583 21.4105 8.34375 17.2324 8.34375C13.0543 8.34375 9.66699 11.0583 9.66699 14.4102C9.66699 17.7621 13.0543 20.4767 17.2324 20.4767C17.9169 20.4767 18.5779 20.3823 19.2034 20.2407L23.2871 21.9992L21.8708 19.1666C23.6412 18.0572 24.7978 16.3577 24.7978 14.4102ZM14.9545 14.0326C14.7304 14.0326 14.5114 13.9661 14.325 13.8416C14.1387 13.7171 13.9935 13.5401 13.9077 13.3331C13.822 13.1261 13.7995 12.8983 13.8432 12.6785C13.887 12.4587 13.9949 12.2568 14.1533 12.0983C14.3118 11.9399 14.5137 11.832 14.7335 11.7882C14.9533 11.7445 15.1811 11.767 15.3881 11.8527C15.5951 11.9385 15.7721 12.0837 15.8966 12.27C16.0211 12.4564 16.0876 12.6754 16.0876 12.8995C16.0994 13.525 15.58 14.0326 14.9545 14.0326ZM19.4985 14.0326C19.198 14.0326 18.9098 13.9132 18.6973 13.7007C18.4848 13.4882 18.3654 13.2 18.3654 12.8995C18.3654 12.599 18.4848 12.3108 18.6973 12.0983C18.9098 11.8858 19.198 11.7665 19.4985 11.7665C19.799 11.7665 20.0872 11.8858 20.2997 12.0983C20.5121 12.3108 20.6315 12.599 20.6315 12.8995C20.6315 13.2 20.5121 13.4882 20.2997 13.7007C20.0872 13.9132 19.799 14.0326 19.4985 14.0326Z" fill="white"/> </svg>'+qrCodeTitle+'</div><div class="qr-code-hide-btn chaty-close-button"><svg width="15" height="9" viewBox="0 0 15 9" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M1 1L7.31429 8L14 1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </svg></div></div>'; 2374 if(!isEmpty(channel.wechat_qr_code_title)) { 2375 formHtml += '<div class="qr-code-title">'+channel.wechat_qr_code_title+':</div>'; 2376 } 2377 formHtml += "<div role='button' class='close-chaty-form is-whatsapp-btn'><div aria-hidden='true' class='chaty-close-button'></div><span class='hide-cht-svg-bg'>"+chaty_settings.lang.hide_whatsapp_form+"</span></div></div>"; 2378 formHtml += "<div class='qr-code-box'><div class='qr-code-image'><img src='" + channel.qr_code_image_url + "' alt='" + channel.title + "' /></div>"; 2379 formHtml += "</div>"; 2380 formHtml += "</div>"; 2381 formHtml += "</div>"; 2382 $("body").append(formHtml); 2383 2384 $("#chaty-form-" + widgetId + "-" + channel.channel_type +" .qr-code-header").css("background-color",channel.wechat_header_color); 2385 } 2386 2387 /** 2388 * 2389 * get tooltip position for channel 2390 * Added On: 09/29/2021 2391 * Added By: Chirag Thummar 2392 * 2393 * */ 2394 function isEmpty(varVal) { 2395 if (varVal == null || varVal == "" || $.trim(varVal) == "") { 2396 return true 2397 } 2398 return false; 2399 } 2400 2401 /** 2402 * 2403 * To get channel icon 2404 * Added On: 10/01/2021 2405 * Added By: Chirag Thummar 2406 * 2407 * */ 2408 function getChannelIcon(channel) { 2409 if (channel.custom_image_url != "" && channel.custom_image_url != "null") { 2410 return "<span class='chaty-icon channel-icon-" + channel.channel_type + "'><span class='chaty-svg chaty-svg-img'><img src='" + channel.custom_image_url + "' alt='" + channel.hover_text + "' /></span></span>"; 2411 } 2412 return "<span class='chaty-icon channel-icon-" + channel.channel_type + "'><span class='chaty-svg'>" + channel.svg_icon + "</span></span>"; 2413 } 2414 2415 /** 2416 * 2417 * check for empty or null items 2418 * Added On: 10/01/2021 2419 * Added By: Chirag Thummar 2420 * 2421 * */ 2422 function isValueEmpty(value) { 2423 if (value == "" || $.trim(value) == "" || value == null || value == "null") { 2424 return true; 2425 } 2426 return false; 2427 } 2428 2429 /** 2430 * 2431 * To get widget position 2432 * Added On: 10/01/2021 2433 * Added By: Chirag Thummar 2434 * 2435 * */ 2436 function getWidgetPosition(widgetRecord) { 2437 if (widgetRecord.position == "custom") { 2438 return widgetRecord.custom_position; 2439 } 2440 return widgetRecord.position; 2441 } 2442 2443 /** 2444 * 2445 * get tooltip position for channel 2446 * Added On: 09/29/2021 2447 * Added By: Chirag Thummar 2448 * 2449 * */ 2450 function getToolTipPosition(widgetRecord) { 2451 if (widgetRecord.settings.icon_view != "vertical") { 2452 return "top"; 2453 } 2454 var toolTipPosition = getWidgetPosition(widgetRecord.settings); 2455 if (toolTipPosition == "right") { 2456 return "left"; 2457 } 2458 return "right"; 2459 } 2460 2461 /** 2462 * 2463 * Check for Triggers if exists 2464 * Added On: 10/04/2021 2465 * Added By: Chirag Thummar 2466 * 2467 * */ 2468 2469 function checkForChatyTriggers() { 2470 if ($(".chaty.auto-hide-chaty").length) { 2471 chatyHideTimeInterval = setInterval(function () { 2472 chatyHideIntervalTime++; 2473 var currentTime = chatyHideIntervalTime; 2474 if ($(".chaty.auto-hide-chaty.hide-after-" + chatyHideIntervalTime).length) { 2475 var widgetId = $(".chaty.auto-hide-chaty.hide-after-" + currentTime).data("id"); 2476 $(".chaty-form-" + widgetId).removeClass("active"); 2477 $(".chaty.auto-hide-chaty.hide-after-" + currentTime).removeClass("active"); 2478 $("#chaty-widget-" + widgetId).removeClass("auto-hide-chaty"); 2479 $("body").removeClass("add-bg-blur-effect"); 2480 } 2481 if ($(".chaty.auto-hide-chaty").length == 0) { 2482 clearInterval(chatyHideTimeInterval); 2483 } 2484 }, 1000); 2485 } 2486 if (chatyHasTimeDelay) { 2487 chatyTimeInterval = setInterval(function () { 2488 chatyIntervalTime++; 2489 if ($(".chaty.delay-time-" + chatyIntervalTime).length) { 2490 //$(".chaty.delay-time-"+chatyIntervalTime).addClass("active"); 2491 var widgetId = $(".chaty.delay-time-" + chatyIntervalTime).data("id"); 2492 removeTriggerRules(widgetId); 2493 } 2494 }, 1000); 2495 } 2496 2497 if (chatyHasPageScroll) { 2498 $(window).on("scroll", function () { 2499 if (chatyHasPageScroll) { 2500 var scrollHeight = $(document).height() - $(window).height(); 2501 var scrollPos = $(window).scrollTop(); 2502 if (scrollHeight != 0) { 2503 var scrollPer = parseInt((scrollPos / scrollHeight) * 100); 2504 if (lastScrollPer <= scrollPer) { 2505 var startFrom = lastScrollPer; 2506 lastScrollPer = scrollPer; 2507 for (var i = startFrom; i <= scrollPer; i++) { 2508 if ($.inArray(i, chatyPageScrolls) == -1) { 2509 if ($(".chaty.on-chaty-scroll.page-scroll-" + i).length) { 2510 $(".chaty.on-chaty-scroll.page-scroll-" + i).each(function () { 2511 //$(this).addClass("active"); 2512 var widgetId = $(this).data("id"); 2513 $(this).removeClass("on-chaty-scroll"); 2514 removeTriggerRules(widgetId); 2515 }); 2516 } 2517 } 2518 } 2519 lastScrollPer = scrollPer; 2520 } 2521 } 2522 } 2523 }); 2524 var hasScrollbar = window.innerWidth > document.documentElement.clientWidth; 2525 if (!hasScrollbar) { 2526 /*$(".chaty.on-chaty-scroll:not(.on-chaty-delay):not(.on-chaty-exit-intent)").each(function(){ 2527 $(this).addClass("active"); 2528 var widgetId = $(this).data("id"); 2529 removeTriggerRules(widgetId); 2530 });*/ 2531 } 2532 } 2533 2534 //if(chatyHasExitIntent) { 2535 2536 //} 2537 } 2538 2539 2540 2541 function close_chaty() { 2542 if (jQuery(".chaty.active .chaty-open").length) { 2543 jQuery(".chaty.active .chaty-open").each(function () { 2544 jQuery(this).find(".chaty-cta-close").trigger("click"); 2545 }) 2546 } 2547 } 2548 2549 /** 2550 * 2551 * To load google Captcha V2 & V3 2552 * Added On: 10/02/2023 2553 * Added By: Chirag Thummar 2554 * 2555 * */ 2556 function LoadChatyGoogleRecaptcha() { 2557 if(jQuery(".v2_site_key").length && jQuery(".v2_site_key").val() != "") { 2558 var dsq = document.createElement('script'); 2559 dsq.type = 'text/javascript'; 2560 dsq.async = true; 2561 dsq.src = 'https://www.google.com/recaptcha/api.js?onload=onloadChatyCallback&render=explicit&hl=en'; 2562 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); 2563 } 2564 if(jQuery(".v3_site_key").length && jQuery(".v3_site_key").val() != "") { 2565 if (jQuery(".v3_site_key").length && jQuery(".v3_site_key").val() != "" && jQuery(".front-google-captcha").length) { 2566 jQuery(".front-google-captcha:not(.loaded)").each(function () { 2567 jQuery(this).addClass("loaded"); 2568 var siteKey = jQuery(".v3_site_key").val(); 2569 var dsq = document.createElement('script'); 2570 dsq.type = 'text/javascript'; 2571 dsq.async = true; 2572 dsq.src = 'https://www.google.com/recaptcha/api.js?onload=onloadCallbackChatyV3&render=' + siteKey; 2573 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); 2574 dsq.loadEventEnd = function() { 2575 2576 } 2577 }) 2578 } 2579 } 2580 } 2581 2582 /** 2583 *
2584 * Display widgets on Exit intent 2585 * Added On: 10/04/2021 2586 * Added By: Chirag Thummar 2587 * 2588 * */ 2589 2590 function mobileExitIntent() { 2591 if (window.history && window.history.pushState && chatyHasExitIntent) { 2592 function whenGoingBack() { 2593 if(chatyHasExitIntent) { 2594 var hashLocation = location.hash; 2595 var hashSplit = hashLocation.split("#!/"); 2596 var hashName = hashSplit[1]; 2597 if (hashName !== '') { 2598 var hash = window.location.hash; 2599 if (hash === '') { 2600 showWidgetsOnExitIntent(); 2601 } 2602 } 2603 } 2604 } 2605 2606 var pageState = 100; 2607 if (window.history.state && window.history.state.page) { 2608 pageState = window.history.state.page; 2609 } 2610 window.history.pushState({page: pageState + 1}, ''); 2611 window.history.pushState({page: pageState + 2}, ''); 2612 2613 window.onpopstate = function () { 2614 whenGoingBack(); 2615 }; 2616 window.history.onpopstate = function () { 2617 whenGoingBack(); 2618 }; 2619 window.addEventListener('popstate', function () { 2620 whenGoingBack(); 2621 }); 2622 document.addEventListener('backbutton', function () { 2623 whenGoingBack(); 2624 }); 2625 window.addEventListener('backbutton', function () { 2626 whenGoingBack(); 2627 }); 2628 $(window).on('popstate', function () { 2629 whenGoingBack(); 2630 }); 2631 } 2632 } 2633 2634 /** 2635 * 2636 * Display widgets on Exit intent 2637 * Added On: 10/04/2021 2638 * Added By: Chirag Thummar 2639 * 2640 * */ 2641 2642 function bindExitIntentFunction() { 2643 if (isChatyInMobile) { 2644 // Back button was pressed. 2645 mobileExitIntent(); 2646 } else { 2647 $(document).mouseleave(function (e) { 2648 function addEvent(obj, evt, fn) { 2649 if (obj.addEventListener) { 2650 obj.addEventListener(evt, fn, false);
2651 showWidgetsOnExitIntent(); 2652 } else if (obj.attachEvent) { 2653 obj.attachEvent("on" + evt, fn); 2654 } 2655 } 2656 2657 addEvent(document, 'mouseout', function (evt) { 2658 if (evt.toElement == null && evt.relatedTarget == null) { 2659 showWidgetsOnExitIntent(); 2660 } 2661 }); 2662 }); 2663 } 2664 } 2665 2666 /** 2667 * 2668 * Display widgets on Exit intent 2669 * Added On: 10/04/2021 2670 * Added By: Chirag Thummar 2671 * 2672 * */ 2673 2674 function showWidgetsOnExitIntent() { 2675 if (chatyHasExitIntent && $(".on-chaty-exit-intent").length) { 2676 $(".on-chaty-exit-intent").each(function () { 2677 //$(this).addClass("active"); 2678 var widgetId = $(this).data("id"); 2679 $(this).removeClass("on-chaty-exit-intent"); 2680 removeTriggerRules(widgetId); 2681 $("#chaty-widget-" + widgetId + " .chaty-widget").append("<div class='chaty-exit-intent'></div>"); 2682 setTimeout(function () { 2683 $(".chaty-exit-intent").addClass("animate"); 2684 setTimeout(function () { 2685 $(".chaty-exit-intent").removeClass("animate"); 2686 }, 2500); 2687 }, 500); 2688 }); 2689 } 2690 } 2691 2692 /** 2693 * 2694 * Remove Trigger Rules if all rules executed 2695 * Added On: 10/04/2021 2696 * Added By: Chirag Thummar 2697 * 2698 * */ 2699 function removeTriggerRules(widgetId) { 2700 2701 updateWidgetViews(widgetId); 2702 2703 $(".chaty-widget-" + widgetId).removeClass("on-chaty-delay"); 2704 $(".chaty-widget-" + widgetId).removeClass("on-chaty-exit-intent"); 2705 $(".chaty-widget-" + widgetId).removeClass("on-chaty-scroll"); 2706 2707 if (!$(".chaty.on-chaty-delay").length) { 2708 clearInterval(chatyTimeInterval); 2709 chatyHasTimeDelay = false; 2710 } 2711 if (!$(".chaty.on-chaty-exit-intent").length) { 2712 chatyHasExitIntent = false; 2713 } 2714 if (!$(".chaty.on-chaty-scroll").length) { 2715 chatyHasPageScroll = false; 2716 } 2717 } 2718 2719 /** 2720 * 2721 * Remove Empty On hover class when text is empty 2722 * Added On: 10/04/2021 2723 * Added By: Chirag Thummar 2724 * 2725 * */ 2726 function removeEmptyTooltip() { 2727 $(".chaty-tooltip").each(function () { 2728 if ($(this).data("hover") == "") { 2729 $(this).removeClass("left").removeClass("right").removeClass("top").removeClass("chaty-tooltip"); 2730 } 2731 }) 2732 } 2733 2734 /** 2735 * 2736 * Set widget icon 2737 * Added On: 10/04/2021 2738 * Added By: Chirag Thummar 2739 * 2740 * */ 2741 function getWidgetIcon(widgetRecord, widgetId) { 2742 /* set default icon if icon is blank */ 2743 if (widgetRecord.widget_icon == "") { 2744 widgetRecord.widget_icon = "chat-base"; 2745 } else if (widgetRecord.widget_icon == "chat-image" && isEmpty(widgetRecord.widget_icon_url)) { 2746 /* if custom icon is selected than check for image URL, if not exists then update icon with default icon */ 2747 widgetRecord.widget_icon = "chat-base"; 2748 } else if (widgetRecord.widget_icon == "chat-fa-icon" && isEmpty(widgetRecord.widget_fa_icon)) { 2749 widgetRecord.widget_icon = "chat-base"; 2750 } 2751 2752 if (widgetRecord.widget_icon == "chat-image") { 2753 return "<span class='chaty-svg' style='background-color: " + widgetRecord.widget_color + "'><img src='" + widgetRecord.widget_icon_url + "' alt='Chaty Widget' /></span>"; 2754 } else if(widgetRecord.widget_icon == "chat-fa-icon") { 2755 return "<span class='chaty-svg' style='background-color: " + widgetRecord.widget_color + "'><i class='" + widgetRecord.widget_fa_icon + " widget-fa-icon' style='color: "+ widgetRecord.widget_icon_color +"'></i></span>"; 2756 } else { 2757 return '<span class="chaty-svg">' + getSvgIcon(widgetRecord.widget_icon, widgetRecord.widget_color, widgetRecord.widget_icon_color, widgetId) + "</span>"; 2758 } 2759 } 2760 2761 /** 2762 * 2763 * check for widget animations if applicable 2764 * Added On: 10/04/2021 2765 * Added By: Chirag Thummar 2766 * 2767 * */ 2768 function checkForWidgetAnimation(widgetRecord, widgetId) { 2769 var clickStatus = checkChatyCookieExpired(widgetId, 'c-widget'); 2770 if (clickStatus && widgetRecord.attention_effect != "none" && widgetRecord.attention_effect != "") { 2771 $("#chaty-widget-" + widgetId).attr("data-animation", widgetRecord.attention_effect); 2772 if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("has-single")) { 2773 $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-channel .chaty-svg").addClass("chaty-animation-" + widgetRecord.attention_effect); 2774 } else { 2775 $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-cta-main .chaty-cta-button").addClass("chaty-animation-" + widgetRecord.attention_effect); 2776 } 2777 } 2778 } 2779 2780 /** 2781 * 2782 * check for pending message if all criteria matches to display it 2783 * Added On: 10/04/2021 2784 * Added By: Chirag Thummar 2785 * 2786 * */ 2787 function checkForPendingMessage(widgetRecord, widgetId) { 2788 var clickStatus = checkChatyCookieExpired(widgetId, 'c-widget'); 2789 2790 if (clickStatus && isTrue(widgetRecord.is_pending_mesg_enabled) && parseInt(widgetRecord.pending_mesg_count) > 0) { 2791 if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("has-single")) { 2792 if (widgetRecord.attention_effect == "sheen" || widgetRecord.attention_effect == "spin" || widgetRecord.attention_effect == "pulse") { 2793 $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-channel").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>"); 2794 } else { 2795 $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-channel .chaty-svg").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>"); 2796 } 2797 } else { 2798 if (widgetRecord.attention_effect == "jump" || widgetRecord.attention_effect == "waggle" || widgetRecord.attention_effect == "blink" || widgetRecord.attention_effect == "pulse-icon" || widgetRecord.attention_effect == "floating") { 2799 $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-cta-main .chaty-cta-button").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>"); 2800 } else { 2801 $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-cta-main").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>"); 2802 } 2803 } 2804 } 2805 } 2806 2807 /** 2808 * 2809 * Add Prefix 0 to Number 2810 * Added On: 10/21/2021 2811 * Added By: Chirag Thummar 2812 * 2813 * */ 2814 2815 function addPrefixToNum(num) { 2816 num = num.toString(); 2817 while (num.length < 2) num = "0" + num; 2818 return num; 2819 } 2820 2821 /** 2822 * 2823 * Check for time Schedule 2824 * Added On: 10/21/2021 2825 * Added By: Chirag Thummar 2826 * 2827 * */ 2828 function checkForDayAndTimeSchedule(widgetRecord) { 2829 var displayStatus = true; 2830 if (isTrue(widgetRecord.triggers.has_day_hours_scheduling_rules) && widgetRecord.triggers.day_hours_scheduling_rules.length > 0) { 2831 var displayRules = widgetRecord.triggers.day_hours_scheduling_rules;
2832 if (displayRules.length > 0) { 2833 displayStatus = false; 2834 var localDate = new Date(); 2835 localDate = changeTimezone(localDate, widgetRecord.triggers.day_time_diff); 2836 var utcHours = localDate.getHours(); 2837 var utcMin = localDate.getMinutes(); 2838 var utcDay = localDate.getDay(); 2839 for (var rule = 0; rule < displayRules.length; rule++) { 2840 var hourStatus = 0; 2841 var minStatus = 0; 2842 var checkForTime = 0; 2843 if (displayRules[rule].days == -1) { 2844 checkForTime = 1; 2845 } else if (displayRules[rule].days >= 0 && displayRules[rule].days <= 6) { 2846 if (displayRules[rule].days == utcDay) { 2847 checkForTime = 1; 2848 } 2849 } else if (displayRules[rule].days == 7) { 2850 if (utcDay >= 0 && utcDay <= 4) { 2851 checkForTime = 1; 2852 } 2853 } else if (displayRules[rule].days == 8) { 2854 if (utcDay >= 1 && utcDay <= 5) { 2855 checkForTime = 1; 2856 } 2857 } else if (displayRules[rule].days == 9) { 2858 if (utcDay == 6 || utcDay == 0) { 2859 checkForTime = 1; 2860 } 2861 } 2862 if (checkForTime == 1) { 2863 if (utcHours > displayRules[rule].start_hours && utcHours < displayRules[rule].end_hours) { 2864 hourStatus = 1; 2865 } else if (utcHours == displayRules[rule].start_hours && utcHours < displayRules[rule].end_hours) { 2866 if (utcMin >= displayRules[rule].start_min) { 2867 hourStatus = 1; 2868 } 2869 } else if (utcHours > displayRules[rule].start_hours && utcHours == displayRules[rule].end_hours) { 2870 if (utcMin <= displayRules[rule].end_min) { 2871 hourStatus = 1; 2872 } 2873 } else if (utcHours == displayRules[rule].start_hours && utcHours == displayRules[rule].end_hours) { 2874 if (utcMin >= displayRules[rule].start_min && utcMin <= displayRules[rule].end_min) { 2875 hourStatus = 1; 2876 } 2877 } 2878 if (hourStatus == 1) { 2879 if (utcMin >= displayRules[rule].start_min && utcMin <= displayRules[rule].end_min) { 2880 minStatus = 1; 2881 } 2882 } 2883 } 2884 2885 if (hourStatus == 1 && checkForTime == 1) { 2886 displayStatus = 1; 2887 } 2888 if (displayStatus == 1) { 2889 rule = displayRules.length + 1; 2890 } 2891 } 2892 } 2893 } 2894 return displayStatus; 2895 } 2896 2897 /** 2898 * 2899 * get tooltip position for channel 2900 * Added On: 09/29/2021 2901 * Added By: Chirag Thummar 2902 * 2903 * */ 2904 function isTrue(varVal) { 2905 if (varVal == "1" || varVal == 1 || varVal == true || varVal == "true" || varVal == "yes" || varVal == "on") { 2906 return true 2907 } 2908 return false; 2909 } 2910 2911 /** 2912 * 2913 * To get time diffrence between dates 2914 * Added On: 04/18/2022 2915 * Added By: Chirag Thummar 2916 * 2917 * */ 2918 2919 function changeTimezone(date, ianatz) { 2920 if (isNaN(ianatz)) { 2921 var invdate = new Date(date.toLocaleString('en-US', { 2922 timeZone: ianatz 2923 })); 2924 var diff = date.getTime() - invdate.getTime(); 2925 return new Date(date.getTime() - diff); // needs to substract 2926 } else { 2927 var newDate = new Date();
2928 newDate = newDate.toLocaleString('en-US', {timeZone: 'UTC'}); 2929 newDate = new Date(newDate); 2930 if (ianatz.indexOf("+") != -1) { 2931 var newTimeZone = ianatz.replace("+", ""); 2932 var extraHours = parseInt(newTimeZone); 2933 var extraMin = parseFloat(newTimeZone % extraHours) * 60; 2934 extraMin = newDate.getUTCMinutes() + extraMin; 2935 if (extraMin > 59) { 2936 extraHours = extraHours + parseInt(extraMin / 60); 2937 extraMin = extraMin % 60; 2938 } 2939 newDate.setUTCHours(newDate.getUTCHours() + extraHours, extraMin); 2940 } else if (ianatz.indexOf("-") != -1) { 2941 var newTimeZone = ianatz.replace("-", ""); 2942 var extraHours = parseInt(newTimeZone); 2943 var extraMin = parseFloat(newTimeZone % extraHours) * 60; 2944 extraMin = newDate.getUTCMinutes() - extraMin; 2945 if (extraMin < 0) { 2946 extraHours = extraHours - parseInt(extraMin / 60); 2947 extraMin = extraMin % 60; 2948 } 2949 newDate.setUTCHours(newDate.getUTCHours() - extraHours, -extraMin); 2950 } 2951 var diff = date.getTime() - newDate.getTime(); 2952 return new Date(date.getTime() - diff); // needs to substract 2953 } 2954 } 2955 2956 /** 2957 * 2958 * Check for time Schedule 2959 * Added On: 10/21/2021 2960 * Added By: Chirag Thummar 2961 * 2962 * */ 2963 2964 function checkForTimeSchedule(widgetRecord) { 2965 if (widgetRecord.triggers.has_date_scheduling_rules) { 2966 var chtStartDate = widgetRecord.triggers.date_scheduling_rules.start_date_time; 2967 var chtEndDate = widgetRecord.triggers.date_scheduling_rules.end_date_time; 2968 2969 var localDate = new Date(); 2970 2971 localDate = changeTimezone(localDate, widgetRecord.triggers.time_diff); 2972 2973 var currentTime = localDate.getFullYear() + "-" + (addPrefixToNum(localDate.getMonth() + 1)) + "-" + addPrefixToNum(localDate.getDate()) + " " + addPrefixToNum(localDate.getHours()) + ":" + addPrefixToNum(localDate.getMinutes()) + ":" + addPrefixToNum(localDate.getSeconds()); 2974 2975 if (chtEndDate == "") { 2976 if (chtStartDate <= currentTime) { 2977 return true; 2978 } 2979 } 2980 2981 if (chtStartDate == "") { 2982 if (chtEndDate >= currentTime) { 2983 return true; 2984 } 2985 } 2986 2987 if (chtStartDate != "" && chtEndDate != "") { 2988 if (chtStartDate <= currentTime && chtEndDate >= currentTime) { 2989 return true; 2990 } 2991 } 2992 return false; 2993 } 2994 return true; 2995 } 2996 2997 /** 2998 * 2999 * Check for visitos's country 3000 * Added On: 10/21/2021 3001 * Added By: Chirag Thummar 3002 * 3003 * */ 3004 function checkForUserCountry(widgetRecord) { 3005 if (isTrue(widgetRecord.triggers.has_countries) && !isEmpty(widgetRecord.triggers.countries) && widgetRecord.triggers.countries.length) { 3006 clientCountry = getUserCountry(); 3007 if (clientCountry != "-") { 3008 if ($.inArray(clientCountry, widgetRecord.triggers.countries) == -1) { 3009 return false; 3010 } 3011 } 3012 } 3013 return true; 3014 } 3015 3016 /** 3017 * 3018 * To get user id from cookie or storage 3019 * Added On: 09/28/2021 3020 * Added By: Chirag Thummar 3021 * 3022 * */ 3023 function getUserCountry() { 3024 clientCountry = ""; 3025 if (typeof Storage !== "undefined" && window.sessionStorage.getItem("chaty_user_country_code") != null) { 3026 clientCountry = window.sessionStorage.getItem("chaty_user_country_code"); 3027 } else { 3028 if (chatyCheckCookie('chaty_user_country_code')) { 3029 clientCountry = chatyGetCookie('chaty_user_country_code'); 3030 } 3031 } 3032 return clientCountry; 3033 } 3034 3035 /** 3036 * 3037 * To save user id in cookie, will be created different for users and by browsers 3038 * Added On: 09/28/2021 3039 * Added By: Chirag Thummar 3040 * 3041 * */ 3042 function setUserCountry(userCountry) { 3043 if (typeof Storage !== "undefined") { 3044 if (window.sessionStorage.getItem("chaty_user_country_code") == null) { 3045 window.sessionStorage.setItem("chaty_user_country_code", userCountry); 3046 } 3047 } else { 3048 if (!chatyCheckCookie('chaty_user_country_code')) { 3049 chatySetCookie('chaty_user_country_code', userCountry, 365); 3050 } 3051 } 3052 } 3053 3054 /** 3055 * 3056 * To ger widget's setting stored cookie Array 3057 * Added On: 10/01/2021 3058 * Added By: Chirag Thummar 3059 * 3060 * */ 3061 function checkForChatyCookieString(widgetId, cookieStr) { 3062 var cookieString = chatyGetCookie("chatyWidget_" + widgetId); 3063 var cookieArray = []; 3064 if (cookieString != null && cookieString != "") { 3065 cookieArray = JSON.parse(cookieString); 3066 } 3067 if (cookieArray.length > 0) { 3068 for (var i = 0; i < cookieArray.length; i++) { 3069 if (cookieArray[i]['k'] == cookieStr) { 3070 return cookieArray[i]['v']; 3071 } 3072 } 3073 } 3074 return null; 3075 } 3076 3077 /** 3078 * 3079 * To save widget's setting in cookie Array 3080 * Added On: 10/01/2021 3081 * Added By: Chirag Thummar 3082 * 3083 * */ 3084 function saveChatyCookieString(widgetId, cookieStr) { 3085 var cookieString = chatyGetCookie("chatyWidget_" + widgetId); 3086 var cookieArray = []; 3087 if (cookieString != null && cookieString != "") { 3088 cookieArray = JSON.parse(cookieString); 3089 } 3090 var cookieFound = false; 3091 if (cookieArray.length > 0) { 3092 for (var i = 0; i < cookieArray.length; i++) { 3093 if (cookieArray[i]['k'] == cookieStr) { 3094 cookieFound = true; 3095 cookieArray[i]['v'] = new Date(); 3096 } 3097 } 3098 } 3099 if (!cookieFound) { 3100 cookieArray.push({"k": cookieStr, "v": new Date()}); 3101 } 3102 cookieString = JSON.stringify(cookieArray); 3103 chatySetCookie("chatyWidget_" + widgetId, cookieString, "7"); 3104 } 3105 3106 3107 function hideDefaultOpenWidgets() { 3108 if($(".chaty-widget.default-open.has-bg-blur-effect").length) { 3109 $(".chaty-widget.default-open.has-bg-blur-effect").each(function(){ 3110 var chatyWidgetId = $(this).closest(".chaty").data("id"); 3111 saveChatyCookieString(chatyWidgetId, "c-widget"); 3112 }); 3113 } 3114 } 3115 3116 3117 /** 3118 * 3119 * To check widget's setting cookie status stored in Array 3120 * Added On: 10/01/2021 3121 * Added By: Chirag Thummar 3122 * 3123 * */ 3124 function checkChatyCookieExpired(widgetId, cookieStr) { 3125 var cookieValue = checkForChatyCookieString(widgetId, cookieStr); 3126 if (cookieValue != null && cookieValue != "") { 3127 cookieValue = new Date(cookieValue); 3128 var diffTime = Math.abs(new Date() - cookieValue); 3129 var diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); 3130 if (diffDays >= 2) { 3131 return true; 3132 } else { 3133 return false; 3134 } 3135 } 3136 return true; 3137 } 3138 3139 /** 3140 * 3141 * To save data in browser cookie 3142 * Added On: 09/28/2021 3143 * Added By: Chirag Thummar 3144 * 3145 * */ 3146 function chatySetCookie(cname, cvalue, exdays) { 3147 var d = new Date(); 3148 d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); 3149 var expires = "expires=" + d.toUTCString(); 3150 document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/; SameSite=Lax"; 3151 } 3152 3153 /** 3154 * 3155 * To get data from browser cookie using cookie name 3156 * Added On: 09/28/2021 3157 * Added By: Chirag Thummar 3158 * 3159 * */ 3160 function chatyGetCookie(cookieName) { 3161 var cookieName = cookieName + "="; 3162 var ca = document.cookie.split(';'); 3163 for (var i = 0; i < ca.length; i++) { 3164 var c = ca[i];
3165 while (c.charAt(0) == ' ') { 3166 c = c.substring(1); 3167 } 3168 if (c.indexOf(cookieName) == 0) { 3169 return c.substring(cookieName.length, c.length); // return data if cookie exists 3170 } 3171 } 3172 return null; // return null if cookie doesn't exists 3173 } 3174 3175 /** 3176 * 3177 * To check cookie exists or not in browser 3178 * Added On: 09/28/2021 3179 * Added By: Chirag Thummar 3180 * 3181 * */ 3182 function chatyCheckCookie(cookieName) { 3183 var cookie = chatyGetCookie(cookieName); 3184 if (cookie != "" && cookie !== null) { 3185 return true; 3186 } else { 3187 return false; 3188 } 3189 } 3190 3191 /** 3192 * 3193 * To remove cookie from browser 3194 * Added On: 09/28/2021 3195 * Added By: Chirag Thummar 3196 * 3197 * */ 3198 function chatyDeleteCookie(cookieName) { 3199 document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; 3200 } 3201 3202 /** 3203 * 3204 * To get current date from Browser 3205 * Added On: 09/28/2021 3206 * Added By: Chirag Thummar 3207 * 3208 * */ 3209 function getCurrentDate() { 3210 today = new Date(); 3211 dd = today.getDate(); 3212 mm = today.getMonth() + 1; 3213 yyyy = today.getFullYear(); 3214 if (dd < 10) { 3215 dd = '0' + dd; 3216 } 3217 if (mm < 10) { 3218 mm = '0' + mm; 3219 } 3220 return yyyy + '-' + mm + '-' + dd; 3221 } 3222 3223 /** 3224 * 3225 * Add log message to console 3226 * 3227 * */ 3228 function addChatyLog(message) { 3229 if (chatyEnv != "app") { 3230 console.log(message); 3231 } 3232 } 3233})); 3234 3235function launch_chaty(widget_number) { 3236 if (widget_number == undefined || widget_number == "widget_index") { 3237 widget_number = 0; 3238 } 3239 if (jQuery("#chaty-widget-"+widget_number).length) { 3240 jQuery("#chaty-widget-"+widget_number+" .chaty-cta-button .open-chaty").trigger("click"); 3241 } 3242 if (jQuery("#chaty-widget-_"+widget_number).length) { 3243 jQuery("#chaty-widget-_"+widget_number+" .chaty-cta-button .open-chaty").trigger("click"); 3244 } 3245} 3246 3247var googleV3Token = ""; 3248function onloadCallbackChatyV3() { 3249 var siteKey = jQuery(".v3_site_key").val(); 3250 if(siteKey && googleV3Token == "") { 3251 grecaptcha.ready(function () { 3252 grecaptcha.execute(siteKey, {action: 'contact_form'}).then(function (token) { 3253 googleV3Token = token; 3254 }); 3255 }); 3256 } 3257} 3258 3259function refreshG3Token() { 3260 if (typeof grecaptcha === "function" || typeof grecaptcha === "object") { 3261 var siteKey = jQuery(".v3_site_key").val(); 3262 if (siteKey && googleV3Token == "") { 3263 grecaptcha.ready(function () { 3264 grecaptcha.execute(siteKey, {action: 'contact_form'}).then(function (token) { 3265 googleV3Token = token; 3266 }); 3267 }); 3268 } 3269 } 3270} 3271 3272function onloadChatyCallback() { 3273 if (jQuery(".v2_site_key").length && jQuery(".v2_site_key").val() != "" && jQuery(".front-google-captcha").length) { 3274 jQuery(".front-google-captcha:not(.loaded)").each(function () { 3275 var thisId = jQuery(this).attr("id"); 3276 jQuery(this).addClass("loaded"); 3277 if (document.getElementById(thisId)) { 3278 grecaptcha.render(thisId, {'sitekey': jQuery(".v2_site_key").val()}); 3279 } 3280 }) 3281 } 3282 3283}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.