1/** 2 * Traditional JS handlers for pro features (Non-node based) 3 * 4 */ 5 6 7jQuery(function () { 8 9 10 /** 11 * Hook into the user chat loop to identify if an agent is typing 12 * 13 */ 14 jQuery(document).on( "wplc_user_chat_loop", function( e ) { 15 if(typeof wplc_node_sockets_ready === "undefined" || wplc_node_sockets_ready === false){ 16 if (wplc_misc_strings.typing_enabled === "1") { 17 wplc_cid = Cookies.get('wplc_cid'); 18 if (typeof e.response['typing'] === "undefined") { 19 jQuery("#wplc_user_typing").fadeOut("slow").remove(); 20 } 21 if (e.response['status'] === 8) { 22 jQuery('#nifty_text_editor_holder').css('display', 'none'); 23 jQuery('#nifty_file_holder').css('display', 'none'); 24 } 25 if (e.response['typing'] === "1") { 26 if (jQuery("#wplc_user_typing").length>0) { } else { 27 if(typeof wplc_localized_string_is_typing !== "undefined"){ 28 if (typeof wplc_agent_name === "undefined" || wplc_agent_name === "") { 29 jQuery(".typing_indicator").html("<span id='wplc_user_typing'>"+ wplc_localized_string_is_typing + "</span>"); 30 jQuery(".typing_indicator").addClass("typing_indicator_active"); 31 } else { 32 jQuery(".typing_indicator").html("<span id='wplc_user_typing'>"+wplc_agent_name+ " "+wplc_localized_string_is_typing_single + "</span>"); 33 jQuery(".typing_indicator").addClass("typing_indicator_active"); 34 } 35 } else { 36 /* Backwards compat */ 37 jQuery("#wplc_chatbox").append("<img id='wplc_user_typing' src='"+wplc_misc_strings.typingimg+"' />"); 38 jQuery("#wplc_user_typing").fadeIn("fast"); 39 var height = jQuery('#wplc_chatbox')[0].scrollHeight; 40 jQuery('#wplc_chatbox').scrollTop(height); 41 } 42 } 43 44 } else if (e.response['typing'] === "0") { 45 if (jQuery("#wplc_user_typing").length>0) { 46 jQuery("#wplc_user_typing").fadeOut("slow").remove(); 47 jQuery(".typing_indicator").removeClass("typing_indicator_active"); 48 } 49 } 50 } 51 } 52 }); 53 54 55 jQuery("body").on("change", "#nifty_file_input", function(evt){ 56 var file = this.files[0]; //Last file in array 57 wplcShareFile(file,'#nifty_attach_fail_icon', '#nifty_attach_success_icon', '#nifty_attach_uploading_icon', "#nifty_select_file"); 58 evt.stopImmediatePropagation(); 59 }); 60 61 /** 62 * Use WP REST API to notify the system that we are typing 63 * 64 */ 65 jQuery("body").on("keydown","#wplc_chatmsg", function(e) { 66 if(typeof wplc_node_sockets_ready === "undefined" || wplc_node_sockets_ready === false){ 67 if (wplc_misc_strings.typing_enabled === "1") { 68 if (e.which <= 90 && e.which >= 48) { 69 if (wplc_is_typing) { 70 71 wplc_renew_typing(); 72 return; /* user already typing */ 73 } 74 wplc_is_typing = true; 75 76 wplc_searchTimeout = setTimeout(wplc_clear_typing, 3000); 77 wplc_cid = Cookies.get('wplc_cid'); 78 wplc_usertyping('user',Math.floor(Date.now() / 1000),wplc_cid); 79 } 80 } 81 } 82 }); 83 84 /** 85 * Clear typing 86 * 87 */ 88 jQuery("body").on("click", "#wplc_send_msg", function() { 89 if (wplc_misc_strings.typing_enabled === "1") { 90 if (wplc_is_typing) { wplc_clear_typing(); } 91 } 92 }); 93 94 95 function wplc_renew_typing() { 96 clearTimeout(wplc_searchTimeout); 97 wplc_searchTimeout = setTimeout(wplc_clear_typing, 3000); 98 } 99 function wplc_clear_typing() { 100 wplc_is_typing = false; 101 clearTimeout(wplc_searchTimeout); 102 wplc_cid = Cookies.get('wplc_cid'); 103 wplc_usertyping('user',0,wplc_cid); 104 } 105 106 107 /** 108 * Notify WP REST API of user typing 109 * 110 */ 111 function wplc_usertyping(wplc_typing_user,wplc_typing_type,wplc_typing_cid) { 112 113 if (typeof wplc_cid !== "undefined" && wplc_cid !== null) { 114 var data = { 115 action: 'wplc_typing',
116 security: wplc_nonce, 117 user: wplc_typing_user, 118 type: wplc_typing_type, 119 cid: wplc_typing_cid, 120 wplc_extra_data:wplc_extra_data 121 }; 122 123 if (typeof wplc_restapi_enabled !== "undefined" && wplc_restapi_enabled === '1' && typeof wplc_using_cloud === "undefined") { 124 data.security = (typeof wplc_restapi_token !== "undefined" ? wplc_restapi_token : false); 125 jQuery.post(wplc_restapi_endpoint+"/typing/", data, function(response) {}); 126 } else { 127 jQuery.post(wplc_ajaxurl, data, function(response) {}); 128 } 129 130 } else { 131 /* no cid? */ 132 } 133 } 134 135 136 137});
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.