//===================== // Copyright (c) 2004-2005 // Fastpath // http://www.jivesoftware.com //===================== /* * $RCSfile$ * $Revision: 19342 $ * $Date: 2005-07-20 09:30:31 -0700 (Wed, 20 Jul 2005) $ * * Copyright (C) 2003-2008 Jive Software. All rights reserved. * * This software is the proprietary information of Jive Software. Use is subject to license terms. */ // Hyperlink in chat message Regexp. const hyperLinkRegex = /(= 33) { start = i; break; } else{ start++; } } for (var i = text.length; i > start; i--) { var code = text.charCodeAt(i - 1); if (code >= 33) { end = i; break; } } return text.substring(start, end); } // Override Date for get AM/PM time Date.prototype.getPeriodHours = function(){ return (this.getHours()>12?this.getHours()-12:this.getHours()); } Date.prototype.getPeriod = function(){ return (this.getHours()>12?"PM":"AM"); } Date.prototype.getMinutesWithLeadingZeros = function(){ return (this.getMinutes()<10?'0':'') + this.getMinutes(); } // variable to tell whether or not a form has been clicked var clicked = false; function allowClick() { if (! clicked) { clicked = true; return true; } return false; } // Sequence for open window names var windowNameSeq = 0; // Array of all open windows var windows = new Array(); // Checks to see if a window exists function windowExists(name) { for (var i = 0; i < windows.length; i++) { // IE needs a try/catch here for to avoid an access violation on windows[i].name // in some cases. try { if (windows[i].name == name) { return true; } } catch (exception) { } } return false; } // Returns the window object - returns nothing if not found. function getWindow(name) { for (var i = 0; i < windows.length; i++) { try { if (windows[i].name == name) { return windows[i]; } } catch (exception) { } } } function removeWindow(name) { for (var i = 0; i < windows.length; i++) { try { if (windows[i].name == name) { windows.splice(i, 1); return; } } catch (exception) { } } } // Open a window given its unique name, url, width and height. function pushWin(name, url, width, height) { var defaultOptions = "location=yes,status=yes,toolbar=no,personalbar=no,menubar=no,directories=no,"; defaultOptions += "scrollbars=yes,resizable=yes,"; defaultOptions += "width=" + width + ",height=" + height; launchWinWithOptions(name, url, defaultOptions); } // Open a window given its unique name, url, width and height. function launchWin(name, url, width, height) { var defaultOptions = "location=no,status=no,toolbar=no,personalbar=no,menubar=no,directories=no,"; var winleft = (screen.width - width) / 2; var winUp = (screen.height - height) / 2; defaultOptions += "scrollbars=no,resizable=yes,top=" + winUp + ",left=" + winleft + ","; defaultOptions += "width=" + width + ",height=" + height; launchWinWithOptions(name, url, defaultOptions); } // Open a window with given name, url, and options list function launchWinWithOptions(name, url, options) { if (! windowExists(name)) { var winVar = window.open(url, name, options); windows[windows.length] = winVar; return winVar; } else{ var theWin = getWindow(name); theWin.focus(); } } function getTopLevelWindow() { var win = window; if (win.parent == win) { return win; } while (win.parent != win) { win = window.parent.window; } return win; } // Close the current window object function closeWin(win) { win.close(); } // Handle closing of the current window function handleClose(message) { if (confirm(message)) { removeWindow(getTopLevelWindow().name); closeWin(getTopLevelWindow()); return true; } else{ return false; } } // Handle closing of the current window function confirmCancel(message) { if (confirm(message)) { getTopLevelWindow().location.href = 'userinfo.jsp'; return true; } else{ return false; } } function cancelQueue(workgroup, chatID){ getTopLevelWindow().location.href = 'userinfo.jsp?workgroup=' + workgroup +'&chatID='+chatID; return true; } function confirmCancelAndClose(message) { if (confirm(message)) { getTopLevelWindow().location.href = 'userinfo.jsp'; getTopLevelWindow().close(); return true; } else{ return false; } } // Handle closing of the current window function confirmCancel(message, workgroup, chatID) { if (confirm(message)) { getTopLevelWindow().location.href = 'userinfo.jsp?workgroup=' + workgroup +'&chatID='+chatID; return true; } else{ return false; } } function closeAll() { removeWindow(getTopLevelWindow().name); closeWin(getTopLevelWindow()); } // Opens the help window: function launchHelpWin() { var win = launchWin('helpwin', 'helpwin.jsp', 550, 350); } // Hide a DIV function hide(divId) { if (document.layers) { document.layers[divId].visibility = 'hide'; } else if (document.all) { document.all[divId].style.visibility = 'hidden'; } else if (document.getElementById) { document.getElementById(divId).style.visibility = 'hidden'; } } // Show a DIV function show(divId) { if (document.layers) { document.layers[divId].visibility = 'show'; } else if (document.all) { document.all[divId].style.visibility = 'visible'; } else if (document.getElementById) { document.getElementById(divId).style.visibility = 'visible'; } } function getDiv(divID) { if (document.layers) { return document.layers[divID]; } else if (document.all) { return document.all[divID]; } else if (document.getElementById) { return document.getElementById(divID); } } function getDivByDoc(divID, doc) { if (doc.layers) { return doc.layers[divID]; } else if (doc.all) { return doc.all[divID]; } else if (doc.getElementById) { return doc.getElementById(divID); } } // TODO function showTypingIndicator(flag) { if (flag) { // put the text in the div } else{ // blank out the div } } function informConnectionClosed() { alert('La sesión ha terminado, usted será redireccionado a la página de transcripción.'); parent.location.href = 'transcriptmain.jsp'; } function addChatText(yakWin, from, text) { // Se reemplazan los controles definidos text = applyFilterMilleObject(applyFilterUtil(text, from)); if(text == "") return; // The div to write to: var yakDiv = yakWin.document.getElementById('ytext'); // This will be an announcement if there is no from passed in var isAnnouncement = (from == ""); // Create a new span node in the yakDiv. Record the num of nodes right now - used later // to see if the node was really added: var numChildren = yakDiv.childNodes.length; var nameSpan = document.createElement("div"); var textSpan = document.createElement("p"); if (isAnnouncement) { nameSpan.setAttribute("class", "chat-announcement"); nameSpan.className="chat-announcement"; textSpan.setAttribute("class", "chat-announcement"); textSpan.className="chat-announcement"; } // add another span containing the username if this is not an announcement: var fromIsCurrentUser = false; // is the from the same as the current user? fromIsCurrentUser = (nickname == from); var chatLineDiv = document.createElement("div"); if (! isAnnouncement) { if (fromIsCurrentUser) { chatLineDiv.setAttribute("class", "msj macro"); chatLineDiv.className="chat-line msj macro"; chatLineDiv.style.display="block"; nameSpan.setAttribute("class", "text-l"); nameSpan.className="text-l"; textSpan.setAttribute("class", "text client-name"); textSpan.className="text client-name"; } else { chatLineDiv.setAttribute("class", "chat-line msj-rta macro"); chatLineDiv.className="chat-line msj-rta macro"; chatLineDiv.style.display="block"; nameSpan.setAttribute("class", "text-r"); nameSpan.className="text-r"; textSpan.setAttribute("class", "text operator-name"); textSpan.className="text operator-name"; } } var appendFailed = false; try { textSpan.innerHTML = text; if (! isAnnouncement) { nameSpan.innerHTML = '' + from + ' ' ; // + '' + new Date().toTimeString().split(' ')[0] + ''; if (fromIsCurrentUser){ chatLineDiv.appendChild(nameSpan); chatLineDiv.appendChild(textSpan); } else { chatLineDiv.appendChild(nameSpan); // Creación de la caja del chat del AGENTE var agentBoxContent = document.createElement("div"); // Imagen del AGENTE var imageBoxContent = document.createElement("div"); imageBoxContent.innerHTML='Smiley face'; // Texto del mensaje del AGENTE var textBoxContent = document.createElement("div"); textBoxContent.style.width="100%"; textBoxContent.appendChild(textSpan); // Se agrega el texto del mensaje /*if($("#ChatTextControl").hasClass("close")) agentBoxContent.appendChild(imageBoxContent); // Imagen a la caja del chat*/ agentBoxContent.appendChild(textBoxContent); // Texo a la caja del chat // Estilos del la caja del chat agentBoxContent.style.display="flex"; imageBoxContent.style.marginRight = "10px"; chatLineDiv.appendChild(agentBoxContent); //chatLineDiv.appendChild(textSpan); } } else { chatLineDiv.appendChild(textSpan); } // Add the message time var timeBox = document.createElement("small"); timeBox.classList.add("text-muted"); timeBox.classList.add("time-msj"); var timeMsj = new Date(); //timeBox.innerHTML = ' ' + timeMsj.getPeriodHours()+':'+timeMsj.getMinutesWithLeadingZeros()+' '+ timeMsj.getPeriod() ; timeBox.innerHTML = ' ' + timeMsj.getPeriodHours()+':'+timeMsj.getMinutesWithLeadingZeros()+' '+ timeMsj.getPeriod() ; chatLineDiv.appendChild( timeBox ); yakDiv.appendChild(chatLineDiv); } catch (exception) { appendFailed = true; } if (! appendFailed) { // Make sure the browser appended: appendFailed = (numChildren == yakDiv.childNodes.length); } if (appendFailed) { var inn = yakDiv.innerHTML; inn += "
"; if (! isAnnouncement) { inn += "" + new Date().toTimeString().split(' ')[0] + ' ' + from + ": "; // yakDiv.innerHTML = inn; } // var inn = yakDiv.innerHTML; inn += "" : "chat_text\">"); inn += text + "
"; yakDiv.innerHTML = inn; } else{ // yakDiv.appendChild(document.createElement("br")); } saveConversationChat($("#ytext", window.parent.frames[0].document).html()); if(yakWin.document.getElementById('dynamicDate') != null) { setFormatDatePicker(dateMin, dateMax, dateFormat); } } function applyFilterMilleObject(bodyMessage) { bodyMessage = bodyMessage.trim(); // CONTROLES TIPO 3, NO HAY ELSE PUES SE VERIFICA CADA UNO DE LOS CONTROLES if(bodyMessage.indexOf("[command.INIT]") != -1) { try { bodyMessage=bodyMessage.replace('[command.INIT]',""); //document.f.chatbox.disabled=true; document.getElementById('typingAgentTEMP').innerHTML = initialAgent + " está escribiendo..."; } catch (exception) { console.log(exception.message); } } if(bodyMessage.indexOf("[command.FIN]") != -1) { try { bodyMessage=bodyMessage.replace('[command.FIN]',""); //document.f.chatbox.disabled=false; document.getElementById('typingAgentTEMP').innerHTML = '' document.f.chatbox.focus(); } catch (exception) { console.log(exception.message); } } // Hyperlinks manipulator var matches = bodyMessage.match(hyperLinkRegex); if( matches!=null && matches.length>0 ){ for( i=0;i').html(bodyMessage.split('[json.list]')[1]).text())[0]; bodyMessage = '' + list.message + ''; bodyMessage += ''; } catch (exception) { console.log(exception.message); } } else if(bodyMessage.indexOf("[json.button]") != -1) { try { var listButton = JSON.parse($('
').html(bodyMessage.split('[json.button]')[1]).text())[0]; bodyMessage = '' + listButton.message + ''; bodyMessage += '
'; $.each(listButton.buttons, function (i, valor) { bodyMessage += '
'; }); bodyMessage += '
'; } catch (exception) { console.log(exception.message); } } else if(bodyMessage.indexOf("[json.input]") != -1 ) { try { var inputButton = JSON.parse($('
').html(bodyMessage.split('[json.input]')[1]).text())[0]; bodyMessage = '' + inputButton.message + ''; bodyMessage += '
'; bodyMessage += '
'; if(inputButton.image != null) { bodyMessage += '
'; } bodyMessage += '
'; } catch (exception) { console.log(exception.message); } } else if(bodyMessage.indexOf("[json.date]") != -1) { try { var inputDate = JSON.parse($('
').html(bodyMessage.split('[json.date]')[1]).text())[0]; bodyMessage = '' + inputDate.message + ''; bodyMessage += '
'; bodyMessage += '
'; bodyMessage += '
'; dateMin = inputDate.min; dateMax = inputDate.max; dateFormat = inputDate.format; } catch (exception) { console.log(exception.message); } } else if(bodyMessage.indexOf("[json.cmd]") != -1 ) { try { var chatCMD = JSON.parse($('
').html(bodyMessage.split('[json.cmd]')[1]).text())[0]; if(chatCMD.command == 'HideChatTextControl') { $("#ChatTextControl").addClass("close"); $("#ChatIVRControl").addClass("open"); hideChatTextControl(true); return ""; } else if(chatCMD.command == 'ShowChatTextControl') { $("#ChatTextControl").removeClass("close"); $("#ChatIVRControl").removeClass("open"); hideChatTextControl(false); return ""; } } catch (exception) { console.log(exception.message); } } // done! return bodyMessage; } // Function to handle text filter application function applyFilters(body) { // Replace ampersands body = body.replace(/&/gi, "&"); // Replace HTML body = body.replace(//gi, ">"); // Replace newlines body = body.replace(/\n/gi, "
"); // text style body = body.replace(/\[b\]/gi, ""); body = body.replace(/\[\/b\]/gi, ""); body = body.replace(/\[i\]/gi, ""); body = body.replace(/\[\/i\]/gi, ""); body = body.replace(/\[u\]/gi, ""); body = body.replace(/\[\/u\]/gi, ""); // Emoticons /* full list -> :) :-) :( :-( :D :x ;\ B-) ]:) :p X-( :^O ;) ;-) :8} :_| ?:| :O :| */ body = body.replace(/\]:\)/gi, ""); body = body.replace(/:\)/gi, ""); body = body.replace(/:-\)/gi, ""); body = body.replace(/:\(/gi, ""); body = body.replace(/:-\(/gi, ""); body = body.replace(/:D/gi, ""); body = body.replace(/:x/gi, ""); body = body.replace(/;\\/gi, ""); body = body.replace(/B-\)/gi, ""); body = body.replace(/:p/gi, ""); body = body.replace(/X-\(/gi, ""); body = body.replace(/:\^O/gi, ""); body = body.replace(/:\^0/gi, ""); body = body.replace(/;\)/gi, ""); body = body.replace(/;-\)/gi, ""); body = body.replace(/:8\}/gi, ""); body = body.replace(/:_\|/gi, ""); body = body.replace(/\?:\|/gi, ""); body = body.replace(/:O/gi, ""); body = body.replace(/:0/gi, ""); body = body.replace(/:\|/gi, ""); // done! return body; } //Cambia los parámetros de configuración de los objetos DatePicker de JQuery function setFormatDatePicker(min, max, format) { window.frames['yak'].setFormatDatePicker(min, max, format); return; } function handleCustomList(idList) { if(idList.value !== undefined && idList.value !== ''){ document.f.chatbox.value = idList.options[idList.selectedIndex].text; $("#dynamicList", window.parent.frames[0].document).remove(); submitMessage(); } return; } function handleCustomButton(idButton) { document.f.chatbox.value = idButton.innerHTML; $("#dynamicButton", window.parent.frames[0].document).remove(); submitMessage(); return; } function handleCustomInput(event) { if(event.keyCode==13) { document.f.chatbox.value = event.currentTarget.value; $("#dynamicInput", window.parent.frames[0].document).remove(); submitMessage(); return true; } else if(event.charCode >= 48 && event.charCode <= 57) { return true; } return false; } function handleCustomDate(date) { document.f.chatbox.value = date; $("#dynamicDate", window.parent.frames[0].document).remove(); submitMessage(); return; } function processMessages() { if(!inProcessStack && stackMessages.length > 0) { inProcessStack = true; try { var allStackMessages = stackMessages.slice(0); allStackMessages.forEach(function(message) { stackMessages.shift(); addChatText(window.frames['yak'], message.from, message.body); }); } catch(exception){ } finally { inProcessStack = false; } } } function applyFilterUtil(bodyMessage, agentName) { bodyMessage = bodyMessage.trim(); if(bodyMessage.indexOf("[UserName]") != -1) { bodyMessage = bodyMessage.split('[UserName]').join(nickname); } if(bodyMessage.indexOf("[UserFirstName]") != -1) { bodyMessage = bodyMessage.split('[UserFirstName]').join(nickname.split(" ", 2)[0]); } if(bodyMessage.indexOf("[TimeGreeting]") != -1) { var time = new Date().getHours(); if (time < 12) bodyMessage = bodyMessage.split('[TimeGreeting]').join('Buenos días'); else if (time < 20) bodyMessage = bodyMessage.split('[TimeGreeting]').join('Buenas tardes'); else bodyMessage = bodyMessage.split('[TimeGreeting]').join('Buenas noches'); } if(bodyMessage.indexOf("[AgentName]") != -1) { bodyMessage = bodyMessage.split('[AgentName]').join(agentName); } return bodyMessage; } function scrollYakToEnd(yakWin) { try { setTimeout(function () { $(yakWin.document.body).animate({ scrollTop: $(yakWin.document.body)[0].scrollHeight }); }, 100); } catch(exception) { console.log(exception.message); } } function validateDevice(workgroup) { var gotoURL = ""; gotoURL = "https://chat.ccc.org.co:8443/ccc/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href; return gotoURL; } function showChatButton(workgroup) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "https://chat.ccc.org.co:8443/ccc/live?action=isAvailable&workgroup=" + workgroup; var gotoURL = "https://chat.ccc.org.co:8443/ccc/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href; document.write( "
"); } function showChatButtonSamePage(workgroup) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "https://chat.ccc.org.co:8443/ccc/live?action=isAvailable&workgroup=" + workgroup; var gotoURL = validateDevice(workgroup); document.write(""); } function displayWorkgroup(workgroup,online,offline) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "https://chat.ccc.org.co:8443/ccc/live?action=isAvailable&workgroup=" + workgroup +"&online="+ online + "&offline="+offline; var gotoURL = "https://chat.ccc.org.co:8443/ccc/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href; document.write( ""); } function showChatButtonWithAgent(workgroup, agent) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "https://chat.ccc.org.co:8443/ccc/live?action=isAvailable&workgroup=" + workgroup; var gotoURL = "https://chat.ccc.org.co:8443/ccc/start.jsp?workgroup=" + workgroup + "&agent=" + agent + "&location=" + window.location.href; document.write(""); } function showButtonWithoutUI(workgroup, params){ var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "https://chat.ccc.org.co:8443/ccc/live?action=isAvailable&workgroup=" + workgroup; var gotoURL = "https://chat.ccc.org.co:8443/ccc/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href + "&noUI=true&"+params; document.write(""); }