var nc_sid; var nc_name; var wplc_cid; var socket; var FADE_TIME = 150; // ms var TYPING_TIMER_LENGTH = 1000; // ms var username = 'Guest'; var connected = false; var typing = false; var lastTypingTime; var nifty_is_chat_open = false; var nifty_chat_status = "browsing"; var bleeper_show_drag_zone = false; /* helps us keep track of which messages made it to the server */ var bleeper_msg_confirmations = {}; /** * Keep track of recent agents * @type {array} */ var bleeper_recent_agents = undefined; var bleeper_recent_agents_data = undefined; /** * Setup Query String, customer ID, and fingerprint */ var query_string = ""; var bleeper_customerID = null; var bleeper_fingerprint = null; /** * Set allowed file types */ var bleeper_file_suffix_check = [ "zip", "pdf", "txt", "mp3", "mpa", "ogg", "wav", "wma", "7z", "rar", "db", "xml", "csv", "sql", "apk", "exe", "jar", "otf", "ttf", "fon", "fnt", "ai", "psd", "svg", "tif", "tiff", "ps", "msi", "doc", "docx", ]; var wplc_chat_delegates; var wplc_connect; var bleeper_ping = new Audio(wplc_baseurl + "/audio/ding.mp3"); var bleeper_inactive = false; var bleeper_inactive_timeout; var bleeper_timeout_duration = 300000; var bleeperAverageResponseTime = undefined; /** * An array to keep track of agent disconnects * @type {array} */ var agent_disc_timer = []; /** * Set the default agent_joined variable * @type {array} */ var agent_joined = []; /** * Used to identify the heartbeat timer */ var user_hearbeat; /** * variable to check if the agent is online or not - this is set after the first run to the server * @type {Boolean} */ var wplc_online = false; /** * Everytime the user clicks the minimize button this is set to true * @type {Boolean} */ var nifty_is_minimized = false; /** * Used as a set up variables for the text editor */ var selectedIndexStart; var selectedIndexEnd; var checkSelection = true; /** * Set up the global variable for the function */ var wplcFormatParser; /** * Variable to help identfy if we are editing a message * @type {Boolean} */ var niftyIsEditing = false; /** * Identify the last message sent, so when we press UP we can edit it */ var lastmessagesent; /** * Sets default for identifying if the welcome message has been sent yet, or not * @type {Boolean} */ var nifty_welcome_message_sent = false; var $inputMessage = ''; var $messages = ''; var bleeper_first; var bleeper_current; var bleeper_location_info = false; /* Regex for inline links */ var bleeper_link_match_regex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!,.;<>]*[-A-Z0-9+&@#\/%=~_|<>])/ig; /* OS Holder */ var bleeper_user_current_os = false; //When false the 'bleeper_get_operating_system' function will run all actions to identify the OS /** * Generate a unique ID for the visitor * * @return {string} guid */ function wplc_jsguid() { var nav = window.navigator; var screen = window.screen; var guid = nav.mimeTypes.length; guid += nav.userAgent.replace(/\D+/g, ''); guid += nav.plugins.length; guid += screen.height || ''; guid += screen.width || ''; guid += screen.pixelDepth || ''; return guid; }; /** * Setup the socket query variable, which is appended to the socket connection whenever the soket connects to the node servers */ function wplc_set_up_query_string() { if (typeof wplc_guid !== "undefined") { query_string += "&guid=" + wplc_guid; } if (typeof bleeper_user_ip_address !== "undefined") { query_string += "&user_ip=" + bleeper_user_ip_address; } if (typeof bleeper_location_info !== "undefined" && bleeper_location_info !== false) { if (typeof bleeper_location_info.code !== "undefined" && typeof bleeper_location_info.name !== "undefined") { query_string += "&location_code=" + bleeper_location_info.code + "&location_name=" + bleeper_location_info.name; } } bleeper_customerID = wplc_getCookie('bleeper_customerID'); if (typeof bleeper_customerID !== "undefined" && bleeper_customerID !== '' && bleeper_customerID !== null) { query_string += "&customer_id=" + bleeper_customerID; } bleeper_fingerprint = wplc_jsguid(); if (typeof bleeper_fingerprint !== "undefined" && bleeper_fingerprint !== '' && bleeper_fingerprint !== null) { query_string += "&bleeper_fingerprint=" + bleeper_fingerprint; } if (typeof window !== "undefined" && typeof window.location !== "undefined" && typeof window.location.href !== "undefined") { query_string += "&referer=" + window.location.href; } query_string = wplc_query_cleanup(query_string); } jQuery(document).on('wplc_sockets_ready', function () { console.log('here'); /** * Run Query setup function */ wplc_set_up_query_string(); wplc_powered_by(); /** * Setup an inactive timer */ bleeper_inactive_timeout = setTimeout(function () { bleeper_inactive = true; }, bleeper_timeout_duration); if (typeof bleeper_message_override !== "undefined") { bleeper_ping = new Audio(bleeper_message_override); } /*Find nifty object and check if online */ if (wplc_test_localStorage()) { var wplc_d = new Date(); wplc_d.toUTCString(); var cdatetime = Math.floor(wplc_d.getTime() / 1000); if (localStorage.getItem('bleeper_first') === null) { localStorage.setItem('bleeper_first', cdatetime); bleeper_first = cdatetime; } else { bleeper_first = localStorage.getItem('bleeper_first'); } localStorage.setItem('bleeper_current', cdatetime); bleeper_current = cdatetime; } if (typeof ns_obj === 'undefined') { //Nifty Chat Object not created yet } else { if (ns_obj.o === '1') { wplc_online = true; } else { wplc_run = false; wplc_online = false; } } wplc_check_minimize_cookie = Cookies.get('nifty_minimize'); var dragTimeout = -1; jQuery("html").bind("dragenter", function () { jQuery("#chat_drag_zone").fadeIn(); bleeper_show_drag_zone = true; }); jQuery("html").bind("dragover", function () { bleeper_show_drag_zone = true; }); jQuery("html").bind("dragleave", function () { bleeper_show_drag_zone = false; clearTimeout(dragTimeout); dragTimeout = setTimeout(function () { if (!bleeper_show_drag_zone) { jQuery("#chat_drag_zone").fadeOut(); } }, 200); }); jQuery("#chat_drag_zone").on("dragover", function (event) { event.preventDefault(); event.stopPropagation(); }); jQuery("#chat_drag_zone").on("dragleave", function (event) { event.preventDefault(); event.stopPropagation(); }); jQuery("#chat_drag_zone").on("drop", function (event) { event.preventDefault(); event.stopPropagation(); if (jQuery('#nifty_add_media:checked').length > 0) { //Do nothing its open } else { jQuery("#nifty_add_media").click(); } var fileInput = document.getElementById('nifty_file_input'); fileInput.files = event.originalEvent.dataTransfer.files; jQuery("#chat_drag_zone").fadeOut(); }); /** * Builds the socket delegates. This needs to be called everytime a connection is made (i.e. moving from a short poll to a long poll) */ wplc_chat_delegates = function (keepalive) { nifty_chat_status_temp = nc_getCookie("nc_status"); if (typeof nifty_chat_status_temp !== "undefined" && nifty_chat_status_temp === "active") { /* leave the cookie untouched as we are already in ACTIVE state and should continue in this state until changed. */ } else { if (keepalive) { niftyUpdateStatusCookie("active"); } else { niftyUpdateStatusCookie("browsing"); } } nifty_username_temp = nc_getCookie("nc_username"); if (typeof nifty_username_temp !== "undefined") { username = nifty_username_temp; } // Socket events socket.on('connect', function (data) { nc_add_user(socket, data); nifty_chat_status_temp = nc_getCookie("nc_status"); if (typeof nifty_chat_status_temp !== "undefined" && nifty_chat_status_temp === "active") { if (typeof user_hearbeat === "undefined") { user_hearbeat = setInterval(function () { if (socket.connected) socket.emit('heartbeat'); }, 5000); } } jQuery.event.trigger({ type: 'bleeper_socket_connected', status: nifty_chat_status_temp }); }); socket.on("force_disconnect", function (data) { socket.disconnect({ test: 'test' }); if (typeof user_heartbeat !== "undefined") clearInterval(user_hearbeat); user_heartbeat = undefined; /* reconnect this socket in 7 seconds to check for a forced chat on the agents end */ setTimeout(function () { wplc_connect(false); }, 12000); /* its important that this number is less than the TTL of the variable in redis */ }); socket.on("blacklisted", function (data) { jQuery.event.trigger({ type: "bleeper_blacklisted", ndata: data }); }); socket.on("user blocked", function (data) { socket.disconnect({ blocked: 'blocked' }); CookieDate.setFullYear(CookieDate.getFullYear() + 1); Cookies.set('bleeper_b', '1', { expires: CookieDate, path: '/' }); jQuery("#wp-live-chat-4").remove(); jQuery("#wp-live-chat-wraper").remove(); keepalive = false; }); socket.on("customerID", function (data) { var CookieDate = new Date; CookieDate.setFullYear(CookieDate.getFullYear() + 1); Cookies.set('bleeper_customerID', data.customerID, { expires: CookieDate, path: '/' }); }); socket.on("agent initiate", function (data) { if (typeof user_hearbeat === "undefined") { socket.emit('initiate received', { chatid: wplc_cid }); user_hearbeat = setInterval(function () { if (socket.connected) { socket.emit('heartbeat'); } }, 5000); } niftyUpdateStatusCookie('active'); jQuery.event.trigger({ type: "bleeper_agent_initiated_chat", ndata: data }); }); /* Confirm that a message was saved to the db */ socket.on('message received', function (data) { if (typeof data !== 'undefined') { if (typeof data.msgID !== 'undefined' && typeof data.outcome !== 'undefined') { bleeper_msg_confirmations[data.msgID] = data.outcome; } } }); socket.on('message read received', function (data) { jQuery.event.trigger({ type: "bleeper_message_read_received", ndata: data }); }); socket.on('agent to participant ping', function (data) { socket.emit('agent to participant ping received', { fromsocket: socket.id, intendedsocket: data.fromsocket, chatid: data.chatid }); }); socket.on("chat ended", function (data) { jQuery.event.trigger({ type: "bleeper_chat_ended_notification", ndata: data }); jQuery("#bleeper_chat_ended").show(); bleeper_end_chat_div_create(); //$("#wplc_user_message_div").hide(); if (typeof user_heartbeat !== "undefined") clearInterval(user_heartbeat); user_heartbeat = undefined; socket.disconnect({ test: 'test' }); niftyUpdateStatusCookie('browsing'); // restart connection as a visitor if (typeof io !== "undefined") { wplc_set_up_query_string(); socket = io.connect(WPLC_SOCKET_URI, { query: query_string, transports: ['websocket'] }); wplc_chat_delegates(); } if (typeof Cookies !== "undefined") { Cookies.remove("wplc_cid"); } }); socket.on("averageResponse", function (data) { jQuery.event.trigger({ type: "bleeper_average_response", ndata: data }); }); socket.on("recent_agents", function (data) { if (typeof data !== "undefined" && typeof data.agents !== "undefined") { bleeper_recent_agents = data.agents; } }); socket.on("agent_data", function (data) { if ((typeof data !== "undefined" && data !== null) && (typeof data.ndata !== "undefined" && data.ndata !== null) && (typeof data.ndata.aid !== 'undefined' && data.ndata.aid !== null)) { if (typeof bleeper_recent_agents_data === "undefined") { bleeper_recent_agents_data = {}; bleeper_recent_agents_data[data.ndata.aid] = data.ndata; } else { bleeper_recent_agents_data[data.ndata.aid] = data.ndata; } } }); socket.on("transfer chat", function (data) { addNotice({ message: 'You are being transferred to another agent. Please be patient.' }); }); socket.on("location found", function (data) { bleeper_location_info = data; //Set the data }); socket.on('chat history', function (data) { jQuery.event.trigger({ type: "bleeper_chat_history", ndata: data }); }); // Whenever the server emits 'login', log the login message socket.on('login', function (data) { connected = true; // Display the welcome message /** * Only show if this is the keepalive session (i.e. we are wanting to chat now) */ if (keepalive) { var message = "Connection established"; } }); // Whenever the server emits 'new message', update the chat body socket.on('new message', function (data) { socket.emit('message read', data); jQuery.event.trigger({ type: "bleeper_new_message", ndata: data }); if (typeof wplc_enable_ding !== 'undefined' && '1' === wplc_enable_ding) { bleeper_ping.play(); } }); // Whenever the server emits 'new message', update the chat body socket.on('edit message', function (data) { jQuery.event.trigger({ type: "bleeper_edit_message", ndata: data }); }); socket.on('user chat notification', function (data) { jQuery.event.trigger({ type: "bleeper_user_chat_notification", ndata: data }); }); socket.on('custom data received', function (data) { jQuery.event.trigger({ type: "bleeper_custom_data_received", ndata: data }); }); // Whenever the server emits 'new message', update the chat body socket.on('socketid', function (socketid) { document.cookie = "nc_sid=" + socketid.socketid; if (!wplc_online) {} }); socket.on('agent joined', function (data) { clearTimeout(agent_disc_timer[data.agent]); jQuery.event.trigger({ type: "bleeper_agent_joined", ndata: data }); }); socket.on('new_socket', function (socketid) {}); socket.on('agent left', function (data) { jQuery.event.trigger({ type: "bleeper_agent_left", ndata: data }); }); socket.on('agent connected', function (data) { clearTimeout(agent_disc_timer[data.aid]); }) socket.on('agent disconnected', function (data) { agent_disc_timer[data.aid] = setTimeout(function () { jQuery.event.trigger({ type: "bleeper_agent_disconnected", ndata: data }); removeChatTyping(data); }, 8000); }); // Whenever the server emits 'typing', show the typing message socket.on('typing', function (data) { jQuery.event.trigger({ type: "bleeper_typing", ndata: data }); }); // Whenever the server emits 'stop typing', kill the typing message socket.on('stop typing', function (data) { jQuery.event.trigger({ type: "bleeper_stop_typing", ndata: data }); }); // Receive CHAT ID from server socket.on('chatID', function (data) { Cookies.set('wplc_cid', data.chatid, { expires: 1, path: '/' }); wplc_cid = data.chatid; /* is chat box open? */ if (!nifty_is_chat_open) { nifty_init_chat_box_check(data.chatid); } }); socket.on("involved check returned", function (data) { jQuery.event.trigger({ type: 'bleeper_build_involved_agents_header', ndata: data }); }); socket.on('disconnect', function () { if (typeof user_heartbeat !== "undefined") clearInterval(user_heartbeat); user_heartbeat = undefined; /** * Only show if this was part of the keepalive session (i.e. an active chat) */ if (keepalive) { //log('you have been disconnected'); //TODO: Add Bleeper handler as well jQuery.event.trigger({ type: "bleeper_disconnected" }); } }); socket.on('reconnect', function () { /** * Only show if this was part of the keepalive session (i.e. an active chat) */ if (keepalive) { //log('you have been reconnected'); //TODO: Addd bleeper handler jQuery.event.trigger({ type: "bleeper_reconnect" }); } nc_add_user(socket, 'what the shizz'); }); socket.on('reconnect_error', function () { //log('attempt to reconnect has failed'); //TODO: Addd bleepet handler jQuery.event.trigger({ type: "bleeper_reconnect_error" }); }); socket.on('a2vping', function (data) { socket.emit('a2vping return', { fromsocket: socket.id, intendedsocket: data.returnsocket, chatid: data.chatid }); }) } $messages = jQuery('#wplc_chatbox'); // Messages area $inputMessage = jQuery('#wplc_chatmsg'); // Input message input box jQuery("#nifty_file_input").on("change", function () { var file = this.files[0]; //Last file in array wplcShareFile(file, '#nifty_attach_fail_icon', '#nifty_attach_success_icon', '#nifty_attach_uploading_icon', "#nifty_select_file"); jQuery("#chat_drag_zone").fadeOut(); }); /** Image pasting functionality */ try { document.getElementById('wplc_chatmsg').onpaste = function (event) { // use event.originalEvent.clipboard for newer chrome versions var items = (event.clipboardData || event.originalEvent.clipboardData).items; // find pasted image among pasted items var blob = null; for (var i = 0; i < items.length; i++) { if (items[i].type.indexOf("image") === 0) { blob = items[i].getAsFile(); } } // load image if there is a pasted image if (blob !== null) { var reader = new FileReader(); reader.onload = function (event) { document.getElementById("wplc_chatmsg").value = "####" + event.target.result + "####"; jQuery("#wplc_send_msg").click(); jQuery("#bleeper_send_msg").click(); }; reader.readAsDataURL(blob); } } } catch (ex) {} jQuery("#nifty_tedit_b").click(function () { niftyTextEdit("b"); }); jQuery("#nifty_tedit_i").click(function () { niftyTextEdit("i"); }); jQuery("#nifty_tedit_u").click(function () { niftyTextEdit("u"); }); jQuery("#nifty_tedit_strike").click(function () { niftyTextEdit("strike"); }); jQuery("#nifty_tedit_mark").click(function () { niftyTextEdit("mark"); }); jQuery("#nifty_tedit_sub").click(function () { niftyTextEdit("sub"); }); jQuery("#nifty_tedit_sup").click(function () { niftyTextEdit("sup"); }); jQuery("#nifty_tedit_link").click(function () { niftyTextEdit("link"); }); setInterval(function () { getText(document.getElementById("wplc_chatmsg")); }, 1000); /** * End of rich text functionality */ /* find out if we have had a chat with this visitor before */ sid = nc_getCookie("wplc_sid"); nifty_chat_status_temp = nc_getCookie("nc_status"); if (nifty_chat_status_temp !== "undefined") { nifty_chat_status = nifty_chat_status_temp; } chatid = nc_getCookie("wplc_cid"); if (chatid !== "undefined") { wplc_cid = chatid; nc_name = nc_getCookie("nc_username"); } if (window.console) { console.log("[WPLC] Connecting to " + WPLC_SOCKET_URI); } /* is socket.io ready yet? */ /* blocked? */ var bleeper_b = wplc_getCookie('bleeper_b'); if (typeof bleeper_b !== "undefined" && bleeper_b === '1') { console.log("[WPLC] You have been blocked from using WP Live Chat Support"); return; } else { if (typeof io !== "undefined") { wplc_set_up_query_string(); socket = io.connect(WPLC_SOCKET_URI, { query: query_string, transports: ['websocket'] }); } else { var socketchecker = setInterval(function () { if (typeof io !== "undefined") { clearInterval(socketchecker); wplc_set_up_query_string(); socket = io.connect(WPLC_SOCKET_URI, { query: query_string, transports: ['websocket'] }); } }, 1000); } wplc_chat_delegates(); } /** * Connect the node socket * * @param {bool} keepalive Keep this connection alive? */ wplc_connect = function (keepalive) { if (bleeper_inactive === false) { if (typeof socket !== "undefined") { if (socket.connected) { /* already connected */ } else { //opening socket connection wplc_set_up_query_string(); socket = io.connect(WPLC_SOCKET_URI, { query: query_string, transports: ['websocket'] }); wplc_chat_delegates(keepalive); } } else { //opening socket connection2 wplc_set_up_query_string(); socket = io.connect(WPLC_SOCKET_URI, { query: query_string, transports: ['websocket'] }); wplc_chat_delegates(keepalive); } } else { /* try again in 7 seconds */ setTimeout(function () { if (socket.connected) {} else { wplc_connect(false); } }, 7000); } } // Initialize variables var $window = jQuery(window); var message_preview_currently_being_typifcationed; /** * Detect if the user is active or inactive. * * This manipulates the shortpoll connection to the server * * i.e. an inactive user will not send shortpolls. */ jQuery(document).on('mousemove', function () { clearTimeout(bleeper_inactive_timeout); bleeper_inactive = false; bleeper_inactive_timeout = setTimeout(function () { bleeper_inactive = true; }, bleeper_timeout_duration); }); document.addEventListener('bleeper_send_message', function (e) { if (typeof wplc_online !== 'undefined' && wplc_online === true) { socket.emit('stop typing', { chatid: wplc_cid }); } // reset the typing variable typing = false; // reset the niftyIsEditing variable niftyIsEditing = false; }, false); jQuery(document).on("bleeper_send_message", function (e) { //sendMessage(e.message); if (typeof wplc_online !== 'undefined' && wplc_online === true) { socket.emit('stop typing', { chatid: wplc_cid }); } // reset the typing variable typing = false; // reset the niftyIsEditing variable niftyIsEditing = false; }); // Keyboard events jQuery(document).on("keydown", "#wplc_chatmsg", function (event) { // When the client hits ENTER on their keyboard if (event.which === 13 && !event.shiftKey) { if (jQuery(this).val().trim() !== '') { event.preventDefault(); jQuery("#wplc_send_msg").click(); jQuery("#bleeper_send_msg").click(); } } else if (event.which === 38 && !event.shiftKey) { if (typeof lastmessagesent !== "undefined") { if (typeof wplc_integration_pro_active !== "undefined" && wplc_integration_pro_active === "true") { var mid = lastmessagesent; var mdiv = jQuery('.message_' + mid + " .messageBody").html(); jQuery("#wplc_chatmsg").val(mdiv); // set the niftyIsEditing variable to the msgID so we can identify if we are in the process of editing a message niftyIsEditing = mid; } } } else if (event.which === 27 && !event.shiftKey) { jQuery("#wplc_chatmsg").val(''); niftyIsEditing = false; } }); $inputMessage.keyup(function (event) { // When the client hits ENTER on their keyboard if (event.which === 13 && !event.shiftKey) {} else { if (typeof wplc_online !== 'undefined' && wplc_online === true) { var typing_preview_tmp = cleanInput($inputMessage.val()); socket.emit('typing_preview', { chatid: wplc_cid, tempmessage: typing_preview_tmp }); } } }); $inputMessage.on('input', function () { updateTyping(); }); // Click events // Focus input when clicking on the message input's border $inputMessage.click(function () { $inputMessage.focus(); }); jQuery(document).on("mouseleave", ".message", function () { var tmid = jQuery(this).attr('mid'); jQuery(".message_" + tmid + " .bleeper-edit-message").hide(); }); jQuery(document).on("mouseenter", ".message", function () { var tmid = jQuery(this).attr('mid'); jQuery(".message_" + tmid + " .bleeper-edit-message").show(); }); jQuery(document).on("click", ".bleeper_restart_chat", function () { jQuery("#wp-live-chat-header").click(); setTimeout(function () { jQuery("#wp-live-chat-header").click(); }, 50); jQuery('#wplc_end_chat_button').show(); jQuery('#wplc_end_chat_button').removeAttr('wplc_disable'); }); jQuery(document).on("click", "#wplc_send_msg", function () { var message = $inputMessage.val(); if(message.length > 2000){ message = message.substring(0, 2000); } sendMessage(message); }); jQuery(document).on("click", ".bleeper-edit-message", function () { var mid = jQuery(this).parent().attr('mid'); var mdiv = jQuery(this).siblings('.messageBody').attr("data-message"); jQuery("#wplc_chatmsg").val(mdiv); // set the niftyIsEditing variable to the msgID so we can identify if we are in the process of editing a message niftyIsEditing = mid; }); jQuery(document).on("nifty_trigger_open_chat", function (event) { open_chat(); jQuery("#bleeper_chat_ended").hide(); }); jQuery(document).on("bleeper_socket_connected", function (e) { if (typeof socket !== "undefined" && typeof nifty_chat_status !== "undefined") { if (nifty_chat_status === "active") { socket.emit('check involved agents', { chatid: chatid }); } } }); jQuery(document).on("wplc_animation_done", function (event) { if (typeof wdtEmojiBundle !== "undefined") { wdtEmojiBundle.defaults.emojiSheets = { 'apple' : wplc_baseurl + '/js/vendor/wdt-emoji/sheets/sheet_apple_64_indexed_128.png', 'google' : wplc_baseurl + '/js/vendor/wdt-emoji/sheets/sheet_google_64_indexed_128.png', 'twitter' : wplc_baseurl + '/js/vendor/wdt-emoji/sheets/sheet_twitter_64_indexed_128.png', 'emojione' : wplc_baseurl + '/js/vendor/wdt-emoji/sheets/sheet_emojione_64_indexed_128.png', 'facebook' : wplc_baseurl + '/js/vendor/wdt-emoji/sheets/sheet_facebook_64_indexed_128.png', 'messenger': wplc_baseurl + '/js/vendor/wdt-emoji/sheets/sheet_messenger_64_indexed_128.png' }; bleeper_attempt_emoji_input_init(0); } }); /* Minimize chat window */ jQuery("#wp-live-chat-minimize").on("click", function () { jQuery.event.trigger({ type: "nifty_minimize_chat" }); Cookies.set('nifty_minimize', "yes", { expires: 1, path: '/' }); nifty_is_minimized = true; }); /** * Click handler for the start chat button */ jQuery("#wplc_start_chat_btn").on("click", function () { var wplc_is_gdpr_enabled = jQuery(this).attr('data-wplc-gdpr-enabled'); if (typeof wplc_is_gdpr_enabled !== "undefined" && (wplc_is_gdpr_enabled === 'true')) { var wplc_gdpr_opt_in_checked = jQuery("#wplc_chat_gdpr_opt_in").is(':checked'); if (typeof wplc_gdpr_opt_in_checked === "undefined" || wplc_gdpr_opt_in_checked === false) { /* GDPR requirements not met */ jQuery("#wplc_chat_gdpr_opt_in").addClass('incomplete'); return false; } jQuery("#wplc_chat_gdpr_opt_in").removeClass('incomplete'); } var wplc_name = jQuery("#wplc_name").val(); var wplc_email = jQuery("#wplc_email").val(); if (wplc_name.length <= 0) { alert("Please enter your name"); return false; } if (wplc_email.length <= 0) { alert("Please enter your email address"); return false; } if (jQuery("#wplc_email").attr('wplc_hide') !== "1") { var testEmail = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,6}$/i; if (!testEmail.test(wplc_email)) { alert("Please Enter a Valid Email Address"); return false; } } jQuery.event.trigger({ type: "nifty_trigger_start_chat" }); var date = new Date(); date.setTime(date.getTime() + (2 * 60 * 1000)); niftyUpdateUserDataCookies(wplc_name, wplc_email); niftyUpdateGravCookie(md5(wplc_email)); niftyUpdateStatusCookie("active"); wplc_connect(true); var request_chat_checker = setInterval(function () { if (typeof socket !== "undefined" && typeof socket.connected !== "undefined" && socket.connected === true) { clearInterval(request_chat_checker); socket.emit("request chat", { chatid: wplc_cid, name: wplc_name, email: wplc_email }); } else { //still not connected, trying again } }, 300); }); }); // document.ready /** * Add a log to the chat box * * @param {string} message Log message string * @param {object} options Options for the message being added (fade, prepend) */ function log(message, options) { var $el = jQuery('
" + to_replace + ""); } } var code_match = msg.match(/`([^*]*?)`/g); if (code_match !== null) { for (var i = 0, len = code_match.length; i < len; i++) { var to_find = code_match[i]; var to_replace = to_find.substring(1, to_find.length - 1); // remove the starting ` and ending ` msg = msg.replace(to_find, "
" + to_replace + "
");
}
}
msg = msg.replace(/\n/g, "