PageSourceSearch

https://www.studiodentisticoronca.it/wp-content/plugins/wp-live-ch…/js/wplc_u_node_events.js?ver=8.1.7

js studiodentisticoronca.it collected 2026-10-08 20:02:17 UTC 20,977 bytes, 533 lines download raw bytes

1
2/**
3 * Create an object so that we can track if we've displayed 'agent has joined' notices
4 * @type {Object}
5 */
6var agent_joined = {};
7
8jQuery(function() {
9
10    jQuery('body').on('click', '.wplc_custom_dropdown', function(){
11        jQuery(this).removeClass('unselected');
12    });
13
14    jQuery(document).on("wplc_open_chat", function(e) {
15        jQuery("#tcx_chat_ended").html('').hide();
16        nc_status = Cookies.get("nc_status");
17        if (typeof nc_status === "undefined" || nc_status === "browsing") {
18            /* show the part that requests name, email and department, etc */
19            jQuery("#wp-live-chat-2").show();    
20            jQuery("#wp-live-chat-2-inner").show();         
21            var wplc_visitor_name = Cookies.get('wplc_name');           
22            if(Cookies.get('wplc_email') !== "no email set" && typeof wplc_visitor_name !== "undefined"){
23                jQuery("#wplc_name").val(Cookies.get('wplc_name'));
24                jQuery("#wplc_email").val(Cookies.get('wplc_email'));
25            }
26            jQuery("#wp-live-chat-header").addClass("active");
27        } else if (nc_status === "active") {
28            /* go straight into chat */
29            Cookies.set('wplc_minimize', "", { expires: 1, path: '/' });
30            jQuery.event.trigger({type: "wplc_open_chat_2", wplc_online: wplc_online});
31            
32
33        }
34        
35    });
36
37    //Chat Notification
38    jQuery(document).on("tcx_user_chat_notification", function(e){
39      if(typeof e.ndata !== "undefined"){
40        if(typeof e.ndata.chatid !== "undefined" && typeof e.ndata.notification_text !== "undefined"){
41          if(e.ndata.chatid === wplc_cid){
42            the_message = {};
43            the_message.msg = e.ndata.notification_text;
44            the_message.originates = 0;
45            the_message.other = {};
46            wplc_push_message_to_chatbox(the_message, "u", function(){
47            });
48          }
49        }
50      }
51    });
52
53    jQuery(document).on("tcx_socket_connected", function(e) {
54        if (e.status === "active") {
55            jQuery.event.trigger({type: "wplc_open_chat_2", wplc_online: wplc_online});      
56        }
57        wplc_clear_system_notification();
58    });
59
60    /**
61     * Handle the disconnect notice
62     * 
63     * @return void
64     */
65    jQuery(document).on("tcx_disconnected", function() {
66        console.log('disconnected');
67        if(typeof wplc_error_messages !== "undefined" && typeof wplc_error_messages['disconnected_message'] !== "undefined"){
68            var the_message = wplc_generate_system_notification_object(wplc_error_messages['disconnected_message'], {}, 0);
69            wplc_display_system_notification(the_message);
70        }
71    });
72
73    jQuery(document).on("nifty_trigger_open_chat_2", function( e ) { 
74      
75      
76
77
78    });    
79
80    /**
81     * Get chat messages from WP storage once the chat box init has been completed.
82     * 
83     */
84    jQuery(document).on("wplc_init_complete", function(e) {
85        if (wplc_online && Cookies.get('tcx_received_msg') === "true" && Cookies.get('nc_status') === "active") {
86            var data = {
87                relay_action: 'wplc_get_messages',
88                security: wplc_nonce,
89                chat_id: wplc_cid,
90                limit:50,
91                offset:0,
92                received_via: 'u',
93                wplc_extra_data:wplc_extra_data
94            };
95            wplc_rest_api('get_messages', data, 12000, function(message_history) {
96                if (typeof message_history !== "undefined" && message_history && typeof message_history.data !== "undefined" && typeof message_history.data.messages !== "undefined" && typeof message_history.data.messages === "object") {
97                    message_history = message_history.data.messages;
98                    for (var key in message_history) {
99                        var the_message = message_history[key];
100                        the_message.mid = key;
101                        wplc_push_message_to_chatbox(the_message,'u', function() {
102                            wplc_scroll_to_bottom();    
103                        });
104                    }
105                }
106            });
107        }
108
109        var wplc_node_status_from_cookie = Cookies.get("nc_status");
110        if(typeof wplc_node_status_from_cookie !== "undefined" &&  wplc_node_status_from_cookie === "active"){
111            if(typeof wplc_cbox_animation !== "undefined"){
112                wplc_cbox_animation();
113            }
114        }
115
116    });
117
118    /**
119     * New message received from socket, add it to the DOM
120     * @return void
121     */
122    jQuery(document).on("tcx_new_message", function(e) {
123        
124        /**
125         * set the tcx_received_msg = true so that we can know when to /get_messages in the future 
126         */
127        Cookies.set('tcx_received_msg', true, { expires: 1, path: '/' });
128
129        if (typeof e.ndata === "object") {
130            if (typeof e.ndata.message === "undefined") { e.ndata.message = ''; }
131            
132            the_message = {};
133            the_message.other = {};
134            
135            if (e.ndata.aoru === 'u') {
136                the_message.originates = 2;
137            } else {
138                the_message.originates = 1;
139                the_message.other.aid = e.ndata.aoru;
140
141            }
142            
143            the_message.msg = e.ndata.message;
144            the_message.mid = e.ndata.msgID;
145            
146            var wplc_d = new Date();
147            the_message.other.datetime = Math.round( wplc_d.getTime() / 1000 );
148            wplc_push_message_to_chatbox(the_message,'u', function() {
149                wplc_scroll_to_bottom();    
150            });
151
152            if (Cookies.get("wplc_minimize") === 'yes' && jQuery("#tcx_bell").length > 0) {
153                jQuery("#tcx_bell").show();
154            }
155        }
156    });
157
158    jQuery(document).on("tcx_send_message", function(e) {
159        var wplc_chat = e.message;
160
161         var data = {
162                relay_action: 'wplc_user_send_msg',
163                security: wplc_nonce,
164                chat_id: wplc_cid,
165                message: wplc_chat,
166                msg_id: e.msg_id,
167                wplc_extra_data:wplc_extra_data
168        };
169
170        if(typeof wplc_chat === "string" && wplc_chat.trim() !== ""){
171            /* 
172             * Will only send message if this is not empty string
173             * This will resolve some issues with rest storage
174            */
175            wplc_rest_api('send_message', data, 12000, null);
176            jQuery("#wplc_chatmsg").val('');
177
178            if (typeof wplc_enable_ga !== "undefined" && wplc_enable_ga === '1') {
179                if (typeof ga !== "undefined") {
180                    ga('send', {
181                      hitType: 'event',
182                      eventCategory: 'WP_Live_Chat_Support',
183                      eventAction: 'Event',
184                      eventLabel: 'User Send Message'
185                    });
186                }
187            }
188        }
189
190        
191
192        jQuery.event.trigger({type: "wplc_update_gdpr_last_chat_id"});
193
194    });
195
196
197    /**
198     * Handle the chat history object returned from the socket
199     * 
200     * @return void
201     */
202    jQuery(document).on("tcx_chat_history", function(e) {
203        if (typeof e.ndata !== "undefined" && e.ndata !== null) {
204            
205        }
206    });
207
208    /**
209     * Handle the agent joined event
210     * 
211     * @return void
212     */
213    jQuery(document).on("tcx_agent_joined", function(e) {
214        if (typeof e.ndata !== "undefined" && typeof e.ndata === "object") {
215            if (typeof agent_joined[parseInt(e.ndata.agent)] === "undefined") {
216                the_message = wplc_generate_system_notification_object(e.ndata.agent_name+tcx_localized_strings[0], {}, 0);
217                wplc_push_message_to_chatbox(the_message,'u', function() {
218                    wplc_scroll_to_bottom();    
219                });
220                agent_joined[parseInt(e.ndata.agent)] = true;
221            }
222
223        }
224    });
225
226    /**
227     * Handle the agent left event
228     * 
229     * @return void
230     */
231    jQuery(document).on("tcx_agent_left", function(e) {
232        if (typeof e.ndata !== "undefined" && typeof e.ndata === "object") {
233            the_message = wplc_generate_system_notification_object(e.ndata.agent_name+tcx_localized_strings[1], {}, 0);
234            if (typeof agent_joined[parseInt(e.ndata.agent)] !== "undefined" && agent_joined[parseInt(e.ndata.agent)] === true) {
235                agent_joined[parseInt(e.ndata.agent)] = undefined;
236                wplc_push_message_to_chatbox(the_message,'u', function() {
237                    wplc_scroll_to_bottom();    
238                });
239            }
240
241            jQuery('#agent_grav_' + parseInt(e.ndata.agent)).remove();
242
243            var wplc_current_agent_names = jQuery(".wplc_agent_name").text();
244
245            var wplc_aid_group = jQuery(".wplc_agent_info").attr("aid");
246            if(wplc_aid_group.indexOf(parseInt(e.ndata.agent)) !== -1){
247                wplc_aid_group = wplc_aid_group.replace(parseInt(e.ndata.agent), '');
248
249                jQuery(".wplc_agent_info").attr("aid", wplc_aid_group);
250            }
251
252            if(wplc_current_agent_names.indexOf(e.ndata.agent_name) !== -1){
253                wplc_current_agent_names = wplc_current_agent_names.replace(', ' + e.ndata.agent_name, '');
254                wplc_current_agent_names = wplc_current_agent_names.replace(e.ndata.agent_name + ', ', '');
255                jQuery(".wplc_agent_name").text(wplc_current_agent_names);
256                jQuery(".wplc_agent_name").attr('title', wplc_current_agent_names);
257            }
258
259
260            if (typeof wplc_enable_ga !== "undefined" && wplc_enable_ga === '1') {
261                if (typeof ga !== "undefined") {
262                    ga('send', {
263                      hitType: 'event',
264                      eventCategory: 'WP_Live_Chat_Support',
265                      eventAction: 'Event',
266                      eventLabel: 'Agent left the chat'
267                    });
268                }
269            }
270
271        }
272    });
273
274
275    jQuery(document).on("tcx_chat_ended_notification", function(e) {
276        if (typeof e.ndata !== "undefined" && typeof e.ndata === "object") {
277            the_message = wplc_generate_system_notification_object(e.ndata.agent_name+tcx_localized_strings[2], {}, 0);
278            wplc_push_message_to_chatbox(the_message,'u', function() {
279                wplc_scroll_to_bottom();    
280            });
281        }
282
283        jQuery("#wplc_user_typing").fadeOut("slow").remove();
284
285        if(typeof wplc_redirect_thank_you !== "undefined" && wplc_redirect_thank_you !== null && wplc_redirect_thank_you !== ""){
286            window.location = wplc_redirect_thank_you;
287        }
288
289        if(jQuery('#wplc_gdpr_end_chat_notice_container').length > 0){
290            jQuery("#wplc_gdpr_end_chat_notice_container").fadeIn('fast');
291        }
292
293        if (typeof wplc_enable_ga !== "undefined" && wplc_enable_ga === '1') {
294            if (typeof ga !== "undefined") {
295                ga('send', {
296                  hitType: 'event',
297                  eventCategory: 'WP_Live_Chat_Support',
298                  eventAction: 'Event',
299                  eventLabel: 'Chat Ended By Agent'
300                });
301            }
302        }
303
304        if (typeof user_heartbeat !== "undefined"){
305          clearInterval(user_heartbeat);
306        }
307        user_heartbeat = undefined;
308        niftyUpdateStatusCookie('browsing');
309        nc_status = 'browsing';
310        nifty_chat_status_temp = 'browsing';
311        nifty_chat_status = 'browsing';
312        // restart connection as a visitor
313        if (typeof io !== "undefined") {
314          socket = io.connect(WPLC_SOCKET_URI, { query : query_string, transports: ['websocket'] } );
315          wplc_chat_delegates();
316        }
317
318    });
319
320    /**
321     * Handle the agent disconnected event
322     * 
323     * @return void
324     */
325    jQuery(document).on("tcx_agent_disconnected", function(e) {
326        /** Disconnects removed as per request */
327        /*the_message = wplc_generate_system_notification_object(e.ndata.agent_name+tcx_localized_strings[3], {}, 0);
328        if (typeof agent_joined[parseInt(e.ndata.aid)] !== "undefined" && agent_joined[parseInt(e.ndata.aid)] === true) {
329            agent_joined[parseInt(e.ndata.aid)] = undefined;
330            wplc_push_message_to_chatbox(the_message,'u', function() {
331                wplc_scroll_to_bottom();    
332            });
333        }*/
334    });
335
336    /**
337     * Custom data trigger
338     *
339     * If custom data is sent through the socket, this is where you would want to handle it
340     *
341     * @return void
342     */
343    jQuery(document).on("tcx_custom_data_received", function(e) {
344        if (typeof e.ndata !== "undefined") {
345            if (typeof e.ndata.action !== "undefined") {
346                if (e.ndata.action === "send_custom_header") {
347
348                    var temail = '';
349                    var tname = '';
350                    var taid = '';
351                    var ta_tagline = '';
352                    if (typeof e.ndata.ndata.email !== "undefined") { temail = e.ndata.ndata.email; }
353                    if (typeof e.ndata.ndata.name !== "undefined") { tname = e.ndata.ndata.name; }
354                    if (typeof e.ndata.ndata.aid !== "undefined") { taid = e.ndata.ndata.aid; }
355                    if (typeof e.ndata.ndata.tagline !== "undefined") { ta_tagline = e.ndata.ndata.tagline; }
356
357                    var data = {
358                        agent_tagline: ta_tagline,
359                        aid: taid,
360                        email: temail,
361                        name: tname
362                    }
363                    
364
365                    jQuery.event.trigger({type: "wplc_agent_joined", ndata:{other:data}}); 
366
367                    if (typeof wplc_enable_ga !== "undefined" && wplc_enable_ga === '1') {
368                        if (typeof ga !== "undefined") {
369                            ga('send', {
370                              hitType: 'event',
371                              eventCategory: 'WP_Live_Chat_Support',
372                              eventAction: 'Event',
373                              eventLabel: 'Agent joined chat'
374                            });
375                        }
376                    }
377                } else if(e.ndata.action === "send_user_direct_to_page") {
378                    if(typeof e.ndata.direction !== "undefined"){
379                        if(typeof e.ndata.pretty_name !== "undefined"){
380                            var notice = "<span> ";
381                            notice += (typeof e.ndata.agent_name !== "undefined" ? e.ndata.agent_name : "Agent") + " "; 
382                            notice += (typeof tcx_direct_to_page_localized_notice !== "undefined" ? tcx_direct_to_page_localized_notice : "would like to direct you to the following page: ");
383                            notice += wplc_safe_html(e.ndata.pretty_name) + " - " + wplc_sanitize_url(e.ndata.direction);
384                            notice += " </span>";
385
386                            the_message = {};
387                            the_message.msg = notice;
388                            the_message.originates = 0;
389                            the_message.decorateurl = true;
390                            the_message.other = {preformatted: true};
391                            wplc_push_message_to_chatbox(the_message, "u", function(){
392                            });
393                        }
394                    }
395                }
396            }
397            
398        }
399
400    });
401
402
403    jQuery(document).on("tcx_init_chat_box", function() {
404        
405        /* find out if we are actively involved in a chat, if yes, then open the chat window, unless the user has minimized it.. */
406        
407        nifty_chat_status_temp = Cookies.get("nc_status");
408        if (typeof nifty_chat_status_temp !== "undefined" && nifty_chat_status_temp === "active" && !nifty_is_minimized) {
409            open_chat(1);
410            jQuery.event.trigger({type: "wplc_open_chat_2", wplc_online: wplc_online});
411        } else {
412            wplc_init_chat_box(false, false);
413        }
414
415        
416    });
417
418    jQuery(document).on("nifty_trigger_start_chat", function(e) {
419        wplc_cookie_name = Cookies.get('wplc_name');
420        wplc_cookie_email = Cookies.get('wplc_email');
421
422        if( typeof wplc_cookie_name == 'undefined' ){ var wplc_cookie_name =  jQuery( "#wp-live-chat" ).find( "#wplc_name" ).val().replace(/(<([^>]+)>)/ig,""); }
423        if( typeof wplc_cookie_email == 'undefined' ){  var wplc_cookie_email =  jQuery( "#wp-live-chat" ).find( "#wplc_email" ).val().replace(/(<([^>]+)>)/ig,""); }
424
425
426        wplc_send_welcome_message();
427
428        var start_data = {
429                relay_action: 'wplc_new_chat',
430                security: wplc_nonce,
431                cid: wplc_cid,
432                wplc_name: wplc_cookie_name,
433                wplc_email: wplc_cookie_email,
434                wplc_extra_data: {},
435                url : window.location.href,
436                session : wplc_session_variable
437        };
438        
439
440
441        if(typeof wplc_start_chat_pro_custom_fields_filter !== "undefined" && typeof wplc_start_chat_pro_custom_fields_filter === "function"){
442            wplc_start_chat_pro_custom_fields_filter(wplc_extra_data, start_data, function(passed_extra_data, passed_action_data){
443                //Callback after processing custom field
444                wplc_rest_api('start_chat', passed_action_data, 12000, null);
445
446            });
447        } else {
448            start_data["wplc_extra_data"] = wplc_extra_data;
449            wplc_rest_api('start_chat', start_data, 12000, null);
450        }
451
452        jQuery.event.trigger({type: "wplc_open_chat_2", wplc_online: wplc_online});
453
454        if (typeof wplc_enable_ga !== "undefined" && wplc_enable_ga === '1') {
455            if (typeof ga !== "undefined") {
456                ga('send', {
457                  hitType: 'event',
458                  eventCategory: 'WP_Live_Chat_Support',
459                  eventAction: 'Event',
460                  eventLabel: 'Start Chat'
461                });
462            }
463        }
464         
465    });
466
467    if (typeof wplc_elem_trigger != 'undefined') {
468      if (wplc_elem_trigger.id != "") {
469        try {
470          var wplc_click_or_hover = parseInt(wplc_elem_trigger.action);
471          var wplc_class_or_id = parseInt(wplc_elem_trigger.type);
472          jQuery((wplc_class_or_id == 1 ? "#" : ".") + wplc_elem_trigger.id).on((wplc_click_or_hover == 1 ? "mouseenter" : "click"), function() {
473            open_chat(0);
474          });
475        } catch (e) {
476          console.log("WPLC Error: \"" + (wplc_class_or_id == 1 ? "#" : ".") + wplc_elem_trigger.id + "\" is not a valid selector");
477        }
478      }
479    }    
480    
481    /** End Chat from User Side */
482    jQuery(document).on("wplc_end_chat_as_user", function(e){
483        if(typeof socket !== "undefined"){
484            socket.emit('end chat', {chatid:chatid,agent:false,agent_name:'User', visitor_socket: socket.id});
485        }
486        jQuery("#wplc_chatbox").html("");
487        Cookies.remove('wplc_chat_status');
488    		Cookies.remove('wplc_cid');
489
490        data = { 'agent_name' : 'User'};
491
492        jQuery.event.trigger({type: "tcx_chat_ended_notification", ndata:data});
493        
494        jQuery('#tcx_chat_ended').show();
495        jQuery('.tcx_restart_chat').remove();
496        tcx_end_chat_div_create();
497
498
499        if (typeof user_heartbeat !== "undefined"){
500            clearInterval(user_heartbeat);
501        }
502        
503        user_heartbeat = undefined;
504        
505        //socket.disconnect({test:'test'});
506        
507        niftyUpdateStatusCookie('browsing');
508        nc_status = 'browsing';
509        nifty_chat_status_temp = 'browsing';
510        nifty_chat_status = 'browsing';
511        // restart connection as a visitor
512        if (typeof io !== "undefined") {
513          socket = io.connect(WPLC_SOCKET_URI, { query : query_string, transports: ['websocket'] } );
514          wplc_chat_delegates();
515        }
516
517        // if(typeof Cookies !== "undefined"){
518        //   Cookies.remove("wplc_cid");
519        // }
520
521        if (typeof wplc_enable_ga !== "undefined" && wplc_enable_ga === '1') {
522            if (typeof ga !== "undefined") {
523                ga('send', {
524                  hitType: 'event',
525                  eventCategory: 'WP_Live_Chat_Support',
526                  eventAction: 'Event',
527                  eventLabel: 'User End Chat'
528                });
529            }
530        }
531    });
532});
533

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.