PageSourceSearch

https://kaufen-steroide.com/wp-content/plugins/chaty/js/cht-front-script.min.js

js kaufen-steroide.com collected 2026-10-04 12:30:09 UTC 141,622 bytes, 2,650 lines download raw bytes

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    $(document).ready(function () {
36        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)";
37        var re = new RegExp(botPattern, 'i');
38        var userAgent = navigator.userAgent;
39        if (re.test(userAgent)) {
40            isBoatUser = true;
41        }
42
43        if(isChatyInMobile) {
44            $("body").addClass("cht-in-mobile");
45        } else {
46            $("body").addClass("cht-in-desktop");
47        }
48
49        if (chaty_settings.data_analytics_settings != "on" || chaty_settings.data_analytics_settings == "off") {
50            isBoatUser = true;
51        }
52
53        if (typeof chaty_settings == "undefined" || chaty_settings.chaty_widgets.length == 0) {
54            console.log("Chaty settings doesn't exists");
55        } else {
56            widgetData = chaty_settings.chaty_widgets;
57            checkForCountry();
58        }
59
60        if($(window).height() > $(window).width()) {
61            $("body").addClass("cht-portrait").removeClass("cht-landscape");
62        } else {
63            $("body").addClass("cht-landscape").removeClass("cht-portrait");
64        }
65
66        $(document).on("click", "html, body", function (e) {
67            $(".form-open").removeClass("form-open");
68            $(".chaty-outer-forms").removeClass("active");
69            $(".chaty .chaty-widget.chaty-no-close-button").addClass("chaty-open");
70        });
71
72        $(document).on("click", ".chaty, .chaty-outer-forms", function (e) {
73            e.stopPropagation();
74        });
75
76        $(document).on("click", ".chaty-close-view-list", function(){
77            $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
78        });
79
80        $(document).on("submit", ".whatsapp-chaty-form", function () {
81
82            if ($(this).hasClass("form-google-analytics")) {
83                var widgetChannel = "Whatsapp";
84                if (window.hasOwnProperty("gtag")) {
85                    gtag("event", "chaty_" + widgetChannel, {
86                        eventCategory: "chaty_" + widgetChannel,
87                        event_action: "chaty_" + widgetChannel,
88                        method: "chaty_" + widgetChannel
89                    });
90                }
91                if (window.hasOwnProperty("ga")) {
92                    var ga_settings = window.ga.getAll()[0];
93                    ga_settings && ga_settings.send("event", "click", {
94                        eventCategory: "chaty_" + widgetChannel,
95                        eventAction: "chaty_" + widgetChannel,
96                        method: "chaty_" + widgetChannel
97                    })
98                }
99            }
100            var widgetId = $(this).data('widget');
101            var chatyChannel = $(this).data('channel');
102
103
104            var clickStatus = checkChatyCookieExpired(widgetId, "c-" + chatyChannel);
105
106            saveChatyCookieString(widgetId, "c-" + chatyChannel);
107            if ((!isEmpty(widgetId) || widgetId == 0) && clickStatus) {
108                saveChatyCookieString(widgetId, "c-" + chatyChannel);
109            }
110
111            if ($("#chaty-widget-" + widgetId).length) {
112                $("#chaty-widget-" + widgetId).removeClass("form-open");
113                $(this).closest(".chaty-outer-forms").removeClass("active");
114                if ($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("cssas-no-close-button")) {
115                    $("#chaty-widget-" + widgetId).find(".chaty-widget").addClass("chaty-open")
116                }
117            }
118        });
119
120        $(document).on("click", ".chaty-close-button, .chaty-close-agent-list", function (e) {
121            e.preventDefault();
122            e.stopPropagation();
123            var widgetId = $(this).closest(".chaty-outer-forms").data('widget');
124            if (!isEmpty(widgetId) || widgetId == 0) {
125                if ($("#chaty-widget-" + widgetId).length) {
126                    $("#chaty-widget-" + widgetId).removeClass("form-open");
127                    $(this).closest(".chaty-outer-forms").removeClass("active");
128                    if ($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("chaty-no-close-button")) {
129                        $("#chaty-widget-" + widgetId).find(".chaty-widget").addClass("chaty-open");
130                    }
131                }
132                if ($(this).closest(".chaty-whatsapp-form").length) {
133                    var dataChannel = $(this).closest(".chaty-outer-forms").data('channel');
134                    if (!isEmpty(dataChannel)) {
135                        var clickStatus = checkChatyCookieExpired(widgetId, "c-" + dataChannel);
136                        if (clickStatus) {
137                            saveChatyCookieString(widgetId, "c-" + dataChannel);
138                        }
139                    }
140                    var visibleStatus = checkChatyCookieExpired(widgetId, 'v-widget');
141                    if (visibleStatus) {
142                        updateWidgetViews(widgetId);
143                    }
144                }
145            }
146        });
147
148        $(document).on("click", "a.chaty-qr-code-form", function (e) {
149            e.preventDefault();
150            // e.stopPropagation();
151            var dataForm = $(this).data('form');
152            if (!isEmpty(dataForm)) {
153                if ($("#" + dataForm).length) {
154                    var buttonHtml = $(this).html();
155
156                    if($("#" + dataForm).hasClass("active")) {
157                        $(this).closest(".chaty").find(".chaty-widget").addClass("chaty-open");
158                        $(this).closest(".chaty").removeClass("form-open");
159                        $("#" + dataForm).removeClass("active");
160                    } else {
161                        $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
162                        $(this).closest(".chaty").addClass("form-open");
163                        $("#" + dataForm).addClass("active");
164
165                        $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
166                    }
167                }
168            }
169        });
170
171        $(document).on("click", "a.chaty-contact-us-form", function (e) {
172            e.preventDefault();
173            // e.stopPropagation();
174            var dataForm = $(this).data('form');
175            if (!isEmpty(dataForm)) {
176                if ($("#" + dataForm).length) {
177
178                    if(googleV3Token != "") {
179                        googleV3Token = "";
180                        refreshG3Token();
181                    }
182
183                    var buttonHtml = $(this).html();
184
185                    if($("#" + dataForm).hasClass("active")) {
186                        $(this).closest(".chaty").find(".chaty-widget").addClass("chaty-open");
187                        $(this).closest(".chaty").removeClass("form-open");
188                        $("#" + dataForm).removeClass("active");
189
190                    } else {
191                        $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
192                        $(this).closest(".chaty").addClass("form-open");
193                        $("#" + dataForm).addClass("active");
194                        $("#" + dataForm).find(".chaty-ajax-success-message").remove();
195                        $("#" + dataForm).find(".chaty-ajax-error-message").remove();
196                        $("#" + dataForm).find(".has-chaty-error").removeClass("has-chaty-error");
197
198                        $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
199                    }
200                }
201            }
202        });
203
204        $(document).on("click", "a.chaty-whatsapp-form", function (e) {
205            e.preventDefault();
206            // e.stopPropagation();
207            var dataForm = $(this).data('form');
208            if (!isEmpty(dataForm)) {
209                if ($("#" + dataForm).length) {
210                    var buttonHtml = $(this).html();
211                    $("#" + dataForm).addClass("is-active");
212                    if($("#" + dataForm).hasClass("active")) {
213                        $(this).closest(".chaty").find(".chaty-widget").addClass("chaty-open");
214                        $(this).closest(".chaty").removeClass("form-open");
215                        $("#" + dataForm).removeClass("active");
216                    } else {
217                        $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
218                        $(this).closest(".chaty").addClass("form-open");
219                        $("#" + dataForm).addClass("active");
220
221                        $(this).closest(".chaty").find(".chaty-widget").find(".open-chaty-channel").html(buttonHtml);
222                    }
223                }
224            }
225        });
226
227        $(document).on("click", ".chaty-channel.chaty-agent-button", function (e) {
228            e.preventDefault();
229            // e.stopPropagation();
230            var dataForm = $(this).data('form');
231            if (!isEmpty(dataForm)) {
232                if ($("#" + dataForm).length) {
233                    if (!$(this).closest(".chaty").find(".chaty-widget").hasClass("has-single")) {
234                        var buttonHtml = $(this).html();
235                        $("#" + dataForm).addClass("is-active");
236
237                        $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
238                        $(this).closest(".chaty").addClass("form-open");
239                        $("#" + dataForm).addClass("active");
240
241                        $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
242                    } else {
243                        if ($(this).closest(".chaty").hasClass("form-open")) {
244                            $(this).closest(".chaty").find(".chaty-widget").addClass("chaty-open");
245                            $(this).closest(".chaty").removeClass("form-open");
246                            $("#" + dataForm).removeClass("active");
247                        } else {
248                            var buttonHtml = $(this).html();
249                            $("#" + dataForm).addClass("is-active");
250
251                            $(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
252                            $(this).closest(".chaty").addClass("form-open");
253                            $("#" + dataForm).addClass("active");
254
255                            $(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
256                        }
257                    }
258                }
259            }
260
261        });
262
263        /* track google analytics event */
264        $(document).on("click", ".chaty-channel a.has-gae", function (e) {
265            e.stopPropagation();
266            var widgetChannel = $(this).closest(".chaty-channel").data("channel");
267            if (widgetChannel !== undefined && widgetChannel != "" && widgetChannel != null) {
268                if (window.hasOwnProperty("gtag")) {
269                    gtag("event", "chaty_" + widgetChannel, {
270                        eventCategory: "chaty_" + widgetChannel,
271                        event_action: "chaty_" + widgetChannel,
272                        method: "chaty_" + widgetChannel
273                    });
274                }
275                if (window.hasOwnProperty("ga")) {
276                    var ga_settings = window.ga.getAll()[0];
277                    ga_settings && ga_settings.send("event", "click", {
278                        eventCategory: "chaty_" + widgetChannel,
279                        eventAction: "chaty_" + widgetChannel,
280                        method: "chaty_" + widgetChannel
281                    })
282                }
283            }
284        });
285
286        $(document).on("mouseover", ".chaty-widget.has-single .chaty-channel a.has-on-hover[data-hover]", function () {
287            $(this).find(".on-hover-text").html($(this).data("hover"));
288            $(this).attr("aria-label", $(this).data("hover"));
289        }).on("mouseleave", ".chaty-widget.has-single .chaty-channel a.has-on-hover[data-text]", function () {
290            $(this).find(".on-hover-text").html($(this).data("text"));
291            $(this).attr("aria-label", $(this).data("text"));
292        });
293
294        $(document).on("submit", ".whatsapp-chaty-form.has-form-gae", function(){
295            var widget_id = $(this).data("widget");
296            var widgetChannel = $("#Whatsapp-"+ widget_id +"-channel").data("channel");
297            if (widgetChannel !== undefined && widgetChannel != "" && widgetChannel != null) {
298                if (window.hasOwnProperty("gtag")) {
299                    gtag("event", "chaty_whatsapp_redirect", {
300                        eventCategory: "chaty_whatsapp_redirect",
301                        event_action: "chaty_whatsapp_redirect",
302                        method: "chaty_whatsapp_redirect"
303                    });
304                }
305                if (window.hasOwnProperty("ga")) {
306                    var ga_settings = window.ga.getAll()[0];
307                    ga_settings && ga_settings.send("event", "click", {
308                        eventCategory: "chaty_whatsapp_redirect",
309                        eventAction: "chaty_whatsapp_redirect",
310                        method: "chaty_whatsapp_redirect"
311                    })
312                }
313            }
314        });
315
316        /* toggle widget on CTA button click */
317        $(document).on("click", ".chaty-i-trigger:not(.single-channel)", function () {
318            if ($(this).closest(".chaty").hasClass("form-open")) {
319                $(this).closest(".chaty").removeClass("form-open");
320                $(this).closest(".chaty-widget").addClass("chaty-open");
321            } else {
322                $(this).closest(".chaty-widget").toggleClass("chaty-open");
323            }
324            $(".chaty-outer-forms.active").each(function(){
325                $(this).remo
325veClass("active");
326                var widgetID = $(this).data("widget");
327                $("#chaty-widget-"+widgetID).removeClass("form-open");
328            });
329            if ($(this).closest(".chaty").find(".chaty-widget").hasClass("chaty-no-close-button")) {
330                $(this).closest(".chaty").find(".chaty-widget").addClass("chaty-open");
331            }
332        });
333
334        /* Open widget on hover */
335        if (!isChatyInMobile) {
336            $(document).on("mouseover", "body:not(.chaty-in-mobile) .chaty.open-on-hover .chaty-i-trigger:not(.single-channel)", function () {
337                if (!$(this).closest(".chaty-widget").hasClass("chaty-open") && !$(this).closest(".chaty-widget").hasClass("on-chaty-widget")) {
338                    $(this).closest(".chaty-widget").addClass("on-chaty-widget");
339                    $(this).find(".chaty-cta-main").trigger("click");
340                }
341            }).on("mouseleave", "body:not(.chaty-in-mobile) .chaty.open-on-hover .chaty-i-trigger:not(.single-channel)", function () {
342                if (!$(this).closest(".chaty-widget").hasClass("chaty-open")) {
343                    $(this).closest(".chaty-widget").removeClass("on-chaty-widget")
344                }
345            });
346        }
347
348        /* Remove active class for CTA button */
349        $(document).on("click", ".chaty-channel.single a", function(){
350            if($(this).closest(".chaty").hasClass("first_click")) {
351                var chatyWidgetId = $(this).closest(".chaty").data("id");
352                saveChatyCookieString(chatyWidgetId, "c-widget");
353                $(this).closest(".chaty-channel").removeClass("active");
354            }
355        });
356
357        /* check for channel or widget click event */
358        $(document).on("click", ".chaty-channel", function (e) {
359            // return;
360            var clickStatus;
361            var chatyChannel;
362            var chatyChannels = [];
363            var isSingle = 0;
364            var chatyWidgetIdentifier;
365            var chatyWidgetId = $(this).closest(".chaty").data("id");
366            if (typeof chatyWidgetId != 'undefined') {
367                chatyWidgetIdentifier = $("#chaty-widget-" + chatyWidgetId).data("identifier");
368                if (typeof chatyWidgetIdentifier != 'undefined') {
369                    var userId = $("#chaty-widget-" + chatyWidgetId).data("user");
370                    removeChatyAnimation(chatyWidgetId);
371                    if ($(this).hasClass("chaty-cta-main") || $(this).hasClass("chaty-cta-close")) {
372                        clickStatus = checkChatyCookieExpired(chatyWidgetId, 'c-widget');
373                        $("#chaty-widget-" + chatyWidgetId).find(".ch-pending-msg").remove();
374                        if (clickStatus) {
375                            saveChatyCookieString(chatyWidgetId, "c-widget");
376                            if ($(this).hasClass("chaty-cta-main")) {
377                                chatyChannels = [];
378                                if($("#chaty-widget-" + chatyWidgetId).hasClass("chaty-has-chat-view")) {
379                                    $(".chaty-chat-view.chaty-chat-view-" + chatyWidgetId + " .chaty-view-channels").find(".chaty-channel").each(function () {
380                                        chatyChannel = $(this).data("channel");
381                                        clickStatus = checkChatyCookieExpired(chatyWidgetId, "v-" + chatyChannel);
382                                        if (clickStatus && typeof chatyChannel != 'undefined') {
383                                            saveChatyCookieString(chatyWidgetId, "v-" + chatyChannel);
384                                            chatyChannels.push(chatyChannel);
385                                        }
386                                    });
387                                } else {
388                                    $("#chaty-widget-" + chatyWidgetId + " .chaty-channel-list").find(".chaty-channel").each(function () {
389                                        chatyChannel = $(this).data("channel");
390                                        clickStatus = checkChatyCookieExpired(chatyWidgetId, "v-" + chatyChannel);
391                                        if (clickStatus && typeof chatyChannel != 'undefined') {
392                                            saveChatyCookieString(chatyWidgetId, "v-" + chatyChannel);
393                                            chatyChannels.push(chatyChannel);
394                                        }
395                                    });
396                                }
397                            }
398                        }
399                        if ($("#chaty-widget-" + chatyWidgetId).hasClass("first_click")) {
400                            $("#chaty-widget-" + chatyWidgetId + " .chaty-cta-main").removeClass("active");
401                            $("#chaty-widget-" + chatyWidgetId + " .chaty-cta-main").removeClass("chaty-tooltip");
402                        }
403                    } else if ($(this).hasClass("single")) {
404                        $("#chaty-widget-" + chatyWidgetId).find(".ch-pending-msg").remove();
405                        clickStatus = checkChatyCookieExpired(chatyWidgetId, 'c-widget');
406
407                        /* checking for CTA status */
408                        if ($("#chaty-widget-" + chatyWidgetId).hasClass("first_click")) {
409                            $("#chaty-widget-" + chatyWidgetId + " .chaty-tooltip").removeClass("chaty-tooltip");
410                            $("#chaty-widget-" + chatyWidgetId + " .single-channel a").addClass("chaty-tooltip");
411                        }
412                    } else if ($(this).hasClass("chaty-channel")) {
413                        chatyChannel = $(this).data("channel");
414                        clickStatus = checkChatyCookieExpired(chatyWidgetId, "c-" + chatyChannel);
415                        if (clickStatus) {
416                            saveChatyCookieString(chatyWidgetId, "c-" + chatyChannel);
417                        }
418                    }
419                }
420            }
421        });
422
423        $(document).on("submit", ".chaty-ajax-contact-form", function (e) {
424            e.preventDefault();
425            var inputErrorCounter = 0;
426            $(this).find(".has-chaty-error").each(function () {
427                $(this).removeClass("has-chaty-error");
428            });
429            $(this).find(".chaty-error-msg").remove();
430            $(this).find(".chaty-ajax-error-message").remove();
431            $(this).find(".chaty-ajax-success-message").remove();
432            $(this).find(".is-required").each(function () {
433                if (jQuery.trim($(this).val()) == "") {
434                    inputErrorCounter++;
435                    $(this).addClass("has-chaty-error");
436                }
437            });
438            if (inputErrorCounter == 0) {
439                var $form = $(this);
440                $(".chaty-submit-button").attr("disabled", true);
441                $("#chaty-submit-button-"+ $form.data("index") + " .chaty-loader").addClass("active");
442                jQuery.ajax({
443                    url: chaty_settings.ajax_url,
444                    data: {
445                        action: "chaty_front_form_save_data",
446                        name: $form.find(".field-name").length ? $form.find(".field-name").val() : "",
447                        email: $form.find(".field-email").length ? $form.find(".field-email").val() : "",
448                        phone: $form.find(".field-phone").length ? $form.find(".field-phone").val() : "",
449                        message: $form.find(".field-message").length ? $form.find(".field-message").val() : "",
450                        nonce: $form.data("token"),
451                        channel: $form.data("channel"),
452                        widget: $form.data("index"),
453                        ref_url: window.location.href,
454                        token: googleV3Token,
455                        page_id: chaty_settings.page_id,
456                        page_title: getPageTitle(),
457                        v2token: $form.find(".g-recaptcha-response").length ? $form.find(".g-recaptcha-response").val() : ""
458                    },
459                    type: 'post',
460                    async: true,
461                    defer: true,
462                    dataType: 'json',
463                    success: function (response) {
464                        if(googleV3Token != "") {
465                            googleV3Token = "";
466                            refreshG3Token();
467                        }
468                        $(".chaty-ajax-error-message").remove();
469                        $(".chaty-ajax-success-message").remove();
470                        $(".chaty-submit-button").attr("disabled", false);
471                        if (response.status == 1) {
472                            $("#chaty-submit-button-"+ $form.data("index") + " .chaty-loader").removeClass("active");
473                            $(".chaty-contact-inputs").append("<div class='chaty-ajax-success-message'>" + response.message + "</div>");
474                            $(".field-name, .field-email, .field-message, .field-phone").val("");
475                            if (response.redirect_action == "yes") {
476                                if (response.link_in_new_tab == "yes") {
477                                    window.open(response.redirect_link, '_blank');
478                                } else {
479                                    window.location = response.redirect_link;
480                                }
481                            }
482                            if (response.close_form_after == "yes") {
483                                setTimeout(function () {
484                                    if ($(".chaty-outer-forms.active").length) {
485                                        var widgetId = $(".chaty-outer-forms.active").data('widget');
486                                        if (!isEmpty(widgetId) || widgetId == 0) {
487                                            if ($("#chaty-widget-" + widgetId).length) {
488                                                $("#chaty-widget-" + widgetId).removeClass("form-open");
489                                                $(".chaty-outer-forms.active").removeClass("active");
490                                                if ($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("chaty-no-close-button")) {
491                                                    $("#chaty-widget-" + widgetId).find(".chaty-widget").addClass("chaty-open")
492                                                }
493                                            }
494                                        }
495                                    }
496                                }, parseInt(response.close_form_after_seconds) * 1000);
497                            }
498                        } else if (response.error == 1) {
499                            if (response.errors.length) {
500                                for (var i = 0; i < response.errors.length; i++) {
501                                    $("." + response.errors[i].field).addClass("has-chaty-error");
502                                    $("." + response.errors[i].field).after("<span class='chaty-error-msg'>" + response.errors[i].message + "</span>");
503                                }
504                            }
505                            $(".chaty-loader").removeClass("active");
506                        } else if(response.status == 0) {
507                            $(".chaty-contact-inputs").append("<div class='chaty-ajax-error-message'>" + response.message + "</div>");
508                            $(".chaty-loader").removeClass("active");
509                        }
510                    }
511                });
512            } else {
513                $(".has-chaty-error:first").focus();
514            }
515            return false;
516        });
517
518        /* Click function for Call */
519        $(document).on("click", ".chaty-widget.has-single .chaty-i-trigger .chaty-channel:not(.chaty-agent-button).Phone-channel", function () {
520            window.location = $(this).find("a").prop("href");
521        });
522
523        $(document).on("click", ".chaty-widget.has-single .chaty-i-trigger .chaty-channel:not(.chaty-agent-button).Phone-channel a", function (e) {
524            e.stopPropagation();
525            e.stopImmediatePropagation();
526        });
527    });
528
529    /**
530     *
531     * add class to body to check dimension
532     * Added On: 08/17/2022
533     * Added By: Chirag Thummar
534     *
535     * */
536    $(window).resize(function(){
537        if($(window).height() > $(window).width()) {
538            $("body").addClass("cht-portrait").removeClass("cht-landscape");
539        } else {
540            $("body").addClass("cht-landscape").removeClass("cht-portrait");
541        }
542    });
543
544    /**
545     *
546     * To remove animation when widget is clicked
547     * Added On: 09/29/2021
548     * Added By: Chirag Thummar
549     *
550     * */
551    function removeChatyAnimation(widgetId) {
552        if ($("#chaty-widget-" + widgetId).data("animation") != undefined && $("#chaty-widget-" + widgetId).data("animation") != "none") {
553            var animationClass = "chaty-animation-" + $("#chaty-widget-" + widgetId).data("animation");
554            $("#chaty-widget-" + widgetId + " ." + animationClass).removeClass(animationClass);
555        }
556    }
557
558    function checkForCountry() {
559        var hasCountryFilter = false;
560        if (widgetData.length) {
561            $.each(widgetData, function (key, widgetRecord) {
562                if (isTrue(widgetRecord.triggers.has_countries) && !isEmpty(widgetRecord.triggers.countries) && widgetRecord.triggers.countries.length) {
563                    hasCountryFilter = true;
564                }
565            });
566        }
567        if (hasCountryFilter) {
568            clientCountry = getUserCountry();
569            if (clientCountry != '') {
570                startMakingWidgets();
571            } else {
572                getClientCountry();
573            }
574        } else {
575            startMakingWidgets();
576        }
577    }
578
579    /**
580     *
581     * Get client country from cloudflare API
582     * Added On: 10/21/2021
583     * Added By: Chirag Thummar
584     *
585     * */
586
587    function getClientCountry() {
588        var $ipurl = 'https://www.cloudflare.com/cdn-cgi/trace';
589        $.get($ipurl, function (cloudflaredata) {
590            var currentCountry = cloudflaredata.match("loc=(.*)");
591            if (currentCountry.length > 1) {
592                currentCountry = currentCountry[1];
593                if (currentCountry) {
594                    currentCountry = currentCountry.toUpperCase();
595                    if (currentCountry == "") {
596                        currentCountry = "-";
597                    }
598                    setUserCountry(currentCountry);
599                    startMakingWidgets();
600                }
601            }
602        });
603    }
604
605    /**
606     *
607     * Creating widgets from API response
608     * Added On: 10/21/2021
609     * Added By: Chirag Thummar
610     *
611     * */
612    function startMakingWidgets() {
613        if (widgetData.length) {
614            $("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>');
615            $.each(widgetData, function (key, widgetRecord) {
616
617                var customCSS = "";
618                var advanceCustomCSS = "";
619                var activeChannels = 0;
620                var channelSetting = {};
621
622                /* check for country filter */
623                var widgetStatus = true;
624
625                $.each(widgetRecord.channels, function (key, channel) {
626                    var channelStatus = checkForChannel(channel);
627                    if (channelStatus) {
628                        activeChannels++;
629                        channelSetting = channel;
630                    }
631                });
632
633                if (widgetRecord.settings.default_state == "open" && activeChannels == 1) {
634                    widgetRecord.settings.default_state = "click";
635                    widgetData[key].settings.default_state = "click";
636                }
637
638                if (widgetStatus && activeChannels > 0 && !$("#chaty-widget-" + widgetRecord.id).length) {
639                    var widgetPosition = getWidgetPosition(widgetRecord.settings);
640                    widgetPosition = (widgetPosition == "right") ? "right" : "left";
641                    var toolTipPosition = getToolTipPosition(widgetRecord);
642                    if(widgetRecord.settings.cta_type == "chat-view") {
643                        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 + "' >" +
644                            "<div class='chaty-widget " + widgetPosition + "-position'>" +
645                            "<div class='chaty-channels'>" +
646                            "<div class='chaty-i-trigger'></div>" +
647                            "</div>" +
648                            "</div>" +
649                            "</div>";
650                        $("body").append(widgetHtml);
651
652                        makeChatyChatView(widgetRecord);
653                    } else {
654                        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 + "' >" +
655                            "<div class='chaty-widget " + widgetPosition + "-position'>" +
656                            "<div class='chaty-channels'>" +
657                            "<div class='chaty-channel-list'></div>" +
658                            "<div class='chaty-i-trigger'></div>" +
659                            "</div>" +
660                            "</div>" +
661                            "</div>";
662                        $("body").append(widgetHtml);
663                    }
664
665                    if (isTrue(widgetRecord.triggers.auto_hide_widget) && parseInt(widgetRecord.triggers.hide_after) > 0) {
666                        $("#chaty-widget-" + widgetRecord.id).addClass("auto-hide-chaty");
667                        $("#chaty-widget-" + widgetRecord.id).attr("data-time", widgetRecord.triggers.hide_after);
668                    }
669
670                    var clickStatus = checkChatyCookieExpired(widgetRecord.id, 'c-widget');
671                    $("#chaty-widget-" + widgetRecord.id).addClass(widgetRecord.settings.show_cta);
672                    if (activeChannels == 1 && widgetRecord.settings.cta_type != "chat-view") {
673                        if (widgetRecord.settings.icon_view != "vertical") {
674                            toolTipPosition = (widgetPosition != "right") ? "right" : "left";
675                        }
676                        var channelHtml = getChannelSetting(channelSetting, widgetRecord.id, toolTipPosition);
677                        $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").html(channelHtml);
678                        $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").addClass("single-channel");
679                        $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel").addClass("single");
680
681                        $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("has-single");
682
683                        var ctaText = widgetRecord.settings.cta_text;
684                        if(!isEmpty(ctaText)) {
685                            ctaText = htmlDecode(ctaText);
686                        }
687                        if (widgetRecord.settings.show_cta == "first_click") {
688                            if (clickStatus) {
689                                $("#chaty-widget-" + widgetRecord.id + " .chaty-tooltip").removeClass("chaty-tooltip");
690                                $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel").addClass("active").addClass("chaty-tooltip").addClass("pos-"+toolTipPosition);
691
692                                $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel").append("<span class='on-hover-text'>"+ctaText+"</span>").addClass("active").addClass("has-on-hover");
693                                $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").append("<span class='on-hover-text'>"+ctaText+"</span>").addClass("has-on-hover");
694                                $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").attr("data-text", ctaText);
695                                $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").attr("aria-label", ctaText);
696                            } else {
697                                $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a").append("<span class='on-hover-text'>"+ctaText+"</span>").removeClass("active").addClass("has-on-hover");
698                            }
699                        }
700                        if (widgetRecord.settings.show_cta == "all_time") {
701                            $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-tooltip").append("<span class='on-hover-text'>"+ctaText+"</span>").addClass("active").addClass("has-on-hover");
702                            $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger.single-channel .chaty-channel a").attr("data-text", ctaText);
703                        }
704
705                        var channel = channelSetting;
706                        if (channel.channel_type != "Instagram" || (channel.icon_color != "#ffffff" && channel.icon_color != "#fff")) {
707                            customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}";
708                            customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}";
709                        }
710
711
712
713                        customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-custom-icon { background-color: " + channel.icon_color + "; }";
714                        customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-svg { background-color: " + channel.icon_color + ";}";
715                        customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .chaty-svg { background-color: " + channel.icon_color + ";}";
716
717
718                        if(channel.channel_type == "Contact_Us") {
719                            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+";} ";
720                        }
721                    } else {
722                        $.each(widgetRecord.channels, function (key, channel) {
723                            var channelStatus = checkForChannel(channel);
724                            if (channelStatus) {
725                                if (isValueEmpty(channel.channel_type)) {
726                                    channel.channel_type = channel.channel;
727                                }
728
729
730                                if(widgetRecord.settings.cta_type == "chat-view") {
731                                    var channelHtml = getChannelSetting(channel, widgetRecord.id, "top");
732                                    $(".chaty-chat-view-" + widgetRecord.id + " .chaty-view-channels").append(channelHtml);
733                                } else {
734                                    var channelHtml = getChannelSetting(channel, widgetRecord.id, toolTipPosition);
735                                    $("#chaty-widget-" + widgetRecord.id + " .chaty-channel-list").append(channelHtml);
736                                }
737
738                                if (channel.channel_type != "Instagram" || (channel.icon_color != "#ffffff" && channel.icon_color != "#fff")) {
739                                    customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}";
740                                    customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .color-element{ fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}";
741                                }
742
743                                customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-custom-icon { background-color: " + channel.icon_color + "; }";
744                                customCSS += "#chaty-widget-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-svg { background-color: " + channel.icon_color + ";}";
745                                customCSS += "#chaty-widget-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .chaty-svg { background-color: " + channel.icon_color + ";}";
746
747                                customCSS += ".chaty-chat-view-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-custom-icon { background-color: " + channel.icon_color + "; }";
748                                customCSS += ".chaty-chat-view-" + widgetRecord.id + " ." + channel.channel_type + "-channel .chaty-svg { background-color: " + channel.icon_color + ";}";
749                                customCSS += ".chaty-chat-view-" + widgetRecord.id + " .channel-icon-" + channel.channel_type + " .chaty-svg { background-color: " + channel.icon_color + ";}";
750
751                                if(channel.channel_type == "Contact_Us") {
752                                    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+";} ";
753                                }
754                            }
755                        });
756
757                        var widgetIcon = getWidgetIcon(widgetRecord.settings, widgetRecord.id);
758                        /* check for widget CTA button */
759                        var ctaText = widgetRecord.settings.cta_text;
760                        if (widgetRecord.settings.show_cta == "first_click") {
761                            if (!clickStatus) {
762                                ctaText = "";
763                            }
764                        }
765
766                        var ctaToolTipPosition = toolTipPosition;
767                        if (widgetRecord.settings.icon_view == "horizontal") {
768                            if (widgetPosition == "left") {
769                                ctaToolTipPosition = "right";
770                            } else {
771                                ctaToolTipPosition = "left";
772                            }
773                        }
774
775                        if(!isEmpty(ctaText)) {
776                            ctaText = htmlDecode(ctaText);
777                        }
778
779                        var widgetButton = '<div class="chaty-channel chaty-cta-main chaty-tooltip has-on-hover pos-' + ctaToolTipPosition + ' active" data-widget="' + widgetRecord.id + '" >' +
780                            '<span class="on-hover-text">'+ctaText+'</span>' +
781                            '<div class="chaty-cta-button">' +
782                            '<button type="button" class="open-chaty">' +
783                            widgetIcon +
784                            '<span class="sr-only">Open chaty</span>' +
785                            '</button>' +
786                            '<button type="button" class="open-chaty-channel"></button>' +
787                            '</div>' +
788                            '</div>';
789                        $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").html(widgetButton);
790
791                        /* close button */
792                        var closeHtml = '<div class="chaty-channel chaty-cta-close chaty-tooltip pos-' + toolTipPosition + '" data-hover="' + widgetRecord.settings.close_text + '">' +
793                            '<div class="chaty-cta-button"><button type="button">' +
794                            '<span class="chaty-svg">' +
795                            '<svg viewBox="0 0 52 52" fill="#ffffff" 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>
795' +
796                            '</span>' +
797                            '<span class="sr-only">Hide chaty</span>' +
798                            '</button>' +
799                            '</div>' +
800                            '</div>';
801                        $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger").append(closeHtml);
802                    }
803
804                    $.each(widgetRecord.channels, function (key, channel) {
805                        if(channel.channel_type == "Contact_Us" && channel.hide_recaptcha_badge == "yes") {
806                            customCSS += ".grecaptcha-badge {visibility: hidden;}";
807                        }
808                    });
809
810
811                    var clickStatus = checkChatyCookieExpired(widgetRecord.id, 'c-widget');
812                    if (clickStatus && (widgetRecord.settings.default_state != "open" || activeChannels == 1)) {
813                        checkForPendingMessage(widgetRecord.settings, widgetRecord.id);
814                        checkForWidgetAnimation(widgetRecord.settings, widgetRecord.id);
815                    }
816
817                    var extraSpace = 0;
818                    /* check for close button */
819                    if (widgetRecord.settings.default_state == "open" && !isTrue(widgetRecord.settings.show_close_button)) {
820                        $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("chaty-no-close-button").addClass("chaty-open");
821                        extraSpace = 1;
822                    }
823
824                    /* checking for google analytics */
825                    if (isTrue(widgetRecord.settings.is_google_analytics_enabled)) {
826                        $("#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel > a").addClass("has-gae");
827                        $("#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-channel > a").addClass("has-gae");
828                        $("#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger.single-channel .chaty-channel > a").addClass("has-gae");
829
830                        $(".chaty-outer-forms.chaty-whatsapp-form.chaty-form-" + widgetRecord.id + " form.add-analytics").addClass("form-google-analytics");
831                        $(".whatsapp-chaty-form-" + widgetRecord.id).addClass("has-form-gae");
832                    }
833
834                    /* checking for custom CSS */
835                    if (isTrue(widgetRecord.settings.has_custom_css) && !isEmpty(widgetRecord.settings.custom_css)) {
836                        advanceCustomCSS += widgetRecord.settings.custom_css;
837                    }
838
839                    /* check for State */
840                    if (widgetRecord.settings.default_state == "hover") {
841                        $("#chaty-widget-" + widgetRecord.id).addClass("open-on-hover");
842                    } else if (widgetRecord.settings.default_state == "open") {
843                        $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("default-open");
844                        if (clickStatus || !isTrue(widgetRecord.settings.show_close_button)) {
845                            $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("chaty-open");
846                        }
847                    }
848
849                    /* set widget channel height */
850                    var widgetSize = getWidgetSize(widgetRecord.settings.widget_size, widgetRecord.settings.custom_widget_size);
851                    widgetSize = parseInt(widgetSize);
852                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
853                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel > a {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
854                    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; }";
855                    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%;}";
856                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel .chaty-svg {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
857                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel .chaty-svg img {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
858                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel span.chaty-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
859                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel a {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
860                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list .chaty-channel .chaty-svg .chaty-custom-c
860hannel-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; line-height: " + widgetSize + "px; display: block; font-size:" + (parseInt(widgetSize / 2)) + "px; }";
861                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-cta-button {background-color: " + widgetRecord.settings.widget_color + "; }";
862                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-cta-button button {background-color: " + widgetRecord.settings.widget_color + "; }";
863                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
864                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel > a {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
865                    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; }";
866                    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%;}";
867                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel .chaty-svg {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
868                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel .chaty-svg img {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
869                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel span.chaty-icon {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
870                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-i-trigger .chaty-channel a {width: " + widgetSize + "px; height: " + widgetSize + "px; }";
871                    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; }";
872
873                    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 + "; }";
874
875                    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; }";
876
877                    if (widgetRecord.settings.icon_view == "vertical") {
878                        //customCSS += "#chaty-widget-"+widgetRecord.id+" .chaty-channel-list {bottom: "+(widgetSize+4)+"px; }";
879                        customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {height: " + (activeChannels * (widgetSize + 8)) + "px; }";
880                        customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {width: " + (widgetSize + 8) + "px; }";
881
882                        for (var i = 0; i <= activeChannels; i++) {
883                            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);}";
884                        }
885                    } else {
886                        $("#chaty-widget-" + widgetRecord.id + " .chaty-widget").addClass("hor-mode");
887                        customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {width: " + (activeChannels * (widgetSize + 8)) + "px; }";
888                        customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-channel-list {height: " + (widgetSize) + "px; }";
889                        // customCSS += "#chaty-widget-"+widgetRecord.id+" .chaty-widget.left-position.hor-mode .chaty-channel-list {left: "+(widgetSize+8)+"px; }";
890                        // customCSS += "#chaty-widget-"+widgetRecord.id+" .chaty-widget.right-position.hor-mode .chaty-channel-list {right: "+(widgetSize+8)+"px; }";
891
892                        for (var i = 0; i <= activeChannels; i++) {
893                            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(" 
893+ ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px); transform: translateX(" + ((widgetSize + 8) * (activeChannels - i - extraSpace)) + "px);}";
894                            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);}";
895                        }
896                    }
897
898
899                    /* set widget position */
900                    var bottomSpacing = widgetRecord.settings.bottom_spacing;
901                    var sideSpacing = widgetRecord.settings.side_spacing;
902                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget {bottom: "+(bottomSpacing)+"px}";
903
904                    if (widgetPosition == "left") {
905                        customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget {left: " + sideSpacing + "px; right: auto;}";
906                        customCSS += ".chaty-outer-forms.pos-left.chaty-form-" + widgetRecord.id + " {left: " + sideSpacing + "px}";
907                        $(".chaty-form-" + widgetRecord.id).addClass("pos-left");
908                    } else {
909                        customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-widget {right: " + sideSpacing + "px; left:auto;}";
910                        $(".chaty-form-" + widgetRecord.id).addClass("pos-right");
911                        customCSS += ".chaty-outer-forms.pos-right.chaty-form-" + widgetRecord.id + " {right: " + sideSpacing + "px; left:auto;}";
912                    }
913                    $(".chaty-form-" + widgetRecord.id).show();
914
915                    var formBottomPos = widgetSize + 15 + parseInt(bottomSpacing)
916                    customCSS += ".chaty-outer-forms.active.chaty-form-" + widgetRecord.id + " {-webkit-transform: translateY(-"+formBottomPos+"px); transform: translateY(-"+formBottomPos+"px)} ";
917                    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)} ";
918
919                    /* set on hover text color */
920                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip:after {background-color: " + widgetRecord.settings.cta_bg_color + "; color: " + widgetRecord.settings.cta_text_color + "}";
921                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-top:before {border-top-color: " + widgetRecord.settings.cta_bg_color + "; }";
922                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-left:before {border-left-color: " + widgetRecord.settings.cta_bg_color + "; }";
923                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-right:before {border-right-color: " + widgetRecord.settings.cta_bg_color + ";}";
924                    customCSS += "#chaty-widget-" + widgetRecord.id + " .on-hover-text {background-color: " + widgetRecord.settings.cta_bg_color + "; color: " + widgetRecord.settings.cta_text_color + "}";
925                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-top .on-hover-text:before {border-top-color: " + widgetRecord.settings.cta_bg_color + "; }";
926                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-left .on-hover-text:before {border-left-color: " + widgetRecord.settings.cta_bg_color + "; }";
927                    customCSS += "#chaty-widget-" + widgetRecord.id + " .chaty-tooltip.pos-right .on-hover-text:before {border-right-color: " + widgetRecord.settings.cta_bg_color + ";}";
928
929                    /* Custom CSS for Agents */
930                    var agentMaxHeight = formBottomPos + 72 + widgetSize;
931                    if (agentMaxHeight > 0) {
932                        customCSS += ".chaty-outer-forms.chaty-form-" + widgetRecord.id + " .chaty-agent-body {max-height: calc(100vh - " + agentMaxHeight + "px); overflow-y: auto; } ";
933                    }
934
935                    customCSS += "#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-view-header {background-color: " + widgetRecord.settings.cta_head_bg_color + ";}";
936                    customCSS += "#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-view-header {color: " + widgetRecord.settings.cta_head_text_color + ";}";
937                    customCSS += "#chaty-form-" + widgetRecord.id + "-chaty-chat-view .chaty-view-header svg {fill : " + widgetRecord.settings.cta_head_text_color + ";}";
938
939                    /* Custom CSS for WhatsApp */
940                    var whatsAppMaxHeight = formBottomPos + 72 + widgetSize;
941                    if (whatsAppMaxHeight > 0) {
942                        customCSS += ".chaty-outer-forms.chaty-whatsapp-form.chaty-form-" + widgetRecord.id + " .chaty-whatsapp-content {max-height: calc(100vh - " + whatsAppMaxHeight + "px); overflow-y: auto; } ";
943                    }
944
945                    /* Custom CSS for Contact Form */
946                    var contactFormMaxHeight = formBottomPos + 82 + widgetSize;
947                    if (contactFormMaxHeight > 0) {
948                        customCSS += ".chaty-outer-forms.chaty-contact-form-box.chaty-form-" + widgetRecord.id + " .chaty-contact-inputs {max-height: calc(100vh - " + contactFormMaxHeight + "px); overflow-y: auto; } ";
949                    }
950
951                    if(bottomSpacing != 25 || sideSpacing != 25) {
952                        $(".chaty-outer-forms.chaty-form-" + widgetRecord.id).addClass("custom-cht-pos");
953                        $("#chaty-widget-"+widgetRecord.id).addClass("has-custom-pos");
954                    }
955
956                    /* checking for triggers */
957                    var visibleStatus = checkChatyCookieExpired(widgetRecord.id, 'v-widget');
958
959                    if (visibleStatus) {
960                        if (isTrue(widgetRecord.triggers.exit_intent) || isTrue(widgetRecord.triggers.has_time_delay) || isTrue(widgetRecord.triggers.has_display_after_page_scroll) > 0) {
961                            /* checking for time delay */
962
963                            if ((isTrue(widgetRecord.triggers.has_time_delay) && parseInt(widgetRecord.triggers.time_delay) == 0)) {
964                                updateWidgetViews(widgetRecord.id);
965                                $("#chaty-widget-" + widgetRecord.id).addClass("active");
966                            } else if ((isTrue(widgetRecord.triggers.has_time_delay) && parseInt(widgetRecord.triggers.time_delay) > 0)) {
967                                chatyHasTimeDelay = true;
968                                if (parseInt(widgetRecord.triggers.time_delay) > chatyMaxTimeInterval) {
969                                    chatyMaxTimeInterval = widgetRecord.triggers.time_delay;
970                                }
971                                $("#chaty-widget-" + widgetRecord.id).addClass("on-chaty-delay");
972                                $("#chaty-widget-" + widgetRecord.id).addClass("delay-time-" + parseInt(widgetRecord.triggers.time_delay));
973                                $("#chaty-widget-" + widgetRecord.id).attr("data-time", parseInt(widgetRecord.triggers.time_delay));
974                            }
975
976                            /* checking for page scroll */
977                            if ((isTrue(widgetRecord.triggers.has_display_after_page_scroll) && parseInt(widgetRecord.triggers.display_after_page_scroll) == 0)) {
978                                updateWidgetViews(widgetRecord.id);
979                                $("#chaty-widget-" + widgetRecord.id).addClass("active");
980                            } else if ((isTrue(widgetRecord.triggers.has_display_after_page_scroll) && parseInt(widgetRecord.triggers.display_after_page_scroll) > 0)) {
981                                chatyHasPageScroll = true;
982                                $("#chaty-widget-" + widgetRecord.id).addClass("on-chaty-scroll");
983                                $("#chaty-widget-" + widgetRecord.id).addClass("page-scroll-" + parseInt(widgetRecord.triggers.display_after_page_scroll));
984                                $("#chaty-widget-" + widgetRecord.id).attr("data-scroll", parseInt(widgetRecord.triggers.display_after_page_scroll));
985                            }
986
987                            /* checking for exit intent */
988                            if (isTrue(widgetRecord.triggers.exit_intent)) {
989                                chatyHasExitIntent = true;
990                                $("#chaty-widget-" + widgetRecord.id).addClass("on-chaty-exit-intent");
991                            }
992                        } else {
993                            // saveChatyCookieString(widgetRecord.id, 'v-widget');
994                            updateWidgetViews(widgetRecord.id);
995                            $("#chaty-widget-" + widgetRecord.id).addClass("active");
996                        }
997                    } else {
998                        updateWidgetViews(widgetRecord.id);
999                        $("#chaty-widget-" + widgetRecord.id).addClass("active");
1000                    }
1001
1002                    /* check for font family */
1003                    if (!isEmpty(widgetRecord.settings.font_family) && widgetRecord.settings.font_family != "none") {
1004
1005                        /* check for default browser font */
1006                        var fontFamily = widgetRecord.settings.font_family;
1007                        if ($.inArray(fontFamily, defaultFontFamily) != -1) {
1008                            if (fontFamily == "System Stack") {
1009                                fontFamily = "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif";
1010                            }
1011                        } else {
1012                            /* load fonts from google */
1013                            $('head').append('<link rel="preload" as="style" href="https://fonts.googleapis.com/css?family=' + fontFamily + '&display=swap">');
1014                            $('head').append('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=' + fontFamily + '&display=swap">');
1015                        }
1016                        customCSS += "#chaty-widget-" + widgetRecord.id + ", #chaty-widget-" + widgetRecord.id + " .chaty-tooltip:after {font-family: " + fontFamily + "}";
1017                    }
1018                }
1019
1020                if(chatyHasExitIntent) {
1021                    bindExitIntentFunction();
1022                }
1023
1024                /* set dynamic CSS for widget */
1025                if (customCSS != "") {
1026                    if (!$("#custom-chaty-css").length) {
1027                        $("head").append("<style id='custom-chaty-css'></style>");
1028                    }
1029                    $("#custom-chaty-css").append(customCSS);
1030                }
1031
1032                /* set dynamic CSS for widget */
1033                if (advanceCustomCSS != "") {
1034                    if (!$("#custom-advance-chaty-css").length) {
1035                        $("head").append("<style id='custom-advance-chaty-css'></style>");
1036                    }
1037                    $("#custom-advance-chaty-css").append(advanceCustomCSS);
1038                }
1039
1040                if (key == (widgetData.length - 1)) {
1041
1042                }
1043
1044                if($(".chaty-sms-channel").length) {
1045                    $(".chaty-sms-channel").each(function(){
1046                        var thisLink = $(this).attr("href");
1047                        thisLink = thisLink.replace(/{title}/g, getPageTitle());
1048                        thisLink = thisLink.replace(/{url}/g, window.location.href);
1049                        $(this).attr("href", thisLink);
1050                    });
1051                }
1052            });
1053            if (!$("#custom-advance-chaty-css").length) {
1054                $("head").append("<style id='custom-advance-chaty-css'></style>");
1055            }
1056            $("#custom-advance-chaty-css").append(customExtraCSS);
1057            if(($(".v3_site_key").length && !isEmpty($(".v3_site_key").val())) || ($(".v2_site_key").length && !isEmpty($(".v2_site_key").val()))) {
1058                LoadChatyGoogleRecaptcha();
1059            }
1060        }
1061        removeEmptyTooltip();
1062        checkForchatyTriggers();
1063    }
1064
1065
1066    function getPageTitle() {
1067        return $("title").length?$("title").text():"";
1068    }
1069
1070
1071    function makeChatyChatView(widgetRecord) {
1072        var widgetId = widgetRecord.id;
1073        var widgetIndex = getWidgetIndex(widgetId);
1074        if (widgetIndex == null) {
1075            widgetIndex = -1;
1076        }
1077        var bodyMsg = widgetRecord.settings.cta_body;
1078        var headMsg = widgetRecord.settings.cta_head;
1079        var pageTitle = $("title").text();
1080        if(!isEmpty(pageTitle)) {
1081            bodyMsg = bodyMsg.replace(/{title}/g, pageTitle);
1082            headMsg = headMsg.replace(/{title}/g, pageTitle);
1083        } else {
1084            bodyMsg = bodyMsg.replace(/{title}/g, '');
1085            headMsg = headMsg.replace(/{title}/g, '');
1086        }
1087        bodyMsg = bodyMsg.replace(/{url}/g, "<a target='_blank' href='"+window.location.href+"'>"+window.location.href+"</a>");
1088        headMsg = headMsg.replace(/{url}/g, "<a target='_blank' href='"+window.location.href+"'>"+window.location.href+"</a>");
1089        var formHtml = "";
1090        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 + "'>";
1091        formHtml += "<div class='chaty-view-body'>";
1092        formHtml += "<div class='chaty-view-header'>"+headMsg;
1093        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.996-150c5.859-5.857 5.859-15.355.001-21.213z'/></svg></div>";
1094        formHtml += "</div>";
1095        formHtml += "<div class='chaty-view-content'>";
1096        formHtml += "<div class='chaty-top-content'>";
1097        formHtml += bodyMsg;
1098        formHtml += "</div>";
1099        formHtml += "<div class='chaty-view-channels'>";
1100        formHtml += "</div>";
1101        formHtml += "</div>";
1102        formHtml += "</div>";
1103        formHtml += "</div>";
1104        $("#chaty-widget-"+widgetId).append(formHtml);
1105    }
1106
1107
1108    /**
1109     *
1110     * To Esc HTML Tags
1111     * Added On: 07/14/2022
1112     * Added By: Chirag Thummar
1113     *
1114     * */
1115
1116
1117    function htmlDecode(input) {
1118        var doc = new DOMParser().parseFromString(input, "text/html");
1119        return doc.documentElement.textContent;
1120    }
1121
1122
1123    /**
1124     *
1125     * Checking for Channel (is normal chhanel or agent channel)
1126     * Added On: 10/19/2021
1127     * Added By: Chirag Thummar
1128     *
1129     * */
1130
1131    function checkForChannel(channel) {
1132        if (isTrue(channel.is_agent)) {
1133            if (channel.agent_data.length) {
1134                if (((!isChatyInMobile && isTrue(channel.is_agent_desktop)) || (isChatyInMobile && isTrue(channel.is_agent_mobile)))) {
1135                    return true;
1136                }
1137            }
1138        } else {
1139            if (((!isChatyInMobile && isTrue(channel.is_desktop)) || (isChatyInMobile && isTrue(channel.is_mobile))) && (channel.value != '' || channel.channel == "Contact_Us")) {
1140                return true;
1141            }
1142        }
1143        return false;
1144    }
1145
1146    /**
1147     *
1148     * Update widget views
1149     * Added On: 10/19/2021
1150     * Added By: Chirag Thummar
1151     *
1152     * */
1153
1154    function updateWidgetViews(widgetId) {
1155        if(parseInt(chaty_settings.capture_analytics)) {
1156            chaty_settings.capture_analytics = 0;
1157            $.ajax({
1158                url: chaty_settings.ajax_url,
1159                type: 'post',
1160                data: {
1161                    action: "update_chaty_view",
1162                    token: chaty_settings.token
1163                }
1164            })
1165        }
1166        if ($("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open").length) {
1167            // $(".chaty-outer-forms").show();
1168            var dataForm = $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open a.chaty-whatsapp-form").data('form');
1169            if (!isEmpty(dataForm)) {
1170                var clickStatus = checkChatyCookieExpired(widgetId, "c-" + $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open").data('channel'));
1171                if (clickStatus) {
1172                    $("#" + dataForm).addClass("is-active");
1173                    if ($("#" + dataForm).length) {
1174                        var buttonHtml = $("#chaty-widget-" + widgetId + " .chaty-channel.chaty-default-open a.chaty-whatsapp-form").html()+"<span class='hide-cht-svg-bg'>"+chaty_settings.lang.hide_whatsapp_form+"</span>";
1175
1176                        removeChatyAnimation(widgetId);
1177                        $("#chaty-widget-" + widgetId   ).find(".ch-pending-msg").remove();
1178                        $("#chaty-widget-" + widgetId + " .chaty-widget").removeClass("chaty-open");
1179                        $("#chaty-widget-" + widgetId).addClass("form-open");
1180                        $("#" + dataForm).addClass("active");
1181
1182                        $("#chaty-widget-" + widgetId + " .open-chaty-channel").html(buttonHtml);
1183                        $("#chaty-widget-" + widgetId).addClass("active");
1184
1185                        $("#chaty-widget-" + widgetId).addClass("active");
1186                        if ($("#chaty-widget-" + widgetId).hasClass("auto-hide-chaty")) {
1187                            var hideAfter = parseInt($("#chaty-widget-" + widgetId).data("time"));
1188                            if (hideAfter > 0) {
1189                                hideAfter = hideAfter + chatyHideIntervalTime;
1190                                $("#chaty-widget-" + widgetId).addClass("hide-after-" + hideAfter);
1191                            }
1192                        }
1193                        return;
1194                    }
1195                }
1196            }
1197        }
1198
1199        $("#chaty-widget-" + widgetId).addClass("active");
1200        if ($("#chaty-widget-" + widgetId).hasClass("auto-hide-chaty")) {
1201            var hideAfter = parseInt($("#chaty-widget-" + widgetId).data("time"));
1202            if (hideAfter > 0) {
1203                hideAfter = hideAfter + chatyHideIntervalTime;
1204                $("#chaty-widget-" + widgetId).addClass("hide-after-" + hideAfter);
1205            }
1206        }
1207
1208        var viewStatus = checkChatyCookieExpired(widgetId, "v-widget");
1209        if (viewStatus) {
1210            saveChatyCookieString(widgetId, 'v-widget');
1211            var widgetChannels = [];
1212            var isSingle = 0;
1213            var isDefaultOpen = 0;
1214            var widgetChannel;
1215            var widgetKey = $("#chaty-widget-" + widgetId).data("key");
1216            if (typeof widgetData[widgetKey] != undefined) {
1217                var activeWidgets = chatyGetCookie("activechatyWidgets");
1218                if (activeWidgets != null) {
1219                    activeWidgets = activeWidgets.split(",");
1220                    if ($.inArray(widgetId, activeWidgets) == -1) {
1221                        activeWidgets.push(widgetId);
1222                        activeWidgets = activeWidgets.join(",");
1223                        chatySetCookie("activechatyWidgets", activeWidgets, 1);
1224                    }
1225                } else {
1226                    activeWidgets = widgetId;
1227                    chatySetCookie("activechatyWidgets", activeWidgets, 1);
1228                }
1229            }
1230            if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("has-single")) {
1231                isSingle = 1;
1232                widgetChannel = $("#chaty-widget-" + widgetId + " .chaty-channel").data("channel");
1233                var viewChannelStatus = checkChatyCookieExpired(widgetId, "v-" + widgetChannel);
1234                if (viewChannelStatus && typeof widgetChannel != 'undefined') {
1235                    saveChatyCookieString(widgetId, "v-" + widgetChannel);
1236                    widgetChannels.push(widgetChannel);
1237                }
1238            } else if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("chaty-open")) {
1239                isDefaultOpen = 1;
1240                if($("#chaty-widget-" + widgetId).hasClass("chaty-has-chat-view")) {
1241                    $(".chaty-chat-view.chaty-chat-view-" + widgetId + " .chaty-view-channels").find(".chaty-channel").each(function () {
1242                        chatyChannel = $(this).data("channel");
1243                        clickStatus = checkChatyCookieExpired(widgetId, "v-" + chatyChannel);
1244                        if (clickStatus && typeof chatyChannel != 'undefined') {
1245                            saveChatyCookieString(widgetId, "v-" + chatyChannel);
1246                            widgetChannels.push(chatyChannel);
1247                        }
1248                    });
1249                } else {
1250                    $("#chaty-widget-" + widgetId + " .chaty-channel-list .chaty-channel").each(function () {
1251                        widgetChannel = $(this).data("channel");
1252                        var viewChannelStatus = checkChatyCookieExpired(widgetId, "v-" + widgetChannel);
1253                        if (viewChannelStatus && typeof widgetChannel != 'undefined') {
1254                            saveChatyCookieString(widgetId, "v-" + widgetChannel);
1255                            widgetChannels.push(widgetChannel);
1256                        }
1257                    });
1258                }
1259            }
1260        }
1261    }
1262
1263    /**
1264     *
1265     * check for visitor status and update it if required
1266     * Added On: 10/04/2021
1267     * Added By: Chirag Thummar
1268     *
1269     * */
1270    function updateVisitorCount(widgetId) {
1271        var userId = $("#chaty-widget-" + widgetId).data("user");
1272        var isOldUser = chatySaasCheckCookie("triggeredFor" + userId);
1273        if (!isOldUser) {
1274            chatySetCookie("triggeredFor" + userId, widgetId, 2);
1275        }
1276    }
1277
1278    /**
1279     *
1280     * Check for Triggers if exists
1281     * Added On: 10/04/2021
1282     * Added By: Chirag Thummar
1283     *
1284     * */
1285
1286    function getWidgetSize(widgetSize, customSize) {
1287        return widgetSize;
1288    }
1289
1290    /**
1291     *
1292     * To get widget CTA icon by it's key
1293     * Added On: 09/29/2021
1294     * Added By: Chirag Thummar
1295     *
1296     * */
1297    function getSvgIcon(iconName, widgetColor, iconColor, widgetId) {
1298        switch (iconName) {
1299            case"chat-smile":
1300                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>';
1301            case"chat-bubble":
1302                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>';
1303            case"chat-db":
1304                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>';
1305            default:
1306                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"/>
1306<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>'
1307        }
1308    }
1309
1310    /**
1311     *
1312     * To get channel settings
1313     * Added On: 10/01/2021
1314     * Added By: Chirag Thummar
1315     *
1316     * */
1317
1318    function getChannelSetting(channel, widgetId, toolTipPosition) {
1319        var extraClass = "";
1320        if (isTrue(channel.is_agent)) {
1321            if (channel.agent_data.length) {
1322                var activeAgents = 0;
1323                var activeAgent = [];
1324                $.each(channel.agent_data, function (key, agent) {
1325                    if (agent.value != "") {
1326                        activeAgents++;
1327                        activeAgent = agent;
1328                    }
1329                });
1330                if (activeAgents > 0) {
1331                    var channelIcon, channelLink;
1332                    var widgetIndex = getWidgetIndex(widgetId);
1333                    if (widgetIndex == null) {
1334                        widgetIndex = -1;
1335                    }
1336                    createAgentList(channel, widgetId);
1337                    channelIcon = getChannelIcon(channel, widgetId);
1338                    channelLink = getChannelURL(channel, channelIcon, toolTipPosition, widgetId);
1339
1340                    if (channel.channel != "Instagram" || (channel.icon_color != "#ffffff" && channel.icon_color != "#fff")) {
1341                        customExtraCSS += ".chaty-agent-" + widgetId + "-" + channel.channel + " .color-element {fill: " + channel.icon_color + "; color: " + channel.icon_color + ";}";
1342                    }
1343                    customExtraCSS += ".chaty-agent-" + widgetId + "-" + channel.channel + " .chaty-custom-icon { background-color: " + channel.icon_color + ";}";
1344                    customExtraCSS += ".chaty-agent-" + widgetId + "-" + channel.channel + " .chaty-svg-img { background-color: " + channel.icon_color + ";}";
1345                    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>";
1346
1347                }
1348            }
1349        } else {
1350            if (isValueEmpty(channel.channel_type)) {
1351                channel.channel_type = channel.channel;
1352            }
1353            var channelIcon = getChannelIcon(channel, widgetId);
1354            var channelLink = getChannelURL(channel, channelIcon, toolTipPosition, widgetId);
1355            if (channel.channel_type == "Contact_Us") {
1356                extraClass += " has-chaty-box chaty-contact-form";
1357            } else if (channel.channel_type == "Whatsapp") {
1358                if (isTrue(channel.has_welcome_message) && !isEmpty(channel.chat_welcome_message)) {
1359                    if (isTrue(channel.is_default_open)) {
1360                        var clickStatus = checkChatyCookieExpired(widgetId, "c-" + channel.channel_type);
1361                        if (clickStatus) {
1362                            extraClass += " chaty-default-open"
1363                        }
1364                    }
1365                }
1366            }
1367            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>";
1368        }
1369    }
1370
1371
1372    function createAgentList(channel, widgetId) {
1373        var formHtml = "";
1374        var widgetIndex = getWidgetIndex(widgetId);
1375        if (widgetIndex == null) {
1376            widgetIndex = -1;
1377        }
1378        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 + "'>";
1379        formHtml += "<div class='chaty-form'>";
1380        formHtml += "<div class='chaty-form-body'>";
1381        formHtml += "<div role='button' class='chaty-close-agent-list'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 330 330' xmlns:v='https://vecta.io/nano'><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
13816-150c5.859-5.857 5.859-15.355.001-21.213z'/></svg></div>";
1382        formHtml += "<div class='chaty-agent-header agent-info-" + widgetId + "-" + channel.channel + "'>";
1383        if (!isEmpty(channel.header_text)) {
1384            formHtml += "<div class='agent-main-header'>" + channel.header_text + "</div>";
1385        }
1386        if (!isEmpty(channel.header_sub_text)) {
1387            formHtml += "<div class='agent-sub-header'>" + channel.header_sub_text + "</div>";
1388        }
1389        formHtml += "</div>";
1390        formHtml += "<div class='chaty-agent-body agents-body-" + widgetId + " agent-body-" + widgetId + "-" + channel.channel + "'>";
1391        $.each(channel.agent_data, function (key, agent) {
1392            if (agent.value != "") {
1393                var agentIcon = agent.svg_icon;
1394                if (!isEmpty(agent.agent_image)) {
1395                    agentIcon = "<img class='chaty-agent-img' src='" + agent.agent_image + "' alt='" + agent.agent_title + "' />"
1396                }
1397                var agentLink = getAgentURL(agent, channel, widgetId, key, agentIcon, agent.agent_title);
1398                formHtml += "<div class='chaty-agent agent-info-" + widgetId + "-" + channel.channel + " agent-info-" + key + "'>" + agentLink + "</div>";
1399            }
1400            customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + ".agent-info-" + key + " .chaty-agent-icon img { background-color: " + agent.agent_bg_color + "; } ";
1401            if (channel.channel != "Instagram" || (agent.agent_bg_color != "#ffffff" && agent.agent_bg_color != "#fff")) {
1402                customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + ".agent-info-" + key + " .chaty-agent-icon .color-element { fill: " + agent.agent_bg_color + "; } ";
1403            }
1404            customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + ".agent-info-" + key + " .chaty-custom-icon { background-color: " + agent.agent_bg_color + "; } ";
1405        });
1406        formHtml += "</div>";
1407        formHtml += "</div>";
1408        formHtml += "</div>";
1409        formHtml += "</div>";
1410        customExtraCSS += ".chaty-agent-header.agent-info-" + widgetId + "-" + channel.channel + " { background-color: " + channel.header_bg_color + "; color: " + channel.header_text_color + " } ";
1411        customExtraCSS += ".agent-info-" + widgetId + "-" + channel.channel + " .chaty-close-agent-list svg { fill: " + channel.header_text_color + " } ";
1412        $("body").append(formHtml);
1413    }
1414
1415    function getAgentChannelURL(channel, agent, widgetId, channelIcon, toolTipPosition) {
1416        var agentURL = agent.value;
1417        var agentTarget = "_blank";
1418        if (channel.channel_type == "Whatsapp") {
1419            var whatsAppNumber = getWhatsAppNumber(agent.value);
1420            if (isChatyInMobile) {
1421                agentTarget = "";
1422                agentURL = whatsAppNumber;
1423            } else {
1424                agentTarget = "_blank";
1425                agentURL = whatsAppNumber;
1426            }
1427        } else if (channel.channel_type == "WeChat") {
1428            agentTarget = "";
1429            agentURL = "javascript:;";
1430        } else if (channel.channel_type == "Email") {
1431            agentTarget = "";
1432            agentURL = "mailto:" + agent.value;
1433        } else if (channel.channel_type == "Facebook_Messenger") {
1434            if (isChatyInMobile) {
1435                agentTarget = "";
1436            } else {
1437                agentTarget = "_blank";
1438            }
1439        } else if (channel.channel_type == "SMS") {
1440            agentTarget = "";
1441            agentURL = "sms:" + agent.value;
1442        } else if (channel.channel_type == "Telegram") {
1443            agentURL = trimChar(agent.value, "@");
1444            agentURL = "https://telegram.me/" + agentURL;
1445            agentTarget = "_blank";
1446        } else if (channel.channel_type == "Twitter") {
1447            agentURL = "https://twitter.com/" + $.trim(agent.value);
1448        } else if (channel.channel_type == "Phone") {
1449            agentTarget = "";
1450            agentURL = "tel:" + $.trim(agent.value);
1451        } else if (channel.channel_type == "Skype") {
1452            agentTarget = "";
1453            agentURL = "skype:" + $.trim(agent.value) + "?chat";
1454        } else if (channel.channel_type == "Snapchat") {
1455            agentURL = "https://www.snapchat.com/add/" + $.trim(agent.value);
1456        } else if (channel.channel_type == "Vkontakte") {
1457            agentURL = "https://vk.me/" + $.trim(agent.value);
1458        } else if (channel.channel_type == "Linkedin") {
1459            if (agent.link_type == "personal") {
1460                agentURL = "https://www.linkedin.com/in/" + $.trim(agent.value);
1461            } else {
1462                agentURL = "https://www.linkedin.com/company/" + $.trim(agent.value);
1463            }
1464        } else if (channel.channel_type == "Viber") {
1465            agentURL = trimChar(agent.value, "+");
1466            if (!isNaN(agentURL)) {
1467                agentURL = agentURL.replace("+", "");
1468                if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
1469                    agentURL = "+" + agentURL;
1470                }
1471                agentURL = "viber://chat?number=" + agentURL;
1472            }
1473            agentTarget = "";
1474        } else if (channel.channel_type == "TikTok") {
1475            agentURL = trimChar($.trim(agent.value), "@");
1476            agentURL = "https://www.tiktok.com/@" + agentURL;
1477            agentTarget = "";
1478        }
1479        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>";
1480    }
1481
1482    function getAgentURL(agent, channel, widgetId, key, agentIcon, agentTitle) {
1483        var agentURL = agent.value;
1484        var agentTarget = "_blank";
1485        if (channel.channel_type == "Whatsapp") {
1486            var whatsAppNumber = getWhatsAppNumber(agent.value);
1487            if (isChatyInMobile) {
1488                agentTarget = "";
1489                agentURL = whatsAppNumber;
1490            } else {
1491                agentTarget = "_blank";
1492                agentURL = whatsAppNumber;
1493            }
1494        } else if (channel.channel_type == "WeChat") {
1495            agentTarget = "";
1496            agentURL = "javascript:;";
1497        } else if (channel.channel_type == "Email") {
1498            agentTarget = "";
1499            agentURL = "mailto:" + agent.value;
1500        } else if (channel.channel_type == "Facebook_Messenger") {
1501            if (isChatyInMobile) {
1502                agentTarget = "";
1503            } else {
1504                agentTarget = "_blank";
1505            }
1506        } else if (channel.channel_type == "SMS") {
1507            agentTarget = "";
1508            agentURL = "sms:" + agent.value;
1509        } else if (channel.channel_type == "Telegram") {
1510            agentURL = trimChar(agent.value, "@");
1511            agentURL = "https://telegram.me/" + agentURL;
1512            agentTarget = "_blank";
1513        } else if (channel.channel_type == "Twitter") {
1514            agentURL = "https://twitter.com/" + $.trim(agent.value);
1515        } else if (channel.channel_type == "Instagram") {
1516            agentURL = "https://www.instagram.com/" + $.trim(agent.value);
1517        } else if (channel.channel_type == "Phone") {
1518            agentTarget = "";
1519            agentURL = "tel:" + $.trim(agent.value);
1520        } else if (channel.channel_type == "Skype") {
1521            agentTarget = "";
1522            agentURL = "skype:" + $.trim(agent.value) + "?chat";
1523        } else if (channel.channel_type == "Snapchat") {
1524            agentURL = "https://www.snapchat.com/add/" + $.trim(agent.value);
1525        } else if (channel.channel_type == "Vkontakte") {
1526            agentURL = "https://vk.me/" + $.trim(agent.value);
1527        } else if (channel.channel_type == "Linkedin") {
1528            if (agent.link_type == "personal") {
1529                agentURL = "https://www.linkedin.com/in/" + $.trim(agent.value);
1530            } else {
1531                agentURL = "https://www.linkedin.com/company/" + $.trim(agent.value);
1532            }
1533        } else if (channel.channel_type == "Viber") {
1534            agentURL = trimChar(agent.value, "+");
1535            if (!isNaN(agentURL)) {
1536                agentURL = agentURL.replace("+", "");
1537                if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
1538                    agentURL = "+" + agentURL;
1539                }
1540                agentURL = "viber://chat?number=" + agentURL;
1541            }
1542            agentTarget = "";
1543        } else if (channel.channel_type == "TikTok") {
1544            agentURL = trimChar($.trim(agent.value), "@");
1545            agentURL = "https://www.tiktok.com/@" + agentURL;
1546            agentTarget = "";
1547        }
1548        return "<a href='" + agentURL + "' target='" + agentTarget + "'><span class='chaty-agent-icon'>" + agentIcon + "</span><span class='chaty-agent-title'>" + agentTitle + "</span></a>";
1549    }
1550
1551    function getWhatsAppNumber(phoneNumber) {
1552        phoneNumber = trimChar(phoneNumber, "+");
1553        phoneNumber = phoneNumber.replace(/ /g, "");
1554        phoneNumber = phoneNumber.replace(/-/g, "");
1555        phoneNumber = phoneNumber.replace(/_/g, "");
1556        return phoneNumber;
1557    }
1558
1559
1560    function trimChar(string, charToRemove) {
1561        string = $.trim(string);
1562        while (string.charAt(0) == charToRemove) {
1563            string = string.substring(1);
1564        }
1565
1566        while (string.charAt(string.length - 1) == charToRemove) {
1567            string = string.substring(0, string.length - 1);
1568        }
1569
1570        return string;
1571    }
1572
1573
1574    /**
1575     *
1576     * To get channel URL
1577     * Added On: 10/01/2021
1578     * Added By: Chirag Thummar
1579     *
1580     * */
1581    function getChannelURL(channel, channelIcon, toolTipPosition, widgetId) {
1582        var extraClass = "";
1583        if (isTrue(channel.is_agent)) {
1584            channel.url = "javascript:;";
1585            channel.target = "";
1586        } else {
1587            if (channel.channel_type == "Whatsapp") {
1588                if (isTrue(channel.has_welcome_message) && !isEmpty(channel.chat_welcome_message)) {
1589                    channel.url = "javascript:;";
1590                    channel.target = "";
1591                    extraClass += " has-chaty-box chaty-whatsapp-form";
1592                    startMakingWhatsAppPopup(channel, widgetId);
1593                } else {
1594                    var preSetMessage = "";
1595                    if (!isEmpty(channel.pre_set_message)) {
1596                        preSetMessage = decodeURI(channel.pre_set_message);
1597                        var pageTitle = $("title").text();
1598                        if (!isEmpty(pageTitle)) {
1599                            preSetMessage = preSetMessage.replace(/{title}/g, pageTitle);
1600                        } else {
1601                            preSetMessage = preSetMessage.replace(/{title}/g, '');
1602                        }
1603                        preSetMessage = preSetMessage.replace(/{url}/g, window.location);
1604                        preSetMessage = encodeURIComponent(preSetMessage);
1605                    }
1606                    if (isChatyInMobile) {
1607                        channel.target = "";
1608                        channel.url = channel.value;
1609                    } else {
1610                        channel.target = "_blank";
1611                        if (!isTrue(channel.is_use_web_version)) {
1612                            channel.url = channel.value;
1613                        } else {
1614                            channel.url = channel.value;
1615                        }
1616                    }
1617                }
1618            } else if (channel.channel_type == "WeChat") {
1619                if (!isEmpty(channel.qr_code_image_url)) {
1620                    startMakingWeChatChannel(channel, widgetId);
1621                    channel.url = "javascript:;";
1622                    channel.target = "";
1623                    extraClass += " has-chaty-box chaty-qr-code-form";
1624                }
1625            } else if (channel.channel_type == "Contact_Us") {
1626                startMakingContactForm(channel, widgetId);
1627                channel.url = "javascript:;";
1628                channel.target = "";
1629                extraClass += " has-chaty-box chaty-contact-us-form";
1630            } else if (channel.channel_type == "Email") {
1631                if (!isEmpty(channel.mail_subject)) {
1632                    var mailSubject = decodeURI(channel.mail_subject);
1633                    var pageTitle = $("title").text();
1634                    if (!isEmpty(pageTitle)) {
1635                        mailSubject = mailSubject.replace(/{title}/g, pageTitle);
1636                    } else {
1637                        mailSubject = mailSubject.replace(/{title}/g, '');
1638                    }
1639                    mailSubject = mailSubject.replace(/{url}/g, window.location);
1640                    mailSubject = encodeURIComponent(mailSubject);
1641                    channel.url += "?subject=" + mailSubject;
1642                }
1643            } else if (channel.channel_type == "Viber") {
1644                channel.value = trimChar(channel.value, "+");
1645                if (isChatyInMobile && !isNaN(channel.value)) {
1646                    // channel.value = channel.value.replace("+", "");
1647                    if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
1648                        channel.value = "+" + channel.value;
1649                    }
1650                }
1651                channel.url = "viber://chat?number=" + channel.value;
1652                channel.target = "";
1653            } else if (channel.channel_type == "Vkontakte") {
1654                channel.url = "https://vk.me/" + $.trim(channel.value);
1655            }
1656        }
1657        if(channel.channel == "Link" || channel.channel == "Custom_Link" || channel.channel == "Custom_Link_3" || channel.channel == "Custom_Link_4" || channel.channel == "Custom_Link_5") {
1658            if(!isEmpty(channel.hover_text)) {
1659                ariaLabel = channel.hover_text;
1660            } else {
1661                ariaLabel = channel.channell
1662            }
1663        }else {
1664            ariaLabel = channel.channel;
1665        }
1666
1667        var onClickFn = "";
1668        if (!isEmpty(channel.click_event)) {
1669            onClickFn = 'onclick="' + channel.click_event + '"';
1670            channel.target = "";
1671            channel.url = "javascript:;";
1672        }
1673        return "<a href='" + channel.url + "' " + onClickFn + " target='" + channel.target + "' rel='nofollow noopener' aria-label='" + ariaLabel + "' class='chaty-tooltip chaty-"+(channel.channel_type).toLowerCase()+"-channel pos-" + toolTipPosition + extraClass + "' data-form='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-hover='" + channel.hover_text + "'>" + channelIcon + "</a>";
1674    }
1675
1676    function startMakingContactForm(channel, widgetId) {
1677        var formHtml = "";
1678        var widgetIndex = getWidgetIndex(widgetId);
1679        if (widgetIndex == null) {
1680            widgetIndex = -1;
1681        }
1682        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 + "'>";
1683        formHtml += "<div class='chaty-form'>";
1684        formHtml += "<div class='chaty-form-body'>";
1685        formHtml += "<div role='button' class='close-chaty-form'><div class='chaty-close-button'></div></div>";
1686        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 + "'>";
1687        formHtml += "<div class='chaty-contact-form-body'>";
1688        formHtml += "<div class='chaty-contact-form-title'>" + channel.contact_form_settings.contact_form_title + "</div>";
1689        formHtml += "<div class='chaty-contact-inputs'>";
1690        $.each(channel.contact_fields, function (key, contactField) {
1691            formHtml += "<div class='chaty-contact-input'>";
1692            var isRequired = isTrue(contactField.is_required) ? "is-required" : "";
1693            if (contactField.type == "textarea") {
1694                if(!isEmpty(contactField.title)) {
1695                    formHtml += "<label class='chaty-form-label' for='" + contactField.field + "-" + widgetId + "'>"+contactField.title+"</label>";
1696                } else {
1697                    formHtml += "<label class='sr-only' for='" + contactField.field + "-" + widgetId + "'>"+contactField.field+"</label>";
1698                }
1699                formHtml += "<textarea type='" + contactField.type + "' class='chaty-textarea-field " + isRequired + " field-" + contactField.field + "' placeholder='" + contactField.placeholder + "' name='" + contactField.field + "' id='" + contactField.field + "-" + widgetId + "' ></textarea>"
1700            } else {
1701                if(!isEmpty(contactField.title)) {
1702                    formHtml += "<label class='chaty-form-label' for='" + contactField.field + "-" + widgetId + "'>"+contactField.title+"</label>";
1703                } else {
1704                    formHtml += "<label class='sr-only' for='" + contactField.field + "-" + widgetId + "'>"+contactField.field+"</label>";
1705                }
1706                formHtml += "<input type='" + contactField.type + "' class='chaty-input-field " + isRequired + " field-" + contactField.field + "' placeholder='" + contactField.placeholder + "' name='" + contactField.field + "' id='" + contactField.field + "-" + widgetId + "' />"
1707            }
1708            formHtml += "</div>";
1709        });
1710        if(isTrue(channel.enable_recaptcha)) {
1711            if (!isEmpty(channel.v2_site_key)) {
1712                formHtml += "<div class='chaty-contact-input'>";
1713                formHtml += "<div class='front-google-captcha' id='front_recaptcha_" + widgetIndex + "'></div>";
1714                formHtml += "</div>";
1715            }
1716            if (!isEmpty(channel.v3_site_key)) {
1717                formHtml += "<div class='chaty-contact-input'>";
1718                formHtml += "<div class='front-google-captcha' id='front_recaptcha_" + widgetIndex + "'></div>";
1719                formHtml += "</div>";
1720            }
1721        }
1722        formHtml += "</div>"; // chaty-contact-inputs
1723        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>";
1724        formHtml += "</div>"; // chaty-contact-form-body
1725        if(isTrue(channel.enable_recaptcha)) {
1726            if (!isEmpty(channel.v2_site_key)) {
1727                formHtml += "<input type='hidden' id='v2_site_key' class='v2_site_key' value='" + channel.v2_site_key + "'>";
1728            }
1729            if (!isEmpty(channel.v3_site_key)) {
1730                formHtml += "<input type='hidden' id='v3_site_key' class='v3_site_key' value='" + channel.v3_site_key + "'>";
1731            }
1732        }
1733        formHtml += "</form>";
1734        formHtml += "</div>";
1735        formHtml += "</div>";
1736        formHtml += "</div>";
1737        $("body").append(formHtml);
1738    }
1739
1740    /**
1741     *
1742     * to make WhatsApp popup form
1743     * Added On: 11/01/2021
1744     * Added By: Chirag Thummar
1745     *
1746     * */
1747    function startMakingWhatsAppPopup(channel, widgetId) {
1748        var formHtml = "";
1749        var widgetIndex = getWidgetIndex(widgetId);
1750        if (widgetIndex == null) {
1751            widgetIndex = -1;
1752        }
1753        var formAction = "";
1754        var formTarget = "";
1755        if (!isChatyInMobile) {
1756            if (isTrue(channel.is_use_web_version)) {
1757                formAction = "";
1758            } else {
1759                formAction = channel.value;
1760            }
1761            formTarget = "_blank";
1762        } else {
1763            formAction = channel.value;
1764        }
1765        formHtml += "<div style='display:none;' class='chaty-outer-forms chaty-whatsapp-form chaty-form-" + widgetId + "' data-channel='" + channel.channel_type + "' id='chaty-form-" + widgetId + "-" + channel.channel_type + "' data-widget='" + widgetId + "' data-index='" + widgetIndex + "'>";
1766        formHtml += "<div class='chaty-whatsapp-form'>";
1767        formHtml += "<div class='chaty-whatsapp-body'>";
1768        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>";
1769        formHtml += "<div class='chaty-whatsapp-content'>";
1770        formHtml += "<div class='chaty-whatsapp-message'></div>";
1771        formHtml += "</div>";
1772        formHtml += "</div>";
1773        formHtml += "<div class='chaty-whatsapp-footer'>";
1774        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 + "'>";
1775        formHtml += "<div class='chaty-whatsapp-data'>";
1776        formHtml += "<div class='chaty-whatsapp-field'>";
1777        formHtml += "<label for='csass-whatsapp-label-"+widgetId+"' class='hide-cht-svg-bg' >"+chaty_settings.lang.whatsapp_label+"</label>";
1778        formHtml += "<input name='text' type='text' class='csass-whatsapp-input' id='csass-whatsapp-label-"+widgetId+"' />";
1779        formHtml += "</div>";
1780        formHtml += "<div class='chaty-whatsapp-button'>";
1781        formHtml += "<button type='submit' >";
1782        formHtml += "<span class='hide-cht-svg-bg'>"+chaty_settings.lang.whatsapp_button+"</span>";
1783        formHtml += "<svg aria-hidden='true' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'><path fill='#ffffff' d='M1.101 21.757L23.8 12.028 1.101 2.3l.011 7.912 13.623 1.816-13.623 1.817-.011 7.912z'></path></svg>";
1784        formHtml += "</button>";
1785        formHtml += "</div>";
1786        formHtml += "</div>";
1787        if (!isChatyInMobile && isTrue(channel.is_use_web_version)) {
1788            formHtml += "<input type='hidden' name='phone' value='" + channel.value + "' />";
1789        }
1790        formHtml += "</form>";
1791        formHtml += "</div>";
1792        formHtml += "</div>";
1793        formHtml += "</div>";
1794        $("body").append(formHtml);
1795        $("#chaty-form-" + widgetId + "-" + channel.channel_type + " .chaty-whatsapp-message").html(channel.chat_welcome_message);
1796        if (!isEmpty(channel.pre_set_message)) {
1797            var preSetMessage = channel.pre_set_message;
1798            var pageTitle = $("title").text();
1799            if (!isEmpty(pageTitle)) {
1800                preSetMessage = preSetMessage.replace(/{title}/g, pageTitle);
1801            } else {
1802                preSetMessage = preSetMessage.replace(/{title}/g, '');
1803            }
1804            preSetMessage = preSetMessage.replace(/{url}/g, window.location);
1805            $("#chaty-form-" + widgetId + "-" + channel.channel_type + " .csass-whatsapp-input").val(preSetMessage);
1806        }
1807        $("#chaty-form-" + widgetId + "-" + channel.channel_type).show();
1808    }
1809
1810    /**
1811     *
1812     * To decode HTML Tag
1813     * Added On: 07/17/2022
1814     * Added By: Chirag Thummar
1815     *
1816     * */
1817
1818    function htmlDecode(input) {
1819        var doc = new DOMParser().parseFromString(input, "text/html");
1820        return doc.documentElement.textContent;
1821    }
1822
1823    /**
1824     *
1825     * To get widget index
1826     * Added On: 11/01/2021
1827     * Added By: Chirag Thummar
1828     *
1829     * */
1830    function getWidgetIndex(widgetId) {
1831        var widgetIndex = null;
1832        if (widgetData.length) {
1833            $.each(widgetData, function (key, widgetRecord) {
1834                if (widgetRecord.id == widgetId) {
1835                    widgetIndex = key;
1836                }
1837            });
1838        }
1839        return widgetIndex;
1840    }
1841
1842    /**
1843     *
1844     * to make WhatsApp popup form
1845     * Added On: 11/02/2021
1846     * Added By: Chirag Thummar
1847     *
1848     * */
1849    function startMakingWeChatChannel(channel, widgetId) {
1850        var formHtml = "";
1851        var widgetIndex = getWidgetIndex(widgetId);
1852        if (widgetIndex == null) {
1853            widgetIndex = -1;
1854        }
1855        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 + "'>";
1856        formHtml += "<div class='chaty-form'>";
1857        formHtml += "<div class='chaty-form-body'>";
1858        formHtml += "<div role='button' class='close-chaty-form is-whatsapp-btn'><div class='chaty-close-button'></div></div>";
1859        formHtml += "<div class='qr-code-image'><img src='" + channel.qr_code_image_url + "' alt='" + channel.title + "' /></div>";
1860        formHtml += "</div>";
1861        formHtml += "</div>";
1862        formHtml += "</div>";
1863        $("body").append(formHtml);
1864    }
1865
1866    /**
1867     *
1868     * get tooltip position for channel
1869     * Added On: 09/29/2021
1870     * Added By: Chirag Thummar
1871     *
1872     * */
1873    function isEmpty(varVal) {
1874        if (varVal == null || varVal == "" || $.trim(varVal) == "") {
1875            return true
1876        }
1877        return false;
1878    }
1879
1880    /**
1881     *
1882     * To get channel icon
1883     * Added On: 10/01/2021
1884     * Added By: Chirag Thummar
1885     *
1886     * */
1887    function getChannelIcon(channel) {
1888        if (channel.custom_image_url != "" && channel.custom_image_url != "null") {
1889            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>";
1890        }
1891        return "<span class='chaty-icon channel-icon-" + channel.channel_type + "'><span class='chaty-svg'>" + channel.svg_icon + "</span></span>";
1892    }
1893
1894    /**
1895     *
1896     * check for empty or null items
1897     * Added On: 10/01/2021
1898     * Added By: Chirag Thummar
1899     *
1900     * */
1901    function isValueEmpty(value) {
1902        if (value == "" || $.trim(value) == "" || value == null || value == "null") {
1903            return true;
1904        }
1905        return false;
1906    }
1907
1908    /**
1909     *
1910     * To get widget position
1911     * Added On: 10/01/2021
1912     * Added By: Chirag Thummar
1913     *
1914     * */
1915    function getWidgetPosition(widgetRecord) {
1916        if (widgetRecord.position == "custom") {
1917            return widgetRecord.custom_position;
1918        }
1919        return widgetRecord.position;
1920    }
1921
1922    /**
1923     *
1924     * get tooltip position for channel
1925     * Added On: 09/29/2021
1926     * Added By: Chirag Thummar
1927     *
1928     * */
1929    function getToolTipPosition(widgetRecord) {
1930        if (widgetRecord.settings.icon_view != "vertical") {
1931            return "top";
1932        }
1933        var toolTipPosition = getWidgetPosition(widgetRecord.settings);
1934        if (toolTipPosition == "right") {
1935            return "left";
1936        }
1937        return "right";
1938    }
1939
1940    /**
1941     *
1942     * Check for Triggers if exists
1943     * Added On: 10/04/2021
1944     * Added By: Chirag Thummar
1945     *
1946     * */
1947
1948    function checkForchatyTriggers() {
1949        if ($(".chaty.auto-hide-chaty").length) {
1950            chatyHideTimeInterval = setInterval(function () {
1951                chatyHideIntervalTime++;
1952                var currentTime = chatyHideIntervalTime;
1953                if ($(".chaty.auto-hide-chaty.hide-after-" + chatyHideIntervalTime).length) {
1954                    var widgetId = $(".chaty.auto-hide-chaty.hide-after-" + currentTime).data("id");
1955                    $(".chaty-form-" + widgetId).removeClass("active");
1956                    $(".chaty.auto-hide-chaty.hide-after-" + currentTime).removeClass("active");
1957                    $("#chaty-widget-0" + widgetId).removeClass("auto-hide-chaty");
1958                }
1959                if ($(".chaty.auto-hide-chaty").length == 0) {
1960                    clearInterval(chatyHideTimeInterval);
1961                }
1962            }, 1000);
1963        }
1964        if (chatyHasTimeDelay) {
1965            chatyTimeInterval = setInterval(function () {
1966                chatyIntervalTime++;
1967                if ($(".chaty.delay-time-" + chatyIntervalTime).length) {
1968                    //$(".chaty.delay-time-"+chatyIntervalTime).addClass("active");
1969                    var widgetId = $(".chaty.delay-time-" + chatyIntervalTime).data("id");
1970                    removeTriggerRules(widgetId);
1971                }
1972            }, 1000);
1973        }
1974
1975        if (chatyHasPageScroll) {
1976            $(window).on("scroll", function () {
1977                if (chatyHasPageScroll) {
1978                    var scrollHeight = $(document).height() - $(window).height();
1979                    var scrollPos = $(window).scrollTop();
1980                    if (scrollHeight != 0) {
1981                        var scrollPer = parseInt((scrollPos / scrollHeight) * 100);
1982                        if (lastScrollPer <= scrollPer) {
1983                            var startFrom = lastScrollPer;
1984                            lastScrollPer = scrollPer;
1985                            for (var i = startFrom; i <= scrollPer; i++) {
1986                                if ($.inArray(i, chatyPageScrolls) == -1) {
1987                                    if ($(".chaty.on-chaty-scroll.page-scroll-" + i).length) {
1988                                        $(".chaty.on-chaty-scroll.page-scroll-" + i).each(function () {
1989                                            //$(this).addClass("active");
1990                                            var widgetId = $(this).data("id");
1991                                            $(this).removeClass("on-chaty-scroll");
1992                                            removeTriggerRules(widgetId);
1993                                        });
1994                                    }
1995                                }
1996                            }
1997                            lastScrollPer = scrollPer;
1998                        }
1999                    }
2000                }
2001            });
2002            var hasScrollbar = window.innerWidth > document.documentElement.clientWidth;
2003            if (!hasScrollbar) {
2004                /*$(".chaty.on-chaty-scroll:not(.on-chaty-delay):not(.on-chaty-exit-intent)").each(function(){
2005                    $(this).addClass("active");
2006                    var widgetId = $(this).data("id");
2007                    removeTriggerRules(widgetId);
2008                });*/
2009            }
2010        }
2011
2012        //if(chatyHasExitIntent) {
2013
2014        //}
2015    }
2016
2017
2018
2019    function close_chaty() {
2020        if (jQuery(".chaty.active .chaty-open").length) {
2021            jQuery(".chaty.active .chaty-open").each(function () {
2022                jQuery(this).find(".chaty-cta-close").trigger("click");
2023            })
2024        }
2025    }
2026
2027    /**
2028     *
2029     * To load google Captcha V2 & V3
2030     * Added On: 10/02/2023
2031     * Added By: Chirag Thummar
2032     *
2033     * */
2034    function LoadChatyGoogleRecaptcha() {
2035        if(jQuery(".v2_site_key").length && jQuery(".v2_site_key").val() != "") {
2036            var dsq = document.createElement('script');
2037            dsq.type = 'text/javascript';
2038            dsq.async = true;
2039            dsq.src = 'https://www.google.com/recaptcha/api.js?onload=onloadChatyCallback&render=explicit&hl=en';
2040            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
2041        }
2042        if(jQuery(".v3_site_key").length && jQuery(".v3_site_key").val() != "") {
2043            if (jQuery(".v3_site_key").length && jQuery(".v3_site_key").val() != "" && jQuery(".front-google-captcha").length) {
2044                jQuery(".front-google-captcha:not(.loaded)").each(function () {
2045                    jQuery(this).addClass("loaded");
2046                    var siteKey = jQuery(".v3_site_key").val();
2047                    var dsq = document.createElement('script');
2048                    dsq.type = 'text/javascript';
2049                    dsq.async = true;
2050                    dsq.src = 'https://www.google.com/recaptcha/api.js?onload=onloadCallbackChatyV3&render=' + siteKey;
2051                    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
2052                    dsq.loadEventEnd = function() {
2053
2054                    }
2055                })
2056            }
2057        }
2058    }
2059
2060    /**
2061     *
2062     * Display widgets on Exit intent
2063     * Added On: 10/04/2021
2064     * Added By: Chirag Thummar
2065     *
2066     * */
2067
2068    function mobileExitIntent() {
2069        if (window.history && window.history.pushState && chatyHasExitIntent) {
2070            function whenGoingBack() {
2071                if(chatyHasExitIntent) {
2072                    var hashLocation = location.hash;
2073                    var hashSplit = hashLocation.split("#!/");
2074                    var hashName = hashSplit[1];
2075                    if (hashName !== '') {
2076                        var hash = window.location.hash;
2077                        if (hash === '') {
2078                            showWidgetsOnExitIntent();
2079                        }
2080                    }
2081                }
2082            }
2083
2084            var pageState = 100;
2085            if (window.history.state && window.history.state.page) {
2086                pageState = window.history.state.page;
2087            }
2088            window.history.pushState({page: pageState + 1}, '');
2089            window.history.pushState({page: pageState + 2}, '');
2090
2091            window.onpopstate = function () {
2092                whenGoingBack();
2093            };
2094            window.history.onpopstate = function () {
2095                whenGoingBack();
2096            };
2097            window.addEventListener('popstate', function () {
2098                whenGoingBack();
2099            });
2100            document.addEventListener('backbutton', function () {
2101                whenGoingBack();
2102            });
2103            window.addEventListener('backbutton', function () {
2104                whenGoingBack();
2105            });
2106            $(window).on('popstate', function () {
2107                whenGoingBack();
2108            });
2109        }
2110    }
2111
2112    /**
2113     *
2114     * Display widgets on Exit intent
2115     * Added On: 10/04/2021
2116     * Added By: Chirag Thummar
2117     *
2118     * */
2119
2120    function bindExitIntentFunction() {
2121        if (isChatyInMobile) {
2122            // Back button was pressed.
2123            mobileExitIntent();
2124        } else {
2125            $(document).mouseleave(function (e) {
2126                function addEvent(obj, evt, fn) {
2127                    if (obj.addEventListener) {
2128                        obj.addEventListener(evt, fn, false);
2129                        showWidgetsOnExitIntent();
2130                    } else if (obj.attachEvent) {
2131                        obj.attachEvent("on" + evt, fn);
2132                    }
2133                }
2134
2135                addEvent(document, 'mouseout', function (evt) {
2136                    if (evt.toElement == null && evt.relatedTarget == null) {
2137                        showWidgetsOnExitIntent();
2138                    }
2139                });
2140            });
2141        }
2142    }
2143
2144    /**
2145     *
2146     * Display widgets on Exit intent
2147     * Added On: 10/04/2021
2148     * Added By: Chirag Thummar
2149     *
2150     * */
2151
2152    function showWidgetsOnExitIntent() {
2153        if (chatyHasExitIntent && $(".on-chaty-exit-intent").length) {
2154            $(".on-chaty-exit-intent").each(function () {
2155                //$(this).addClass("active");
2156                var widgetId = $(this).data("id");
2157                $(this).removeClass("on-chaty-exit-intent");
2158                removeTriggerRules(widgetId);
2159                $("#chaty-widget-" + widgetId + " .chaty-widget").append("<div class='chaty-exit-intent'></div>");
2160                setTimeout(function () {
2161                    $(".chaty-exit-intent").addClass("animate");
2162                    setTimeout(function () {
2163                        $(".chaty-exit-intent").removeClass("animate");
2164                    }, 2500);
2165                }, 500);
2166            });
2167        }
2168    }
2169
2170    /**
2171     *
2172     * Remove Trigger Rules if all rules executed
2173     * Added On: 10/04/2021
2174     * Added By: Chirag Thummar
2175     *
2176     * */
2177    function removeTriggerRules(widgetId) {
2178
2179        updateWidgetViews(widgetId);
2180
2181        $(".chaty-widget-" + widgetId).removeClass("on-chaty-delay");
2182        $(".chaty-widget-" + widgetId).removeClass("on-chaty-exit-intent");
2183        $(".chaty-widget-" + widgetId).removeClass("on-chaty-scroll");
2184
2185        if (!$(".chaty.on-chaty-delay").length) {
2186            clearInterval(chatyTimeInterval);
2187            chatyHasTimeDelay = false;
2188        }
2189        if (!$(".chaty.on-chaty-exit-intent").length) {
2190            chatyHasExitIntent = false;
2191        }
2192        if (!$(".chaty.on-chaty-scroll").length) {
2193            chatyHasPageScroll = false;
2194        }
2195    }
2196
2197    /**
2198     *
2199     * Remove Empty On hover class when text is empty
2200     * Added On: 10/04/2021
2201     * Added By: Chirag Thummar
2202     *
2203     * */
2204    function removeEmptyTooltip() {
2205        $(".chaty-tooltip").each(function () {
2206            if ($(this).data("hover") == "") {
2207                $(this).removeClass("left").removeClass("right").removeClass("top").removeClass("chaty-tooltip");
2208            }
2209        })
2210    }
2211
2212    /**
2213     *
2214     * Set widget icon
2215     * Added On: 10/04/2021
2216     * Added By: Chirag Thummar
2217     *
2218     * */
2219    function getWidgetIcon(widgetRecord, widgetId) {
2220        /* set default icon if icon is blank */
2221        if (widgetRecord.widget_icon == "") {
2222            widgetRecord.widget_icon = "chat-base";
2223        } else if (widgetRecord.widget_icon == "chat-image" && isEmpty(widgetRecord.widget_icon_url)) {
2224            /* if custom icon is selected than check for image URL, if not exists then update icon with default icon */
2225            widgetRecord.widget_icon = "chat-base";
2226        } else if (widgetRecord.widget_icon == "chat-fa-icon" && isEmpty(widgetRecord.widget_fa_icon)) {
2227            widgetRecord.widget_icon = "chat-base";
2228        }
2229
2230        if (widgetRecord.widget_icon == "chat-image") {
2231            return "<span class='chaty-svg' style='background-color: " + widgetRecord.widget_color + "'><img src='" + widgetRecord.widget_icon_url + "' alt='Chaty Widget' /></span>";
2232        } else if(widgetRecord.widget_icon == "chat-fa-icon") {
2233            return "<span class='chaty-svg' style='background-color: " + widgetRecord.widget_color + "'><i class='" + widgetRecord.widget_fa_icon + " widget-fa-icon' style='color: "+ "#ffffff" +"'></i></span>";
2234        } else {
2235            return '<span class="chaty-svg">' + getSvgIcon(widgetRecord.widget_icon, widgetRecord.widget_color, "#ffffff", widgetId) + "</span>";
2236        }
2237    }
2238
2239    /**
2240     *
2241     * check for widget animations if applicable
2242     * Added On: 10/04/2021
2243     * Added By: Chirag Thummar
2244     *
2245     * */
2246    function checkForWidgetAnimation(widgetRecord, widgetId) {
2247        var clickStatus = checkChatyCookieExpired(widgetId, 'c-widget');
2248        if (clickStatus && widgetRecord.attention_effect != "none" && widgetRecord.attention_effect != "") {
2249            $("#chaty-widget-" + widgetId).attr("data-animation", widgetRecord.attention_effect);
2250            if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("has-single")) {
2251                $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-channel .chaty-svg").addClass("chaty-animation-" + widgetRecord.attention_effect);
2252            } else {
2253                $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-cta-main .chaty-cta-button").addClass("chaty-animation-" + widgetRecord.attention_effect);
2254            }
2255        }
2256    }
2257
2258    /**
2259     *
2260     * check for pending message if all criteria matches to display it
2261     * Added On: 10/04/2021
2262     * Added By: Chirag Thummar
2263     *
2264     * */
2265    function checkForPendingMessage(widgetRecord, widgetId) {
2266        var clickStatus = checkChatyCookieExpired(widgetId, 'c-widget');
2267
2268        if (clickStatus && isTrue(widgetRecord.is_pending_mesg_enabled) && parseInt(widgetRecord.pending_mesg_count) > 0) {
2269            if ($("#chaty-widget-" + widgetId + " .chaty-widget").hasClass("has-single")) {
2270                if (widgetRecord.attention_effect == "sheen" || widgetRecord.attention_effect == "spin" || widgetRecord.attention_effect == "pulse") {
2271                    $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-channel").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>");
2272                } else {
2273                    $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-channel .chaty-svg").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>");
2274                }
2275            } else {
2276                if (widgetRecord.attention_effect == "jump" || widgetRecord.attention_effect == "waggle" || widgetRecord.attention_effect == "blink" || widgetRecord.attention_effect == "pulse-icon") {
2277                    $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-cta-main .chaty-cta-button").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>");
2278                } else {
2279                    $("#chaty-widget-" + widgetId + " .chaty-i-trigger .chaty-cta-main").append("<span class='ch-pending-msg'>" + widgetRecord.pending_mesg_count + "</span>");
2280                }
2281            }
2282        }
2283    }
2284
2285    /**
2286     *
2287     * Add Prefix 0 to Number
2288     * Added On: 10/21/2021
2289     * Added By: Chirag Thummar
2290     *
2291     * */
2292
2293    function addPrefixToNum(num) {
2294        num = num.toString();
2295        while (num.length < 2) num = "0" + num;
2296        return num;
2297    }
2298
2299    /**
2300     *
2301     * Check for time Schedule
2302     * Added On: 10/21/2021
2303     * Added By: Chirag Thummar
2304     *
2305     * */
2306    function checkForDayAndTimeSchedule(widgetRecord) {
2307        var displayStatus = true;
2308
2309        return displayStatus;
2310    }
2311
2312    /**
2313     *
2314     * get tooltip position for channel
2315     * Added On: 09/29/2021
2316     * Added By: Chirag Thummar
2317     *
2318     * */
2319    function isTrue(varVal) {
2320        if (varVal == "1" || varVal == 1 || varVal == true || varVal == "true" || varVal == "yes" || varVal == "on") {
2321            return true
2322        }
2323        return false;
2324    }
2325
2326    /**
2327     *
2328     * To get time diffrence between dates
2329     * Added On: 04/18/2022
2330     * Added By: Chirag Thummar
2331     *
2332     * */
2333
2334    function changeTimezone(date, ianatz) {
2335        if (isNaN(ianatz)) {
2336            var invdate = new Date(date.toLocaleString('en-US', {
2337                timeZone: ianatz
2338            }));
2339            var diff = date.getTime() - invdate.getTime();
2340            return new Date(date.getTime() - diff); // needs to substract
2341        } else {
2342            var newDate = new Date();
2343            newDate = newDate.toLocaleString('en-US', {timeZone: 'UTC'});
2344            newDate = new Date(newDate);
2345            if (ianatz.indexOf("+") != -1) {
2346                var newTimeZone = ianatz.replace("+", "");
2347                var extraHours = parseInt(newTimeZone);
2348                var extraMin = parseFloat(newTimeZone % extraHours) * 60;
2349                extraMin = newDate.getUTCMinutes() + extraMin;
2350                if (extraMin > 59) {
2351                    extraHours = extraHours + parseInt(extraMin / 60);
2352                    extraMin = extraMin % 60;
2353                }
2354                newDate.setUTCHours(newDate.getUTCHours() + extraHours, extraMin);
2355            } else if (ianatz.indexOf("-") != -1) {
2356                var newTimeZone = ianatz.replace("-", "");
2357                var extraHours = parseInt(newTimeZone);
2358                var extraMin = parseFloat(newTimeZone % extraHours) * 60;
2359                extraMin = newDate.getUTCMinutes() - extraMin;
2360                if (extraMin < 0) {
2361                    extraHours = extraHours - parseInt(extraMin / 60);
2362                    extraMin = extraMin % 60;
2363                }
2364                newDate.setUTCHours(newDate.getUTCHours() - extraHours, -extraMin);
2365            }
2366            var diff = date.getTime() - newDate.getTime();
2367            return new Date(date.getTime() - diff); // needs to substract
2368        }
2369    }
2370
2371    /**
2372     *
2373     * Check for time Schedule
2374     * Added On: 10/21/2021
2375     * Added By: Chirag Thummar
2376     *
2377     * */
2378
2379    function checkForTimeSchedule(widgetRecord) {
2380        return true;
2381    }
2382
2383    /**
2384     *
2385     * Check for visitos's country
2386     * Added On: 10/21/2021
2387     * Added By: Chirag Thummar
2388     *
2389     * */
2390    function checkForUserCountry(widgetRecord) {
2391        return true;
2392    }
2393
2394    /**
2395     *
2396     * To get user id from cookie or storage
2397     * Added On: 09/28/2021
2398     * Added By: Chirag Thummar
2399     *
2400     * */
2401    function getUserCountry() {
2402        clientCountry = "";
2403        if (typeof Storage !== "undefined" && window.sessionStorage.getItem("chaty_user_country_code") != null) {
2404            clientCountry = window.sessionStorage.getItem("chaty_user_country_code");
2405        } else {
2406            if (chatyCheckCookie('chaty_user_country_code')) {
2407                clientCountry = chatyGetCookie('chaty_user_country_code');
2408            }
2409        }
2410        return clientCountry;
2411    }
2412
2413    /**
2414     *
2415     * To save user id in cookie, will be created different for users and by browsers
2416     * Added On: 09/28/2021
2417     * Added By: Chirag Thummar
2418     *
2419     * */
2420    function setUserCountry(userCountry) {
2421        if (typeof Storage !== "undefined") {
2422            if (window.sessionStorage.getItem("chaty_user_country_code") == null) {
2423                window.sessionStorage.setItem("chaty_user_country_code", userCountry);
2424            }
2425        } else {
2426            if (!chatyCheckCookie('chaty_user_country_code')) {
2427                chatySetCookie('chaty_user_country_code', userCountry, 365);
2428            }
2429        }
2430    }
2431
2432    /**
2433     *
2434     * To ger widget's setting stored cookie Array
2435     * Added On: 10/01/2021
2436     * Added By: Chirag Thummar
2437     *
2438     * */
2439    function checkForChatyCookieString(widgetId, cookieStr) {
2440        var cookieString = chatyGetCookie("chatyWidget_" + widgetId);
2441        var cookieArray = [];
2442        if (cookieString != null && cookieString != "") {
2443            cookieArray = JSON.parse(cookieString);
2444        }
2445        if (cookieArray.length > 0) {
2446            for (var i = 0; i < cookieArray.length; i++) {
2447                if (cookieArray[i]['k'] == cookieStr) {
2448                    return cookieArray[i]['v'];
2449                }
2450            }
2451        }
2452        return null;
2453    }
2454
2455    /**
2456     *
2457     * To save widget's setting in cookie Array
2458     * Added On: 10/01/2021
2459     * Added By: Chirag Thummar
2460     *
2461     * */
2462    function saveChatyCookieString(widgetId, cookieStr) {
2463        var cookieString = chatyGetCookie("chatyWidget_" + widgetId);
2464        var cookieArray = [];
2465        if (cookieString != null && cookieString != "") {
2466            cookieArray = JSON.parse(cookieString);
2467        }
2468        var cookieFound = false;
2469        if (cookieArray.length > 0) {
2470            for (var i = 0; i < cookieArray.length; i++) {
2471                if (cookieArray[i]['k'] == cookieStr) {
2472                    cookieFound = true;
2473                    cookieArray[i]['v'] = new Date();
2474                }
2475            }
2476        }
2477        if (!cookieFound) {
2478            cookieArray.push({"k": cookieStr, "v": new Date()});
2479        }
2480        cookieString = JSON.stringify(cookieArray);
2481        chatySetCookie("chatyWidget_" + widgetId, cookieString, "7");
2482    }
2483
2484
2485    /**
2486     *
2487     * To check widget's setting cookie status stored in Array
2488     * Added On: 10/01/2021
2489     * Added By: Chirag Thummar
2490     *
2491     * */
2492    function checkChatyCookieExpired(widgetId, cookieStr) {
2493        var cookieValue = checkForChatyCookieString(widgetId, cookieStr);
2494        if (cookieValue != null && cookieValue != "") {
2495            cookieValue = new Date(cookieValue);
2496            var diffTime = Math.abs(new Date() - cookieValue);
2497            var diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
2498            if (diffDays >= 2) {
2499                return true;
2500            } else {
2501                return false;
2502            }
2503        }
2504        return true;
2505    }
2506
2507    /**
2508     *
2509     * To save data in browser cookie
2510     * Added On: 09/28/2021
2511     * Added By: Chirag Thummar
2512     *
2513     * */
2514    function chatySetCookie(cname, cvalue, exdays) {
2515        var d = new Date();
2516        d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
2517        var expires = "expires=" + d.toUTCString();
2518        document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/; SameSite=Lax";
2519    }
2520
2521    /**
2522     *
2523     * To get data from browser cookie using cookie name
2524     * Added On: 09/28/2021
2525     * Added By: Chirag Thummar
2526     *
2527     * */
2528    function chatyGetCookie(cookieName) {
2529        var cookieName = cookieName + "=";
2530        var ca = document.cookie.split(';');
2531        for (var i = 0; i < ca.length; i++) {
2532            var c = ca[i];
2533            while (c.charAt(0) == ' ') {
2534                c = c.substring(1);
2535            }
2536            if (c.indexOf(cookieName) == 0) {
2537                return c.substring(cookieName.length, c.length); // return data if cookie exists
2538            }
2539        }
2540        return null; // return null if cookie doesn't exists
2541    }
2542
2543    /**
2544     *
2545     * To check cookie exists or not in browser
2546     * Added On: 09/28/2021
2547     * Added By: Chirag Thummar
2548     *
2549     * */
2550    function chatyCheckCookie(cookieName) {
2551        var cookie = chatyGetCookie(cookieName);
2552        if (cookie != "" && cookie !== null) {
2553            return true;
2554        } else {
2555            return false;
2556        }
2557    }
2558
2559    /**
2560     *
2561     * To remove cookie from browser
2562     * Added On: 09/28/2021
2563     * Added By: Chirag Thummar
2564     *
2565     * */
2566    function chatyDeleteCookie(cookieName) {
2567        document.cookie = cookieName + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
2568    }
2569
2570    /**
2571     *
2572     * To get current date from Browser
2573     * Added On: 09/28/2021
2574     * Added By: Chirag Thummar
2575     *
2576     * */
2577    function getCurrentDate() {
2578        today = new Date();
2579        dd = today.getDate();
2580        mm = today.getMonth() + 1;
2581        yyyy = today.getFullYear();
2582        if (dd < 10) {
2583            dd = '0' + dd;
2584        }
2585        if (mm < 10) {
2586            mm = '0' + mm;
2587        }
2588        return yyyy + '-' + mm + '-' + dd;
2589    }
2590
2591    /**
2592     *
2593     * Add log message to console
2594     *
2595     * */
2596    function addChatyLog(message) {
2597        if (chatyEnv != "app") {
2598            console.log(message);
2599        }
2600    }
2601}));
2602
2603function launch_chaty(widget_number) {
2604    if (widget_number == undefined || widget_number == "widget_index") {
2605        widget_number = 0;
2606    }
2607    if (jQuery("#chaty-widget-_"+widget_number).length) {
2608        jQuery("#chaty-widget-_"+widget_number+" .chaty-cta-button .open-chaty").trigger("click");
2609    } else if (jQuery("#chaty-widget-"+widget_number).length) {
2610        jQuery("#chaty-widget-"+widget_number+" .chaty-cta-button .open-chaty").trigger("click");
2611    }
2612}
2613
2614var googleV3Token = "";
2615function onloadCallbackChatyV3() {
2616    var siteKey = jQuery(".v3_site_key").val();
2617    if(siteKey && googleV3Token == "") {
2618        grecaptcha.ready(function () {
2619            grecaptcha.execute(siteKey, {action: 'contact_form'}).then(function (token) {
2620                googleV3Token = token;
2621            });
2622        });
2623    }
2624}
2625
2626function refreshG3Token() {
2627    if (typeof grecaptcha === "function" || typeof grecaptcha === "object") {
2628        var siteKey = jQuery(".v3_site_key").val();
2629        if (siteKey && googleV3Token == "") {
2630            grecaptcha.ready(function () {
2631                grecaptcha.execute(siteKey, {action: 'contact_form'}).then(function (token) {
2632                    googleV3Token = token;
2633                });
2634            });
2635        }
2636    }
2637}
2638
2639function onloadChatyCallback() {
2640    if (jQuery(".v2_site_key").length && jQuery(".v2_site_key").val() != "" && jQuery(".front-google-captcha").length) {
2641        jQuery(".front-google-captcha:not(.loaded)").each(function () {
2642            var thisId = jQuery(this).attr("id");
2643            jQuery(this).addClass("loaded");
2644            if (document.getElementById(thisId)) {
2645                grecaptcha.render(thisId, {'sitekey': jQuery(".v2_site_key").val()});
2646            }
2647        })
2648    }
2649
2650}

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.