/gi, '');
// html = html.replace(/
/gi, '');
// html = html.replace(/<\/p>/ig, '\n');
// html = html.replace(/ /gi, "\n");
// html = html.replace(/ ]+>/ig, '');
// return html;
// }
PrintElem2Printer = function (elem) {
try {
if (sessionStorageGet('chattext') != "") { // ektiposi mono an iparxei keimeno
document.getElementById("onwebchat-widget-settings-submenu-ul").style.setProperty("display", "none");
// Popup2Print($ (elem).html());
Popup2Print(document.getElementById(elem).innerHTML);
}
} catch (e) { console.log(e); }
}
Popup2Print = function (data) {
var mywindow = window.open('', 'onWebChat live chat - Print ', 'height=700,width=920');
mywindow.document.write('
Chat transcript from ' + extractDomain(window.location.href) + ' ');
mywindow.document.write('');
//mywindow.document.write('');
mywindow.document.write('
');
mywindow.document.write(data);
mywindow.document.write('');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
function download(filename, text) {
// if (logging) console.log("download is run 1.. isIE?:" + isIE());
// // if (logging) console.log("navigator.userAgent:"+navigator.userAgent);
var pom = document.createElement('a');
var DownloadAttributeSupport = 'download' in pom;
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
//var event = document.createEvent('MouseEvents');
//event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); //depreciated
var event = new MouseEvent("click", { view: window, bubbles: true, cancelable: true, clientX: 0, });
pom.dispatchEvent(event);
} else {
pom.click();
}
}
okButtonClicked = function () {
// to ok koumpi tis offline formas
// // if (logging) console.log("ok pressed");
socket.emit('chatWindowMax', 0);
minimizeChatWindow();
}
uploadFilePressed = function () {
// if (logging) console.log("uploadFilePressed..");
if (document.getElementById("uploadfileid").style.opacity > 0.9) { // elegxo an to exo kanei disabled to menu item uploadfileid (me tin disableMenuItem)
//$ ('#onwbchtFileinput').trigger('click');
document.getElementById('onwbchtFileinput').click();
if ((isConnected == false) && (tryToReconnect == false)) { // auto gia na diorthoso to bug, otan itan disconnect kai pige apeutheias o visiotr na steilei eikona, den itan connected k den estelne
// if (logging) console.log(" isConnected = false , so try to connect now..")
socketReconnect();
}
}
}
if (sessionStorageGet('chattext') != undefined && sessionStorageGet('chattext') != "") { // an iparxei keimeno energopoio tin epilogi "ektiposi" kai "save"
// if (logging) { console.log("chattext:" + sessionStorageGet('chattext')); }
enableMenuItem("onwebchat-print-li");
enableMenuItem("onwebchat-savetofile-li");
if (emailsSentLastHour < 6) {
enableMenuItem("onwebchat-email-li");
}
enableMenuItem('onwebchat-endchat-li');
endChatButtonEnabled = true;
//addEndChat2Menu();
}
var dragCounter = 0;
var dropArea = document.getElementById('onwbchat_window');
var uploadImgDiv = document.getElementById('upload_img');
dropArea.addEventListener('dragenter', function (e) {
// // if (logging) console.log("drag enter..");
document.getElementById('upload_img_id').src = "https://www.onwebchat.com/operator/assets/images/drop-file.png";
dragCounter++;
if ((isAbleToWrite == true) && (menu_use == 1) && (show_upload_file_menu == 1) && (nowIsShowing == 'chat')) {
dropArea.style.filter = "brightness(55%)";
uploadImgDiv.style.display = "block";
}
e.preventDefault();
}, false)
dropArea.addEventListener('dragleave', function (e) {
// // if (logging) console.log("drag leave..");
dragCounter--;
if (dragCounter == 0) {
dropArea.style.filter = "brightness(100%)";
uploadImgDiv.style.display = "none";
}
e.preventDefault();
}, false)
dropArea.addEventListener('dragover', function (e) {
// // if (logging) console.log("drag over..");
e.preventDefault();
}, false)
dropArea.addEventListener('drop', function (e) {
// // if (logging) console.log("drop..");
dragCounter = 0;
var dt = e.dataTransfer;
var files = dt.files;
// // if (logging) console.log("files:" + files);
// // if (logging) console.log(files);
dropArea.style.filter = "brightness(100%)";
uploadImgDiv.style.display = "none";
e.preventDefault();
// if (logging) console.log("isAbleToWrite:" + isAbleToWrite + " nowIsShowing:" + nowIsShowing);
if ((isAbleToWrite == true) && (menu_use == 1) && (show_upload_file_menu == 1) && (nowIsShowing == 'chat')) {
if (validateFileSizeType(files[0], 0)) {
var formData = new FormData();
formData.append('file', files[0]);
formData.append('siteid', siteId);
sendFileToServer(formData);
}
}
}, false)
// $ ("#onwbchtUploadFormXXX").submit(function (e) {
// // if (logging) console.log("onwbchuploadForm 1");
// //var formObj = //$ (this); //
// //var formURL = formObj.attr("action");
// var formData = new FormData(this);
// //console.log(formData);
// //console.log("formURL:" + formURL);
// sendFileToServer(formData);
// e.preventDefault(); //Prevent Default action.
// //e.unbind();
// });
function onwbchtUploadFormFunction(){
// if (logging) console.log("onwbchuploadForm 1");
//var formObj = //$ (this); //
//var formURL = formObj.attr("action");
//var formData = new FormData(this);
var formData = new FormData(document.getElementById("onwbchtUploadForm"));
//console.log(formData);
//console.log("formURL:" + formURL);
if ((menu_use == 1) && (show_upload_file_menu == 1)) {
sendFileToServer(formData);
}
//e.preventDefault(); //Prevent Default action.
//e.unbind();
}
function httpPost(url, formDataTemp, error, callback) {
var elements = document.getElementsByClassName("formVal");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200 || (xhr.status === 0 && xhr.responseText !== '')) {
callback({
url: url,
status: 200,
body: xhr.responseText || ''
});
}
else {
error({
url: url,
status: xhr.status,
body: xhr.responseText || ''
});
}
}
}
xhr.open("post", url, true);
xhr.send(formDataTemp);
}
sendFileToServer = function (formData) {
httpPost( '' + protocol + '//' + serverIP + '/chat_upload_file/url', formData,
function (param) { // error sending file
// if (logging) console.log("error sending file, url:" + param.url + " status:" + param.status ); // + " body:" + param.body);
console.log('Error sending file: ' + param.status);
},
function (param) { // send file successfully
// if (logging) console.log("url:" + param.url + " status:" + param.status);
// if (logging) console.log("server response: " + param.body + " textStatus:" + param.status);
//var imgLoading = $ ("#onwbchat_window img[src$='loading.gif']"); // ta epistrefei ola an einai polla, ara ta antikathista ola
//var imgLoading = document.getElementsByClassName('onweb_uploadfile')[0];
var imgLoading = document.querySelectorAll('img[src$="loading.gif"][class="onweb_uploadfile"]')[0];
//console.log("img...");
//console.log(imgLoading);
var imgsrc;
var data = param.body;
var fileUrl = data.substring(data.indexOf(":") + 1); // afero to 'ok file uploaded to:' kai menei to file url
// if (logging) console.log("fileUrl:" + fileUrl);
if (fileUrl.toLowerCase().endsWith(".png") || (fileUrl.toLowerCase().endsWith(".jpg")) || (fileUrl.toLowerCase().endsWith(".jpeg")) || (fileUrl.toLowerCase().endsWith(".svg")) || (fileUrl.toLowerCase().endsWith(".gif"))) {
imageNumberId++;
//imgsrc = imgLoading.attr("src").replace("chatimages/loading.gif", "filesUpload/" + encodeURI(fileUrl));
imgsrc = imgLoading.src.replace("chatimages/loading.gif", "filesUpload/" + encodeURI(fileUrl));
//imgLoading.css("max-width", "150px");
imgLoading.style.maxWidth = "198px"; // max-width: 198px;
//imgLoading.css("max-height", "70px");
imgLoading.style.maxHeight = "110px"; // max-height: 110px;
imgLoading.style.borderRadius = "9px"; // border-radius: 9px;
imgLoading.style.overflow = "auto"; // overflow: auto;
// otan allazei selida i sto refresh na min deixnei to loading..
sessionStorageSet('chattext', sessionStorageGet('chattext').replace('
', "
"));
//$ ('#onwbchat_window .chat_area').animate({ scrollTop: 999999999 }, 200);
// my_animate(document.getElementById("chat_area_id"), 999999999, 999999999, 1);
// setTimeout(function () { my_animate(document.getElementById("chat_area_id"), 999999999, 999999999, 1); }, 1000); //mono me to pano den douleue panta..
my_animate2(document.getElementById("chat_area_id"), 20, 1);
setTimeout(function () { my_animate2(document.getElementById("chat_area_id"), 20, 1); }, 500); //mono me to pano den douleue panta..
setTimeout(function () { my_animate2(document.getElementById("chat_area_id"), 20, 1); }, 1000); //mono me to pano den douleue panta..
//imgLoading.attr("src", imgsrc);
imgLoading.src = imgsrc;
//imgLoading.wrap("
"); // to encodeURI to evala giati px otan anevaze eikona me keno sto onoma , den epeze to link sto chat window..
var link = document.createElement("a");
link.innerHTML = imgLoading.outerHTML;
link.setAttribute('href', protocol + "//" + serverIP + "/filesUpload/" + encodeURI(fileUrl) );
link.setAttribute('target', '_blank' );
link.setAttribute('rel', 'noopener noreferrer' );
imgLoading.parentNode.insertBefore(link, imgLoading);
imgLoading.remove();
} else { // not image
//imgsrc = imgLoading.attr("src").replace("loading.gif", "download-icon.png");
imgsrc = imgLoading.src.replace("loading.gif", "download-icon.png");
var filename = fileUrl.replace(/^.*[\\\/]/, '');
//imgLoading.attr("src", imgsrc);
imgLoading.src = imgsrc;
//imgLoading.wrap("
"); // to encodeURI to evala giati px otan anevaze eikona me keno sto onoma , den epeze to link sto chat window..
var link = document.createElement("a");
link.innerHTML = imgLoading.outerHTML;
link.setAttribute('href', protocol + "//" + serverIP + "/filesUpload/" + encodeURI(fileUrl) );
link.setAttribute('target', '_blank' );
link.setAttribute('rel', 'noopener noreferrer' );
imgLoading.parentNode.insertBefore(link, imgLoading);
var parent = imgLoading.parentNode;
imgLoading.remove();
var child = document.createElement("span");
child.innerHTML = filename;
parent.appendChild(child);
// otan allazei selida i sto refresh na min deixnei to loading..
sessionStorageSet('chattext', sessionStorageGet('chattext').replace('
', "
" + filename + " "));
}
endTime = getCurrentTime();
obj={};
obj.vesrion = version;
obj.durationInSeconds = (endTime - startTime) / 1000;
obj.socketDurationInSeconds = (endTime - startConnectTime) / 1000;
obj.isConnected = isConnected;
obj.firstConnection = firstConnection;
obj.timeoutTime_userconnect = timeoutTime_userconnect;
obj.tryToReconnect = tryToReconnect;
obj.pos = 3244;
//obj.sendChatDelay = sendChatDelay;
if (sessionStorageGet('chattext')){
obj.chattext = sessionStorageGet('chattext').substring(0,20);
}
let sendChatDelay = 0;
if (!isConnected){
sendChatDelay = 5400;
if ((isConnected == false) && (tryToReconnect == false)) {
// if (logging) console.log("isConnected = false! Try to connect now...")
obj.socketReconnect = 1;
socketReconnect();
}
}
///
setTimeout(function () {
endTime = getCurrentTime();
obj.durationInSeconds2 = (endTime - startTime) / 1000;
obj.socketDurationInSeconds2 = (endTime - startConnectTime) / 1000;
obj.isConnected2 = isConnected;
obj.tryToReconnect2 = tryToReconnect;
obj.firstConnection2 = firstConnection;
obj.timeoutTime_userconnect2 = timeoutTime_userconnect;
obj.sendChatDelay = sendChatDelay;
obj.pos = 3244;
socket.emit('sendchat', '{{fileuploaded:' + fileUrl + '}}', undefined, 0, 0, 3244, num_connected, clientId, secretKey, obj);
callbackOnNewMessage("{{fileuploaded:" + fileUrl + "}}", "visitor");
}, sendChatDelay); // to dialogid den to apothikeuo topika , to vrisko ston server apo to socketsession
///
}
);
// $.ajax({
// url: '' + protocol + '//' + serverIP + '/chat_upload_file/url',
// type: 'POST',
// data: formData,
// mimeType: "multipart/form-data",
// contentType: false,
// cache: false,
// processData: false,
// success: function (data, textStatus, jqXHR) {
// // if (logging) console.log("server response: " + data + " textStatus:" + textStatus);
// var imgLoading = //$ ("#onwbchat_window img[src$='loading.gif']"); // ta epistrefei ola an einai polla, ara ta antikathista ola
// var imgsrc;
// var fileUrl = data.substring(data.indexOf(":") + 1); // afero to 'ok file uploaded to:' kai menei to file url
// // if (logging) console.log("fileUrl:" + fileUrl);
// if (fileUrl.toLowerCase().endsWith(".png") || (fileUrl.toLowerCase().endsWith(".jpg")) || (fileUrl.toLowerCase().endsWith(".jpeg")) || (fileUrl.toLowerCase().endsWith(".svg")) || (fileUrl.toLowerCase().endsWith(".gif"))) {
// imageNumberId++;
// imgsrc = imgLoading.attr("src").replace("chatimages/loading.gif", "filesUpload/" + encodeURI(fileUrl));
// imgLoading.css("max-width", "150px");
// imgLoading.css("max-height", "70px");
// // otan allazei selida i sto refresh na min deixnei to loading..
// sessionStorageSet('chattext', sessionStorageGet('chattext').replace('
', "
"));
// //$ ('#onwbchat_window .chat_area').animate({ scrollTop: 999999999 }, 200);
// my_animate(document.getElementById("chat_area_id"), 999999999, 999999999, 1);
// //setTimeout(function () { //$ ('#onwbchat_window .chat_area').animate({ scrollTop: 999999999 }, 200); }, 1000); //mono me to pano den douleue panta..
// setTimeout(function () { my_animate(document.getElementById("chat_area_id"), 999999999, 999999999, 1); }, 1000); //mono me to pano den douleue panta..
// imgLoading.attr("src", imgsrc);
// imgLoading.wrap("
"); // to encodeURI to evala giati px otan anevaze eikona me keno sto onoma , den epeze to link sto chat window..
// } else { // not image
// imgsrc = imgLoading.attr("src").replace("loading.gif", "download-icon.png");
// var filename = fileUrl.replace(/^.*[\\\/]/, '');
// imgLoading.attr("src", imgsrc);
// imgLoading.wrap("
"); // to encodeURI to evala giati px otan anevaze eikona me keno sto onoma , den epeze to link sto chat window..
// imgLoading.parent().append("
" + filename + " ");
// // otan allazei selida i sto refresh na min deixnei to loading..
// sessionStorageSet('chattext', sessionStorageGet('chattext').replace('
', "
" + filename + " "));
// }
// socket.emit('sendchat', '{{fileuploaded:' + fileUrl + '}}');
// callbackOnNewMessage("{{fileuploaded:" + fileUrl + "}}", "visitor");
// },
// error: function (jqXHR, textStatus, errorThrown) {
// console.log('Error: ' + jqXHR.status + errorThrown);
// }
// });
}
/*
//$ ('.onwebchat-widget-settings-icon').click(function() {
//$ ('.onwebchat-widget-settings-submenu').toggle();
});
*/
//$ ('.onwebchat-widget-settings-icon').click(function (event) {
if (document.getElementById('onwc-settings-icon-id')) document.getElementById('onwc-settings-icon-id').onclick = function(event){
event.stopPropagation();
//$ ('#onwebchat-emoticons-div').hide(); // an einai anoixta ta emoticons na ta kleiso
myHide2(document.getElementById('onwebchat-emoticons-div')); // oxi tin myHide edo - provlima
//$ ('.onwebchat-widget-settings-submenu').fadeToggle(240, "swing");
myFadeToggle(document.getElementById('onwebchat-widget-settings-submenu-ul'));
//$ ('#onwebchat-emoticons-div').fadeToggle(240, "swing"); // to fadeToggle den iparxei sto jquery slim... (opote iparxei provlima sta site pou fortonoun to slip, opos se ola ta wordpress sites)
//$ ("
").attr("src",protocol+'//'+serverIP+'/chatimages/volume-icon-off.png'); // preload image (gia na min kathisterei)
//$ ("
").attr("src",protocol+'//'+serverIP+'/chatimages/volume-icon-2.png'); // preload image (gia na min kathisterei)
};
//$ ('#wb-smile-image').click(function (event) {
document.getElementById('wb-smile-image').onclick = function(event){
event.stopPropagation();
//loadEmoticons(); // fortono ta emoticons an den ta exo idi fortosei..
//$ ('#onwebchat-emoticons-div').fadeToggle(240, "swing"); //linear
myFadeToggle(document.getElementById('onwebchat-emoticons-div'));
//document.getElementById("onwebchat-widget-settings-submenu-ul").style.setProperty("display", "none");
myHide(document.getElementById('onwebchat-widget-settings-submenu-ul'));
if ((isConnected == false) && (tryToReconnect == false)) { // auto gia na diorthoso to bug, otan itan disconnect kai pige apeutheias o visiotr na steilei emoticon, den itan connected k den estelne
// if (logging) console.log(" isConnected = false , so try to connect now..")
socketReconnect();
}
};
var fadeTimout;
function myFadeToggle(elem) {
// // if (logging) console.log("myFadetoggle...");
if (elem) {
if (elem.classList.contains('onwc-show')) {
// // if (logging) console.log("myFadetoggle... contains once-show");
elem.classList.remove('onwc-show');
elem.classList.add('onwc-hide');
fadeTimout = setTimeout(function () { elem.style.setProperty("display", "none") }, 400);
} else {
// // if (logging) console.log("myFadetoggle...not contains onwc-show (hide)...");
clearTimeout(fadeTimout);
elem.style.setProperty("display", "block");
setTimeout(function () {
elem.classList.remove('onwc-hide');
elem.classList.add('onwc-show');
}, 0);
}
}
}
function myHide(elem){
// // if (logging) console.log("myHide... elem:" + elem);
if (elem && elem.classList.contains('onwc-show')) {
// // if (logging) console.log("myHide... contains once-show");
elem.classList.remove('onwc-show');
elem.classList.add('onwc-hide');
fadeTimout = setTimeout(function(){ elem.style.setProperty("display", "none"); }, 400);
}
}
function myHide2(elem){ // giati me tin myHide, eixa provlima, otan patousa sta emotiocons kai amesos meta sto settings (eno den fainontan ta emoticons , mporouses na ta patiseis..)
if (elem) {
elem.classList.remove('onwc-show');
elem.classList.add('onwc-hide');
setTimeout(function(){ elem.style.setProperty("display", "none"); }, 400);
}
}
//$ (document).on("click", function () {
document.addEventListener("click", function(event) {
// if (logging) console.log(" document on click..");
// if //($ (".onwebchat-widget-settings-submenu").css('display') != 'none')
// //$ (".onwebchat-widget-settings-submenu").fadeToggle(240, "swing");
//if (//$ ("#onwebchat-widget-settings-submenu-ul").css('opacity') == '1')
if (document.getElementById("onwebchat-widget-settings-submenu-ul") && document.getElementById("onwebchat-widget-settings-submenu-ul").classList.contains('onwc-show') == '1')
myFadeToggle(document.getElementById('onwebchat-widget-settings-submenu-ul'));
//$ ('#onwebchat-emoticons-div').hide();
if (document.getElementById("onwebchat-emoticons-div").classList.contains('onwc-show') == '1')
myFadeToggle(document.getElementById('onwebchat-emoticons-div'));
//document.getElementById('onwebchat-emoticons-div').classList.add('onwc-hide');
//document.getElementById('onwebchat-emoticons-div').classList.remove('onwc-show');
//$ ('#onwebchat-emoticons-div').fadeToggle(240, "swing");
});
//$ ("#onwebchat-volume-li-id").click(function () {
if (document.getElementById('onwebchat-volume-li-id')){
document.getElementById('onwebchat-volume-li-id').onclick = function (event) {
if (soundOn == true) {
// if (logging) console.log("sound off");
//$ ("#wb-volume-text-id").html(getText('menu_sound', language));
soundOn = false;
//setCookie("onwbchtSound", 0, 93);
localStorageSet("onwbchtSound", 0);
//document.getElementById('onwebchat-volume-icon').classList.replace('onwbchtvolume-icon-2', 'onwbchtvolume-icon-off');
document.getElementById('onwebchat-volume-icon').innerHTML = volumeOffPath;
}
else {
// if (logging) console.log("sound on");
//$ ("#wb-volume-text-id").html(getText('menu_sound', language));
soundOn = true;
//setCookie("onwbchtSound", 1, 93);
localStorageSet("onwbchtSound", 1);
//document.getElementById('onwebchat-volume-icon').classList.replace('onwbchtvolume-icon-off', 'onwbchtvolume-icon-2');
document.getElementById('onwebchat-volume-icon').innerHTML = volumeOnPath;
}
};
}
if (soundOn == false) { // timi molis fortosei i selida (apo to cookie)
//$ ("#wb-volume-text-id").html(getText('menu_sound', language));
//document.getElementById('onwebchat-volume-icon').classList.replace('onwbchtvolume-icon-2', 'onwbchtvolume-icon-off');
document.getElementById('onwebchat-volume-icon').innerHTML = volumeOffPath;
}
//$ ('.onwebchat-widget-settings-icon').click(function(event) {
// event.stopPropagation(); // This is the preferred method.
// return false; // This should not be used unless you do not want
// // any click events registering inside the div
//});
//$ (".onwebchat-widget-settings-submenu").on("click", function (event) {
if (document.getElementById("onwebchat-widget-settings-submenu-ul"))
document.getElementById("onwebchat-widget-settings-submenu-ul").addEventListener("click", function (event) {
event.stopPropagation();
});
//$ ("#onwebchat-emoticons-div").on("click", function (event) {
document.getElementById("onwebchat-emoticons-div").addEventListener("click", function(event){
event.stopPropagation(); // gia na min kleinei to emoticons div , otan patao mesa sto div alla oxi pase se ena emoticon
});
//$ ('.widget-settings-icon').hover(function(){
// //alert("Settings was clicked.");
// //$ ('.widget-settings-submenu').css('visibility', 'visible');
//});
//
//$ ('.widget-settings-icon').bind('mouseover',function(){
// //$ ('.widget-settings-submenu').css('visibility', 'hiden');
//});
//$ ("#operatorImage").error(function () { // an den vrei to operatorImage (hide broken image icon)
// // if (logging) console.log(" den vrika to operatorImage");
//$ (this).hide();
// });
//if (modern == 1) { // sto modern to header height einai diaforetiko otan einai min apo otan einai max.
//$ (".webchat_header").css("height", "40px");
document.getElementById("webchat_header").style.setProperty("height", "40px", "important");
document.getElementById("onwbchat_window").style.setProperty("height", "40px", "important");
document.getElementById("div_chat_min_title").style.setProperty("line-height", "42px", "important");
document.getElementById("onwbchat_window").style.setProperty("box-shadow", "0px 0px 5px 0px #777", "important");
//}
if (image_use == 1 || isMobile) { // eimai mesa sto function runWhenLoadAllFiles()
if (isMobile)
imageClass = "onweb_chatimage_mobile";
else
imageClass = "onweb_chatimage";
//if (agentOnline == 1)
var imageUrl = protocol + '//' + serverIP + '/chatWidgetImages/' + image_name;
//if ($ (".onwebchatbox") != undefined) {
var on_id = document.getElementById('onwbchat_window');
if (on_id) {
on_id.insertAdjacentHTML("afterend", '
');
//$ (".onwebchatbox").after('
');
if (showChatApi == 0) { // den dixno tin eikona an exo thesei me to api: set('show',0)
if (document.getElementById("onweb_chatimage")) document.getElementById("onweb_chatimage").style.setProperty("display", "none");
}
// sto alt="chat with us" to evgala, giati sto firefox fainotan asxima gia ligo , otan fortone
}
if (agentOnline == 0 && hideOffline == 1) { // otan den einai kaneis agent online kai den thelo na emfanizo to offline, form tote na min fainetai to
//image 11/7/19 (prin to valo auto otan oloi itan offline kai den xris. to offline form , emfanizotan mono i eikona gia poli ligo k meta exafanizotan (flickering))
if (document.getElementById("onweb_chatimage")) document.getElementById("onweb_chatimage").style.setProperty("display", "none");
}
//$ ("#onweb_chatimage").load(function() { // prepei na ginei load gia na exo sosta to $ ("#onweb_chatimage").height()
onweb_chatimage_loaded = function () {
////$ (".onwebchatbox").append('
');
//$ (".onwebchatbox").append('
');
document.getElementById('onwbchat_window').insertAdjacentHTML('beforeend', '
');
//var xleft = parseInt(document.getElementById("onweb_chatimage").style.getPropertyValue("left")); // gia na vgalo to px vazo to parseint
var xleft = parseInt(window.getComputedStyle(document.getElementById("onweb_chatimage"),null).getPropertyValue("left"));
xleft = xleft + parseInt(document.getElementById('onweb_chatimage').clientWidth) - 4;
//xleft = xleft+0;
document.getElementById("onweb_chatimage_x").style.setProperty("left", xleft+"px");
var xbot = parseInt(window.getComputedStyle(document.getElementById("onweb_chatimage"),null).getPropertyValue("bottom")) + parseInt(document.getElementById('onweb_chatimage').clientHeight) - 4;
document.getElementById("onweb_chatimage_x").style.setProperty("bottom", xbot+"px");
//$ (".onwebchatbox").mouseleave(function () {
document.getElementById('onwbchat_window').onmouseleave = function(){
document.getElementById('onweb_chatimage_x').style.visibility = 'hidden';
}
//$ (".onweb_chatimage_x").mouseleave(function () {
document.getElementById('onweb_chatimage_x').onmouseleave = function(){
document.getElementById('onweb_chatimage_x').style.opacity = '0.5';
}
//$ (".webchat_header").mouseenter(function () {
document.getElementById('webchat_header').onmouseenter = function(){
document.getElementById('onweb_chatimage_x').style.visibility = 'hidden';
}
//$ ('#onweb_chatimage_x').click(
document.getElementById('onweb_chatimage_x').onclick = function () {
document.getElementById("onweb_chatimage").style.setProperty("display", "none");
//$ (".onweb_chatimage_x").css("display", "none");
document.getElementById('onweb_chatimage_x').style.display = "none";
sessionStorageSet('hideImage', 1);
}
};
// if (logging) console.log("imageurl:" + imageUrl);
}
/*if (image_use==1 && !sessionStorage.hideImage) {
var imageUrl = protocol+'//'+serverIP+'/chatimages/press_here_en.png';
var imDim = "widht=153 height=82";
if (language == 'gr') {
imageUrl = protocol+'//'+serverIP+'/chatimages/press_here_gr.png';
imDim = "widht=152 height=98";
}
//$ (".onwebchatbox").append('
' +
'
'+
' '+
' ' );
}*/
//$ ('#onwcmap1').css("cursor", "pointer");
// an emfanizontai kai ta 3 fields, mikraino ligo ta kena, margins
/* function ////checkOfflineMargins(){
if (show_offline_name_field==1 && show_offline_email_field==1 && show_offline_phone_field==1){
document.getElementById("onwebchatoffname").style.setProperty("margin", "11px auto 7px", "important");
document.getElementById("onwebchatoffemail").style.setProperty("margin", "11px auto 7px", "important");
document.getElementById("onwebchatofftel").style.setProperty("margin", "11px auto 7px", "important");
document.getElementById("offlineform_btn").style.setProperty("margin", "23px auto 20px", "important");
}
}*/
/*function checkPrechatMargins(){
// if (show_prechat_name_field==1 && show_prechat_email_field==1 && show_prechat_phone_field==1){
// document.getElementById("onprechatname").style.setProperty("margin", "11px auto 7px", "important");
// document.getElementById("onprechatemail").style.setProperty("margin", "11px auto 7px", "important");
// document.getElementById("onprechattel").style.setProperty("margin", "11px auto 7px", "important");
// document.getElementById("prechat_btn").style.setProperty("margin", "23px auto 20px", "important");
// }
}*/
// checkOfflineMargins();
// checkPrechatMargins();
//$ ('#offlineform_btn').click( // send offline message
document.getElementById('offlineform_btn').onclick = function () {
// if (logging) console.log(" mandatory_offline_email_field: " + mandatory_offline_email_field + " show_offline_phone_field:" + show_offline_phone_field);
if ((consent_use == 1 && show_consent_checkbox == 1 && document.getElementById("onwc_consent_checkbox_offline").checked == false) ||
(show_offline_email_field == 1 && mandatory_offline_email_field == 1 && !validateEmail(document.getElementById("onwebchatoffemail").value)) ||
(show_offline_phone_field == 1 && mandatory_offline_phone_field == 1 && document.getElementById("onwebchatofftel").value.length < 4) ||
(show_offline_name_field == 1 && mandatory_offline_name_field == 1 && document.getElementById("onwebchatoffname").value.length < 2) ||
//$ ("textarea#onwebchatemailtext").val().length < 1) {
document.getElementById("onwebchatemailtext").value.length < 1) {
// den stelnetai to minima (kati leipei!)
if (consent_use == 1 && show_consent_checkbox == 1 && document.getElementById("onwc_consent_checkbox_offline").checked == false) {
document.getElementById("onwc_consent_l_offline_span").style.setProperty("color", "#D04848", "important");
}
if (document.getElementById("onwebchatemailtext").value.length < 1) {
//$ ("textarea#onwebchatemailtext").focus();
document.getElementById("onwebchatemailtext").focus();
document.getElementById("onwebchatemailtext").style.setProperty("border", "1px solid #D04848", "important");
}
if (show_offline_phone_field == 1 && mandatory_offline_phone_field == 1 && document.getElementById("onwebchatofftel").value.length < 4) {
document.getElementById("onwebchatofftel").focus();
setTimeout(function () { document.getElementById("onwebchatofftel").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
//checkOfflineMargins();
checkBottomOfButton();
}
if (show_offline_email_field == 1 && mandatory_offline_email_field == 1 && !validateEmail(document.getElementById("onwebchatoffemail").value)) {
document.getElementById("onwebchatoffemail").focus();
setTimeout(function () { document.getElementById("onwebchatoffemail").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
//checkOfflineMargins();
checkBottomOfButton();
}
if (show_offline_name_field == 1 && mandatory_offline_name_field == 1 && document.getElementById("onwebchatoffname").value.length < 2) {
document.getElementById("onwebchatoffname").focus();
setTimeout(function () { document.getElementById("onwebchatoffname").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
//checkOfflineMargins();
checkBottomOfButton();
}
return false;
} else {
// // if (logging) console.log("now will send the offline email " + document.getElementById("onwebchatoffname").value + " name: " + document.getElementById("onwebchatoffname").value);
var conboxv = -1;
if (document.getElementById("onwc_consent_checkbox_offline"))
conboxv = document.getElementById("onwc_consent_checkbox_offline").value;
// if (conboxv == true){
// setCookie("consentv", 2, 93); // to theto gia na min to zitao kathe fora (meta apo 3 mines to zitao pali)
// }
// // if (logging) console.log('clientip='+client_ip+'&clientid='+clientId+'&sid='+siteId+'&name='+//$ ("input#onwebchatoffname").val()+'&email='+//$ ("input#onwebchatoffemail").val()+'&text='+//$ ("textarea#onwebchatemailtext").val()+'&phone='+//$ ("input#onwebchatofftel").val());
var formData2 = new FormData();
//formData2.append('data', 'clientip=' + client_ip + '&clientid=' + clientId + '&sid=' + siteId + '&name=' +document.getElementById("onwebchatoffname").value + '&email=' +document.getElementById("onwebchatoffemail").value + '&text=' +document.getElementById("onwebchatemailtext").value + '&phone=' +document.getElementById("onwebchatofftel").value + '&conboxv=' + conboxv + '&conuse=' + consent_use + '&conboxshow=' + show_consent_checkbox);
formData2.append('clientip', client_ip);
formData2.append('clientid', clientId);
formData2.append('sid', siteId);
formData2.append('name', '');
formData2.append('email', '');
formData2.append('text', '');
formData2.append('phone', '');
if (document.getElementById("onwebchatoffname"))
formData2.append('name', document.getElementById("onwebchatoffname").value);
if (document.getElementById("onwebchatoffemail"))
formData2.append('email', document.getElementById("onwebchatoffemail").value);
if (document.getElementById("onwebchatemailtext"))
formData2.append('text', document.getElementById("onwebchatemailtext").value);
if (document.getElementById("onwebchatofftel"))
formData2.append('phone', document.getElementById("onwebchatofftel").value);
formData2.append('conboxv', conboxv);
formData2.append('conuse', consent_use);
formData2.append('conboxshow', show_consent_checkbox);
// // if (logging) console.log(formData2);
// var body = {
// "clientip": 78912,
// "body.clientid": "333",
// "request.body.name": 1,
// "email": 18.00
// };
// body = JSON.stringify(body);
//if (clientid==undefined) clientid=23234;
var offlineEmail = ""
var offlineName = ""
var offlineText = ""
var offlinePhone = ""
if (document.getElementById("onwebchatoffname"))
offlineName = document.getElementById("onwebchatoffname").value;
if (document.getElementById("onwebchatoffemail"))
offlineEmail = document.getElementById("onwebchatoffemail").value;
if (document.getElementById("onwebchatemailtext"))
offlineText = document.getElementById("onwebchatemailtext").value;
if (document.getElementById("onwebchatofftel"))
offlinePhone = document.getElementById("onwebchatofftel").value;
socket.emit('visitorSendOfflineEmail', clientId, client_ip, siteId, offlineName, offlineEmail, offlineText, offlinePhone, conboxv, consent_use, show_consent_checkbox, windowLocationHref );
// httpPost("" + protocol + "//" + serverIP + "/visitorSendEmail", formData2,
// function (param) { // error sending
// // if (logging) console.log("error sending offline message, url:" + param.url + " status:" + param.status); // + " body:" + param.body);
// console.log('Error sending file: ' + param.status);
// },
// function (param) { // send successfully
// // if (logging) console.log("ok sending off message, url:" + param.url + " status:" + param.status); // + " body:" + param.body);
// }
// )
// $.ajax({ // auto to evgala, giati den trexei me to jquery slim..
// type: "POST",
// url: protocol + "//" + serverIP + "/visitorSendEmail",
// data: 'clientip=' + client_ip + '&clientid=' + clientId + '&sid=' + siteId + '&name=' +document.getElementById("onwebchatoffname").value + '&email=' +document.getElementById("onwebchatoffemail").value + '&text=' +document.getElementById("onwebchatemailtext").value + '&phone=' +document.getElementById("onwebchatofftel").value + '&conboxv=' + conboxv + '&conuse=' + consent_use + '&conboxshow=' + show_consent_checkbox,
// });
//$ (".onwebchatform_div").css("display", "none");
document.getElementById('onwebchatform_div_id').style.display = "none";
//$ (".onweboffline_msg").html(getText('off_thank', language) + '
');
document.getElementById('onweboffline_msg_id').innerHTML = getText('off_thank', language) + '
';
sendAnalyticsEvent('onWebChat', 'Offline message sent', '');
return false;
}
}
//$ ('#prechat_btn').click(
document.getElementById('prechat_btn').onclick = function() {
if (document.getElementById("onprechatname")) clientName =document.getElementById("onprechatname").value;
if (document.getElementById("onprechatemail")) clientEmail =document.getElementById("onprechatemail").value;
if (document.getElementById("onprechattel")) clientPhone =document.getElementById("onprechattel").value;
if (clientName == undefined) clientName = "";
if (clientEmail == undefined) clientEmail = "";
if (clientPhone == undefined) clientPhone = "";
clientName = clientName.trim();
clientEmail = clientEmail.trim();
clientPhone = clientPhone.trim();
// check if everythink is ok
if ((consent_use == 1 && show_consent_checkbox == 1 && document.getElementById("onwc_consent_checkbox_prechat").checked == false) ||
(show_prechat_email_field == 1 && mandatory_prechat_email_field == 1 && !validateEmail(clientEmail)) ||
(show_prechat_phone_field == 1 && mandatory_prechat_phone_field == 1 && clientPhone.length < 4) ||
(show_prechat_name_field == 1 && mandatory_prechat_name_field == 1 && clientName.length < 2) ||
(departments_use == 1 && mandatory_prechat_departments_field == 1 && selectedDepartment == 0) ||
(document.getElementById('onprechattext').value.trim().length < 1 )) {
if (consent_use == 1 && show_consent_checkbox == 1 && document.getElementById("onwc_consent_checkbox_prechat").checked == false) {
document.getElementById("onwc_consent_l_prechat_span").style.setProperty("color", "#D04848","important");
}
//if ($ ("textarea#onprechattext").val().trim().length < 1) {
if (document.getElementById('onprechattext').value.trim().length < 1 ) {
//$ ("textarea#onprechattext").focus();
document.getElementById('onprechattext').focus();
document.getElementById("onprechattext").style.setProperty("border", "1px solid #D04848", "important");
}
if (show_prechat_phone_field == 1 && mandatory_prechat_phone_field == 1 && clientPhone.length < 4) {
document.getElementById("onprechattel").focus();
setTimeout(function () { document.getElementById("onprechattel").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
//checkPrechatMargins();
checkBottomOfButton();
}
if (show_prechat_email_field == 1 && mandatory_prechat_email_field == 1 && !validateEmail(document.getElementById('onprechatemail').value)) {
document.getElementById("onprechatemail").focus();
setTimeout(function () { document.getElementById("onprechatemail").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
//checkPrechatMargins();
checkBottomOfButton();
}
if (show_prechat_name_field == 1 && mandatory_prechat_name_field == 1 && clientName.length < 2) {
document.getElementById("onprechatname").focus();
setTimeout(function () { document.getElementById("onprechatname").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
//checkPrechatMargins();
checkBottomOfButton();
}
if (departments_use == 1 && mandatory_prechat_departments_field == 1 && selectedDepartment == 0) {
setTimeout(function () { document.getElementById("departments").style.setProperty("border", "1px solid #D04848", "important"); }, 0);
checkBottomOfButton();
}
return false;
} else { // ola ok ta pedia tis prechat form, proxorao sto kanoniko chat
// // if (logging) console.log("PRECHAT: start chat with user name: " +document.getElementById("onprechatname").value + " and user email:" +document.getElementById("onprechatemail").value);
// if (logging) console.log("clienId:" + clientId);
var pre_msg =document.getElementById("onprechattext").value;
// if (logging) console.log("pre_msg:" + pre_msg);
socket.emit('setclientdetails', clientId, siteId, clientName, clientEmail, clientPhone, "");
var conboxv = -1;
if (document.getElementById("onwc_consent_checkbox_prechat"))
conboxv = document.getElementById("onwc_consent_checkbox_prechat").value;
if (conboxv == true) {
setCookie("consentvalue", 2, 93); // to theto gia na min to zitao kathe fora (meta apo 3 mines to zitao pali)
} else if (consent_use == 1) {
setCookie("consentvalue", 1, 93); // to theto gia na min to zitao kathe fora (meta apo 3 mines to zitao pali)
}
socket.emit('setconsentsettings', clientId, conboxv, consent_use, show_consent_checkbox); // ta stelno apo edo ola, gia na min ta xanatravao apo tin vasi
//$ ("#onwbchat_window").find(".chat_area,.chat_message,.chat_info").css("display", "block"); // show chat form
document.getElementById('chat_area_id').style.display = "block";
document.getElementById('onwc_chat_message_div').style.display = "block";
document.getElementById('chat_info_id').style.display = "block";
//$ ("#onwbchat_window").find("#prechat_form").css("display", "none");
document.getElementById('prechat_form').style.display = "none";
//$ ("#onwbchat_window #div_chat_max_title_span").text(getText('max_title', language)); // Chat with us!
document.getElementById('div_chat_max_title_span').textContent = getText('max_title', language); // Chat with us! isos den xreiazetai
var bubble_st = "";
//if (bubbles_use == 1)
bubble_st = " me-bubble";
printChat('
' + getText('max_me', language) + ' ' + escapeHtml(pre_msg) + '
', 'me');
previous_chat = "me";
endTime = getCurrentTime();
obj={};
obj.vesrion = version;
obj.durationInSeconds = (endTime - startTime) / 1000;
obj.socketDurationInSeconds = (endTime - startConnectTime) / 1000;
obj.isConnected = isConnected;
obj.firstConnection = firstConnection;
obj.timeoutTime_userconnect = timeoutTime_userconnect;
obj.tryToReconnect = tryToReconnect;
obj.pos = 3850;
//obj.sendChatDelay = sendChatDelay;
if (sessionStorageGet('chattext')){
obj.chattext = sessionStorageGet('chattext').substring(0,20);
}
let sendChatDelay = 0;
if (!isConnected){
sendChatDelay = 5400;
if ((isConnected == false) && (tryToReconnect == false)) {
// if (logging) console.log("isConnected = false! Try to connect now...")
obj.socketReconnect = 1;
socketReconnect();
}
}
setTimeout(function () {
endTime = getCurrentTime();
obj.durationInSeconds2 = (endTime - startTime) / 1000;
obj.socketDurationInSeconds2 = (endTime - startConnectTime) / 1000;
obj.isConnected2 = isConnected;
obj.tryToReconnect2 = tryToReconnect;
obj.firstConnection2 = firstConnection;
obj.timeoutTime_userconnect2 = timeoutTime_userconnect;
obj.sendChatDelay = sendChatDelay;
setTimeout(function () { socket.emit('sendchat', pre_msg, undefined, 0, selectedDepartment, 3850, num_connected, clientId, secretKey, obj) }, 400); // 300 tin kathisterisi tin vazo, giati kapoios mou elege oti eno
// xrisimopoiei tin prechat form, me required fields, polles fores den vlepei ta stoixia tou visitor, einai kena. Isos kathisterei na ta grapsei stin vasi ligo..
}, sendChatDelay);
//to selectedDepartment einai 0 ektos an exei epilexei department, opote einai to departmentid
enableNoReplyTrigger(); // an argisei na apantisei kapoios operator, emfanizo to trigger an to exei orisei
nowIsShowing = "chat"; //giati itan prechat
checkHeaderTitlePosition();
return false;
}
}
//$ ('input#onwc_consent_checkbox_offline').change(
if (document.getElementById('onwc_consent_checkbox_offline')) document.getElementById('onwc_consent_checkbox_offline').addEventListener('change', function () {
// if (logging) console.log("click on box...");
if (document.getElementById("onwc_consent_checkbox_offline").checked == true) {
document.getElementById("onwc_consent_l_offline_span").style.setProperty("color", "#545454", "important"); // vgazo to kokkino xroma apo to consent text
}
})
//$ ('input#onwc_consent_checkbox_prechat').change(
if (document.getElementById('onwc_consent_checkbox_prechat')) document.getElementById('onwc_consent_checkbox_prechat').onchange = function() {
if (document.getElementById("onwc_consent_checkbox_prechat").checked == true) {
document.getElementById("onwc_consent_l_prechat_span").style.setProperty("color", "#545454", "important"); // vgazo to kokkino xroma apo to consent text
}
}
//$ ('input#onwebchatoffemail').keyup(
if (document.getElementById('onwebchatoffemail')) document.getElementById('onwebchatoffemail').onkeyup = function () {
if (validateEmail(document.getElementById('onwebchatoffemail').value)) {
document.getElementById("onwebchatoffemail").style.setProperty("border", "1px solid #ccc", "important");
//checkOfflineMargins();
checkBottomOfButton();
}
}
//$ ('textarea#onwebchatemailtext').keyup(
if (document.getElementById('onwebchatemailtext')) document.getElementById('onwebchatemailtext').onkeyup = function () {
if (document.getElementById('onwebchatemailtext').value.length >= 1) {
document.getElementById("onwebchatemailtext").style.setProperty("border", "1px solid #ccc", "important");
//checkOfflineMargins();
checkBottomOfButton();
}
}
//$ ('input#onwebchatofftel').keyup(
if (document.getElementById('onwebchatofftel'))
document.getElementById('onwebchatofftel').onkeyup = function () {
checkPhone(document.getElementById('onwebchatofftel'));
if (document.getElementById('onwebchatofftel').value.length >= 4) {
//$ ("input#onwebchatofftel").attr( 'style', 'border:1px solid #ccc !important' );
document.getElementById("onwebchatofftel").style.setProperty("border", "1px solid #ccc", "important");
//checkOfflineMargins();
checkBottomOfButton();
}
}
//$ ('input#onwebchatoffname').keyup(
if (document.getElementById('onwebchatoffname'))
document.getElementById('onwebchatoffname').onkeyup = function () {
if (document.getElementById('onwebchatoffname').value.length >= 2) {
//$ ("input#onwebchatoffname").attr( 'style', 'border:1px solid #ccc !important' );
document.getElementById("onwebchatoffname").style.setProperty("border", "1px solid #ccc", "important");
////checkOfflineMargins();
checkBottomOfButton();
}
}
//$ ('input#onprechatemail').keyup(
if (document.getElementById('onprechatemail'))
document.getElementById('onprechatemail').onkeyup = function () {
if (validateEmail(document.getElementById('onprechatemail').value)) {
document.getElementById("onprechatemail").style.setProperty("border", "1px solid #ccc", "important");
//checkPrechatMargins();
checkBottomOfButton();
}
}
//$ ('textarea#onprechattext').keyup(
document.getElementById('onprechattext').onkeyup = function () {
if (document.getElementById('onprechattext').value.length >= 1) {
document.getElementById("onprechattext").style.setProperty("border", "1px solid #ccc", "important");
//checkPrechatMargins();
checkBottomOfButton();
}
}
//$ ('input#onprechattel').keyup(
if (document.getElementById('onprechattel'))
document.getElementById('onprechattel').onkeyup = function () {
checkPhone(document.getElementById('onprechattel'));
if (document.getElementById('onprechattel').value.length >= 4) {
//$ ("input#onprechattel").attr( 'style', 'border:1px solid #ccc !important' );
document.getElementById("onprechattel").style.setProperty("border", "1px solid #ccc", "important");
//checkPrechatMargins();
checkBottomOfButton();
}
}
//$ ('input#onprechatname').keyup(
if (document.getElementById('onprechatname'))
document.getElementById('onprechatname').onkeyup = function () {
if (document.getElementById('onprechatname').value.length >= 2) {
//$ ("input#onprechatname").attr( 'style', 'border:1px solid #ccc !important' );
document.getElementById("onprechatname").style.setProperty("border", "1px solid #ccc", "important");
//checkPrechatMargins();
checkBottomOfButton();
}
}
//$ ('onwbchat_window').draggable();
/*var image = document.getElementById("onwebchatImage");
image.addEventListener("click", function() {
maximizeChatWindow();
});*/
/*$ (".onwebchatbox").on("click",function(){
callbackOnClick(); // to eixa valei na kaleitai opoudipote k an kanei click o xristis alla eixa provlima, me ta settings, sto volume den kalutan, eno sto file send kaloutan..
})*/
loadEmoticons = function () {
//if ($ ('#onwebchat-emoticons-div').html() == "") { // ta vazo mono sto click, allios ta fortone ola stin arxi (polla request xoris logo otan eixa images)
if (document.getElementById('onwebchat-emoticons-div').innerHTML == "") { // ta vazo mono sto click, allios ta fortone ola stin arxi (polla request xoris logo otan eixa images)
//$ ('#onwebchat-emoticons-div').append('
😀 😬 😁 😂 😃 😄 ' +
document.getElementById('onwebchat-emoticons-div').insertAdjacentHTML('beforeend', '
😉 😀 🙂 😂 😃 😁 ' +
'
😅 😆 😎 😊 😇 😋 ' +
'
😌 🤔 😍 😘 😗 😶 ' +
'
😚 😜 😝 😛 😐 😒 ' +
'
😳 😲 😵 😧 😞 😟 ' +
'
😠 😡 😈 😔 😕 😓 ' +
'
😦 😣 😖 😩 😤 😱 ' +
'
😨 😰 😢 😭 😷 😴 ' +
'
👍 👎 👏 🤝 💓 🙋 ');
//👍👎👏🤝💓🙋 😈😷 🙏
//'
🙃 🤓 🤗 🙄 🤔 🤒 '+
//'
👍 👎 👏 ✌ 🤝 🤒 ');
//https://www.unicode.org/emoji/charts/full-emoji-list.html
var emoticons = document.querySelector("#onwebchat-emoticons-div").querySelectorAll("span");
for (var j = 0; j < emoticons.length; j++) {
emoticons[j].addEventListener("click", function () {
// // if (logging) console.log("click");
//console.log(event.target.innerHTML);
var emot = event.target.innerHTML;
//if (emot!=undefined) console.log(emot.length);
if (emot == "") { //se merika site px https://creditbrokers.mx/ den epeze k den egrafe tipota sto textarea.. (isos epeidi xrisimopioun to wp-emoji-release.min.js )
// // if (logging) console.log("emot keno!");
emot = event.target.getAttribute("alt");
}
if (emot != undefined && emot.length > 2) // sta idia site px https://creditbrokers.mx/ to kanei merikes fores otan den patao akrivos panos to icon..
emot = ""; // k evaze px
{
// chat_area_div.scrollTop = chat_area_div.scrollHeight;
my_animate2(document.getElementById("chat_area_id"), 50, 1);
});
// Check if we need to show the button on load and on resize
//window.onload = updateScrollToBottomButtonVisibility; //not needed
//window.onresize = updateScrollToBottomButtonVisibility; //not needed
} // appendChatWidget
//var timesVisited = getCookie('onwbchttimesVisited');
var timesVisited = localStorageGet('onwbchttimesVisited');
if (timesVisited == '' || timesVisited == undefined || timesVisited == 'NaN') {
timesVisited = 0;
localStorageSet("onwbchttimesVisited", 1);
}
/*var dialogid= getCookie('chatdialogid'); // to dialogid tis trexousas sinomilias, xreiazetai otan milaei kai allazei selida
if ((dialogid=='null')||(dialogid==null)||(dialogid=='')) {
// if (logging) console.log("dialogid from cookie: "+dialogid);
dialogid=0;
// if (logging) console.log("dialogid .. : "+dialogid);
} */
// to evgala 22/1/2022, (otan evgala to jquery) xreiazetai?
// $.support.cors = true;
function extractDomain(url) {
var domain; //find & remove protocol (http, ftp, etc.) and get domain
if (url == null) return null;
if (url.indexOf("://") > -1) {
domain = url.split('/')[2];
} else {
domain = url.split('/')[0];
}
domain = domain.split(':')[0]; //find & remove port number
domain = domain.trim();
// Remove "www." if it exists
if (domain.startsWith("www.")) {
domain = domain.slice(4);
}
return domain;
}
function ioconnect() {
var conn_options = {
//'sync disconnect on unload':false,
//query: $.param({'jsonpsessionid': '3333333' }),
query: { 'server': serverid },
reconnectionAttempts: 40 // megistos arithmos prospation gia reconnect.. (diorthosi bug me ta polla sockets?)
//'max reconnection attempts' : 2
};
if (!isLocalhost) {
socket = io.connect('https://' + serverIP + port, conn_options); // open connection // prepei na einai to idio me auto pou pairno to socket.js gia na paizei to cors!!
} else {
socket = io.connect('http://' + serverIP + port, conn_options); // local host // socket connect socket.connect
}
//socket = io.connect(protocol + '//'+serverIP + port, conn_options);
//socket = io.connect(protocol + '//www.onwebchat.com', conn_options); // prepei na einai to idio me auto pou pairno to socket.js gia na paizei to cors!!
/*socket = io.connect('http://'+serverIP+':81', // prepei na einai to idio me auto pou pairno to socket.js gia na paizei to cors!!
{ query: $.param({'jsonpsessionid': sessionid }) }
);*/
//socket.heartbeatTimeout = 25000; // reconnect if not received heartbeat for 25 seconds IE8!! default:60000
// if (logging) console.log('call connect ..');
socket.on('disconnect', function () {
isConnected = false;
disableSendButton();
// if (logging) console.log("on socket disconnect.." + new Date());
});
socket.on('error', function (reason) {
// if (logging) console.log('Unable to connect Socket.IO' + reason);
});
socket.on('connect_error', function (reason) {
// if (logging) console.log('on connect_error: ' + reason);
});
socket.on('connect_timeout', function () {
// if (logging) console.log('on connect_timeout');
});
socket.on('reconnect', function () {
// if (logging) console.log('on socket reconnect.');
});
socket.on('reconnecting', function (attemptNumber) {
// if (logging) console.log('on reconnecting , attempt:' + attemptNumber);
});
if (isIE() != 8) { // to socket.close ston ie8 petaei ena error ston browser (stack overflow, out of memory..), den xero an mporei o server na kleisei to connection..
socketTimeoutTimer = setTimeout(function () {
// if (logging) console.log("socketTimeoutTimer2... will disconnect now!");
socket.io.disconnect();
minimizeChatWindow();
}, socketTimeOutmsec); //close socket if client is more than 6 hours on the same page
}
socket.on('connect', function () { //onconnect on connect
isConnected = true;
tryToReconnect = false;
enableSendButton();
num_connected++;
startConnectTime = getCurrentTime();
if (num_connected > 15) { // diorthosi tou bug me ta polla sockets ?
// if (logging) console.log('num_connected > 10 => socket.disconnect');
socket.io.disconnect();
socket.disconnect();
socket = null;
}
// if (logging) console.log("on connect... num_connected:" + num_connected + " date:" + new Date());
//$ ('#onwbchat_window .chat_info p').text(' onWebChat');
// ta clientName, clientEmail, clientPhone, clientNotes an den ta kano set me to api, tha einai ""
var urlReferrer = document.referrer;
timeoutTime_userconnect = 0;
if (!firstConnection && (sessionStorageGet('chattext') == null || sessionStorageGet('chattext') == '')) { // xanasindeetai kai den exei grapsei kaneis sto chat
//timeoutTime_userconnect = Math.floor(Math.random() * 11000) + 5000; // comment it on 8/12/23 for bug 2023_12_8 (exitSendChat! (clientsId[sessionid]==null)..)
// parago tixaio int apo 5000 eos 15000 (23/4/2019) auto to kano sto server restart na min kanoun oloi oi visitors mazei tautoxrona connect..
// giati eixa provlima me to server restart (evgaze polla:
//stin userconnect will call db.getVisitorDetails, clientid:101583066
//warn: 10/4/2019 5:33:9 Waiting for available connection slot! (pool.on enqueue - db.js) enqueueNum:3035 acquireNum:1093 connectionNum:40 releaseNum:1082
}
setTimeout(function () {
// to agentOnline to stelno gia na to epiveveoso me ton server(an to exei cachare to js o browser k exei allaxei to agentStatus mporei na min to deixei sosta)
socket.emit('userconnect', clientId, clientName, clientEmail, clientPhone, clientNotes, documentTitle, windowLocationHref, screen.width, sessionrandom, browser, os, timesVisited, siteId, client_ip, urlReferrer, localStorageGet('onwbchtlastvisit'), allUseragentInfo, isMobile, blocked, firstConnection, agentOnline, consent_use, show_consent_checkbox);
//sessionrandom + "-" + screenWidth + "-" + ip + "-" + useragent;
// if (logging) console.log("sessionrandom:" + sessionrandom + " screenWidth: " + screen.width + " ip: " + client_ip + " useragent:" + allUseragentInfo);
}, timeoutTime_userconnect);
firstConnection = false; // must be after the "socket.emit('userconnect'..."
// // if (logging) console.log("### broswer: "+browser+ " os:"+os);
// // if (logging) console.log("oldexpsid:"+oldexpsid);
// // if (logging) console.log("getcookie - express.sid:"+getCookie('onwbchtexpress.sid'));
// // if (logging) console.log("getcookie - lang :"+getCookie('onwbchtlang'));
});
/*socket.on('initChatStatus', function (show_chat, isMax){
// if (logging) console.log("on initChatStatus: show_chat:"+ show_chat + " isMax:" + isMax);
//if (preConnect && show_chat == 1) {
//showChatWindow();
//}
if (isMax == 1){
// if (logging) console.log("isMax==1");
maximizeChatWindow();
}
});*/
socket.on('onwcemailtranscript_ok', function () {
toggleModal('onwcEmailOkModal');
})
socket.on('addvisited1', function (today) {
timesVisited++;
//setCookie("onwbchttimesVisited", timesVisited, 93);
localStorageSet("onwbchttimesVisited", timesVisited);
//setCookie("onwbchtlastvisit", today, 93); // auto to krata gia na metrao ta unique visits/day
localStorageSet("onwbchtlastvisit", today); // auto to krata gia na metrao ta unique visits/day
});
socket.on('setCookie', function (name, value) {
if (name == "onwbchtclientid") { // pros to paron mono auto stelnei o server..
if (localStorageGet('onwbchtclientid') != '' && localStorageGet('onwbchtclientid') != null) {
// if (logging) console.log("vrika kai palio cookie onwbchtclientid me timi:" + localStorageGet('onwbchtclientid') + " o server esteile:" + value + " (pithano visitor deleted)");
if (localStorageGet('onwbchtclientid') != value) { // isos exei ginei diagrafi autou tou visitor(eno den itan sto site), kai autos epistrefei sto site! opote na ta svixo apo ton browser tou , ta data!
deleteAllCookiesAndStorage();
sessionStorageSet('chattext', '');
//$ ('#onwbchat_window .chat_area p').remove();
var els=document.querySelectorAll('#chat_area_id p'); //exefanizo ta chats(messages)
els.forEach(function(el) {
el.remove();
});
document.getElementById('onwc_welcome_message').style.display = "block"; // emfanizo to bubble
}
}
clientId = value;
}
localStorageSet(name, value);
// if (logging) console.log('set cookie...');
});
socket.on('chatWindowMax', function (isMax) {
// if (logging) console.log("on chatWindowMax max!!:" + isMax);
if (isMax == 1)
maximizeChatWindow();
else if (isMax == 0)
minimizeChatWindow();
});
socket.on('updateagents', function (agentsdata) { // temp - check!
// if (logging) console.log("on updateagents agentsdata:" + agentsdata);
callbackOnUpdateOperators(agentsdata);
});
socket.on('send_dialogid', function (dialogidtemp) {
// if (logging) console.log("on send_dialogid dialogidtemp:" + dialogidtemp);
dialogid = dialogidtemp;
});
socket.on('newChatEvent', function (bywho) { // bywho : 'operator' i 'visitor'
// // if (logging) console.log("on newChatEvent , by "+bywho);
// kano post to event gia ta google analytics
sendAnalyticsEvent('onWebChat', 'Chat started', 'by ' + bywho);
});
socket.on('askforrating', function (dialogidtemp) {
// if (logging) console.log("askforrating!!!");
dialogid = dialogidtemp;
toggleModal("onwcRatingChatModal", true); // to emfanizo
});
socket.on('updateclientdetails', function (clientnametemp, clientemailtemp, clientphonetemp, clientnotestemp) {
// if (logging) console.log(" on updateclientdetails! : clientnametemp:" + clientnametemp + " clientemailtemp:" + clientemailtemp + " clientphonetemp:" + clientphonetemp + " clientnotestemp:" + clientnotestemp);
// // if (logging) console.log("arxika: clientName:" + clientName + " clientEmail:" + clientEmail + " clientPhone:" + clientPhone + " clientNotes:"+ clientNotes);
if (clientnametemp != '' && isNaN(clientnametemp)) { // returns true if the variable does NOT contain a valid number
clientName = clientnametemp;
}
if (clientemailtemp != '') {
clientEmail = clientemailtemp;
}
if (clientphonetemp != '') {
clientPhone = clientphonetemp;
}
if (clientnotestemp != '') {
clientNotes = clientnotestemp;
}
// // if (logging) console.log("telika: clientName:" + clientName + " clientEmail:" + clientEmail + " clientPhone:" + clientPhone + " clientNotes:"+ clientNotes);
});
socket.on('senddepartments', function (deps) {
document.getElementById("onwcdepartmenu").style.setProperty("display", "grid", "important");
// if (logging) console.log(deps);
deps = JSON.parse(deps);
onwcdepartmenu = document.getElementById("onwcdepartmenu");
onwcdepartmenu.innerHTML = ""; //clear all child elements
if (onwcdepartmenu.childElementCount == 0) { // only if there are no child elements
for (var j = 0; j < deps.length; j++) {
var li = document.createElement("LI");
var span = document.createElement("span");
var textnode = document.createTextNode(deps[j].name);
span.appendChild(textnode);
li.appendChild(span);
var span2 = document.createElement("span");
span2.appendChild(document.createTextNode(deps[j].id)); // vazo to id se ena hidden span
span2.style.setProperty("display", "none", "important");
li.appendChild(span2);
//px
Support 2
onwcdepartmenu.appendChild(li);
li.onclick = function () { onwcmenuliclick(this); };
}
}
if (isRTLlanguage(getText('departments', language).trim().substring(0, 2))){
document.getElementById("onwcdepartmenu").style.setProperty("direction", "rtl", "important");
document.getElementById("onwcdepartmenu").style.setProperty("text-align", "right", "important");
} else {
document.getElementById("onwcdepartmenu").style.setProperty("direction", "", "important");
document.getElementById("onwcdepartmenu").style.setProperty("text-align", "left", "important");
}
});
socket.on('setAgentImage', function (agentimage) { // to stelnei o server, molis o visitor epilexei ena department (gia na dixei tin eikona enos operator apo auto to department)
// if (logging) console.log("server sent setAgentImage:" + agentimage);
if (agentimage != undefined && agentimage != '') {
operatorImage = agentimage;
//$ ('#operatorImage').attr('src', protocol + '//' + serverIP + '/filesUpload/operatorImages/' + agentimage); // allagi tis eikona tou xeiristi, (se periptosi pou itan offline otan fortose k meta ginetai online kapios agent)
if (document.getElementById("operatorImage")) document.getElementById("operatorImage").src = protocol + '//' + serverIP + '/filesUpload/operatorImages/' + agentimage; // allagi tis eikona tou xeiristi, (se periptosi pou itan offline otan fortose k meta ginetai online kapios agent)
}
})
socket.on('setAgentOnlineHideOffline', function (setAgentOnline, setHideOffline, realAgentOnlineTemp, agentimage) { // to agentimage den to stelno panta setagentstatus sendagentstatus
// to realAgentOnlineTemp einai 1 an to chat widget einai online (toulaxiston 1 agent me status online)
// to setAgentOnline einai to idio me to realAgentOnlineTemp, alla an einai sto Free plan kai den exei diathesima chat, tote to kano 0
// k emfanizo tin offline form!
if (alwaysOffline == 1) return; // prepei na einai sinexeia offline (xrisi mono sto onwebchat.com gia mena, gia merikes xores..)! opote den perno ipopsin mou tixon allages sto status tou agent
if (realAgentOnlineTemp == undefined) realAgentOnlineTemp = 0;
realAgentOnline = realAgentOnlineTemp;
try {
// if (logging) console.log(" on setAgentOnlineHideOffline, setAgentOnline: " + setAgentOnline + " setHideOffline:" + setHideOffline + " blocked:" + blocked + " sessionStorage.chattext.length:" + sessionStorage.chattext.length);
} catch (e) { console.log(e); }
// // if (logging) console.log(" chatLeftSite: "+ chatLeftSite);
// if (logging) console.log(" realAgentOnlineTemp: " + realAgentOnlineTemp);
if (setAgentOnline == 1) {
if (agentimage != undefined && agentimage != '') {
operatorImage = agentimage;
//$ ('#operatorImage').attr('src', protocol + '//' + serverIP + '/filesUpload/operatorImages/' + agentimage); // allagi tis eikona tou xeiristi, (se periptosi pou itan offline otan fortose k meta ginetai online kapios agent)
if (document.getElementById("operatorImage")) document.getElementById("operatorImage").src = protocol + '//' + serverIP + '/filesUpload/operatorImages/' + agentimage; // allagi tis eikona tou xeiristi, (se periptosi pou itan offline otan fortose k meta ginetai online kapios agent)
}
}
if (setAgentOnline != undefined && setAgentOnline != null) {
if (agentOnline != setAgentOnline) {
if (isMobile) {
if (setAgentOnline == 1) image_name = image_name_mobile; else image_name = image_name_mobile_offline;
} else { if (setAgentOnline == 1) image_name = image_name_desktop; else image_name = image_name_desktop_offline; }
if (setAgentOnline == 1) { // to kano online
//$ ("#div_chat_min_title_span").text(getText('min_online', language));
document.getElementById("div_chat_min_title_span").textContent=getText('min_online', language);
////$ ('#onweb-offline-icon').hide();
document.getElementById("onweb-offline-icon").style.setProperty("display", "none");
//$ ('#onweb-online-icon').show();
document.getElementById("onweb-online-icon").style.setProperty("display", "inline-block");
//if (onlineColor != "") //$ ('#webchat_header')[0].style.setProperty('background-color', onlineColor, 'important');
if (onlineColor != "") document.getElementById("webchat_header").style.setProperty('background-color', onlineColor, 'important');
//$ ('#onweb_chatimage').attr('src', protocol + '//' + serverIP + '/chatWidgetImages/' + image_name); // allagi tis eikonas otan to status allazei se online
if (document.getElementById("onweb_chatimage")) document.getElementById("onweb_chatimage").setAttribute('src', protocol + '//' + serverIP + '/chatWidgetImages/' + image_name); // allagi tis eikonas otan to status allazei se online
} else {
setTimeout(function () { // to kano offline
//$ ("#div_chat_min_title_span").text(getText('min_offline', language)); // offline title: We are offline - Send us an email
document.getElementById("div_chat_min_title_span").textContent=getText('min_offline', language)
//$ ('#onweb-offline-icon').show();
document.getElementById("onweb-offline-icon").style.display = "inline-block";
//$ ('#onweb-online-icon').hide();
document.getElementById("onweb-online-icon").style.display = "none";
if (offlineColor != "") document.getElementById("webchat_header").style.setProperty('background-color', offlineColor, 'important');
if (offlineColor != "") document.getElementById("offlineform_btn").style.setProperty('background-color', offlineColor, 'important');
//$ ('#onweb_chatimage').attr('src', protocol + '//' + serverIP + '/chatWidgetImages/' + image_name); // allagi tis eikonas otan to status allazei se offline
if (document.getElementById("onweb_chatimage")) document.getElementById("onweb_chatimage").setAttribute('src', protocol + '//' + serverIP + '/chatWidgetImages/' + image_name); // allagi tis eikonas otan to status allazei se online
}, 300); // vazo to timeout , giati an ginei hide to chat (me to pou ginei offline), fainetai gia ligo i allagi tou titlou (exetias tou fadeout)
/* if (sessionStorage.chattext==null || sessionStorage.chattext=='') { // an iparxei keimeno den vazo tin offline form
if ((setAgentOnline==1 || setHideOffline!=1) && blocked==0) // den ginetai hide (i sinthiki auti prepei na einai i idi me autin 10 grammes pio kato!)
//$ ("#div_chat_max_title_span").text("Emal us!!!");
else
setTimeout( function() { //$ ("#div_chat_max_title_span").text("Emal us!!!"); } , 300 );
}*/
}
}
agentOnline = setAgentOnline;
hideOffline = setHideOffline;
//showChatApi
if ((agentOnline == 1 || hideOffline != 1 || sessionStorageGet('chattext').length > 0) && blocked == 0) {
// if (logging) console.log("show.........");
if (showChatApi != 0) // an exei ginei show 0 me to api na min emfanistei (epeidi px allaxe status o agent)
showChatWindow();
} else { // otan px agentOnline=0 kai hideOffline=1 (klp..)
// if (logging) console.log("hide......... blocked:" + blocked);
hideChatWindow();
}
if ((sessionStorageGet('chattext').endsWith(getText('max_gone', language) + "")) && agentOnline == 1 && realAgentOnline != 0) { // an ginei online o operator, tote na svino to minima : Operator has gone offline
//$ ('p:last-child', '#onwbchat_window .chat_area').remove(); // to afero apo to div chat_area.. (All operators are offline)
var lastchild = document.getElementById('chat_area_id').lastChild;
document.getElementById('chat_area_id').removeChild(lastchild);
sessionStorageSet('chattext', sessionStorageGet('chattext').substring(0, sessionStorageGet('chattext').lastIndexOf('
' + getText('max_gone', language) + '
'))); // to afero apo to session storage
enableWriting();
}
if (agentOnline == 1 && realAgentOnline != 0) {
enableWriting();
}
if (chatWithBot == 0 & agentOnline != 1 && realAgentOnline == 0 && sessionStorageGet('chattext').length > 0) { // otan milaei me kapion agent kai figoun offline oloi oi agents
if (!sessionStorageGet('chattext').endsWith(getText('max_gone', language) + "")) { // na min to vazei polles fores..
var timeoutTime2 = 1000; //1000 (to allaxa apo 2000 se 1000 tin 6/4/2020 giati se auton ton xrono (2sec) mporei na prolavei o visitor na steilei minima, eno o operator exei vgei kanonika offline )
if (isAgentFromAndroid == 1) {
timeoutTime2 = 3000; // 5000
}
//console.log("0 agentOnline!!!!!!!!!!!: " + agentOnline + " realAgentOnline:" + realAgentOnline);
setTimeout(function () {
//console.log("1 agentOnline!!!!!!!!!!!: " + agentOnline + " realAgentOnline:" + realAgentOnline);
if ((agentOnline != 1) && realAgentOnline == 0 && (!sessionStorageGet('chattext').endsWith(getText('max_gone', language) + ""))) {
printChat('
' + getText('max_gone', language) + '
');
//console.log("2 agentOnline!!!!!!!!!!!: " + agentOnline + " realAgentOnline:" + realAgentOnline);
disableWriting();
}
//console.log("3 agentOnline!!!!!!!!!!!: " + agentOnline + " realAgentOnline:" + realAgentOnline);
}, timeoutTime2);
// me to disableWriting kano anenergo to textarea kai ta buttons..
//elegxo me to timeoutTime2 an exei xanasindethei grigora (px sto refresh) na min grapsei to minima
}
}
}
});
socket.on('setIsBlocked', function (isBlocked) { // 0 i 1
// if (logging) console.log(" on setIsBlocked, set isBlocked: " + isBlocked);
if (isBlocked == undefined) {
isBlocked = 0;
// if (logging) console.log("isBlocked undefined , so set it to 0");
}
blocked = isBlocked;
//setCookie("onwbchtblocked", isBlocked, 183); // 1/2 year
localStorageSet("onwbchtblocked", isBlocked);
if (blocked == 1) {
hideChatWindow();
} else if (blocked == 0) {
if (agentOnline == 1 || hideOffline != 1) {
if (showChatApi != 0)
showChatWindow();
}
}
});
socket.on('visitordeleted', function () { //deletevisitor
// if (logging) console.log(" on visitordeleted");
sessionStorageSet('chattext', ''); // svino te text apo to session otan o opearator diagrafei ton visitor auton
//$ ('#onwbchat_window .chat_area p').remove(); //exefanizo ta chats(messages)
var els=document.querySelectorAll('#chat_area_id p'); //exefanizo ta chats(messages)
els.forEach(function(el) {
el.remove();
});
////$ ("#onwbchat_window .onwebchat_title2").css("display", "block");// emfanizo to bubble
////setTimeout(function () { //$ ("#onwbchat_window").fadeOut(700, 'swing'); }, 200);
myFadeOut(document.getElementById("onwbchat_window"));
deleteAllCookiesAndStorage();
socket.disconnect();
});
deleteAllCookiesAndStorage = function () {
deleteCookie("onwbchtclientid");
deleteCookie("inChatC");
deleteCookie("onwbchtSound");
deleteCookie("onwbchtblocked");
deleteCookie("onwbchtexpress.sid");
deleteCookie("onwbchtlastvisit");
deleteCookie("onwbchtsessionrandom");
deleteCookie("onwbchttimesVisited");
try{
localStorage.clear();
sessionStorage.clear();
} catch(err){}
}
socket.on('servercommand', function (command, agentid, agentname, agentinfo, agentimage, dialogidtemp) {
// ta agentinfo kai agentimage, ta stelno mono sto serve_dialog command! (gia na elegxo an einai apo android)
// to dialogid to stelno mono me to close_dialog ! gia ta ratings to xreiazomai..
if (agentname == null || agentname == "") agentname = "operator";
// if (logging) console.log(" on servercommand: " + command + " agentname:" + agentname + " agentinfo:" + agentinfo + " agentImage:" + agentimage + " agentid:" + agentid);
if (command == 'close_dialog') { // agent_close_dialog operator_close_dialog close chat closechat endchat end chat closechat
//dialogid=0;
//setCookie("chatdialogid", 0 , 30);
//agentSocket="";
// if (logging) console.log('close_dialog get... clear chatdialogid cookie...');
//document.cookie = "chatdialogid=-1; expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";;
// if (logging) console.log('clear chatdialogid cookie...');
if (getCookie('inChatC') == 1) { // to elegxo auto, giati diaforetika , an estelne o visitor ena neo mesage kai den apantouse kaneis agent
// kai enas agent patouse X , tote egrafe ston visitor "operator xxx closed the chat" k meta mporouse na ton parei allos operator ton dialog
if (getText('max_closed', language) != "")
printChat('
' + getText('max_closed', language).replace('{{operator}}', agentname) + '
');
}
//kanonika edo prepei na apoepilego ta star ola, an exo epilexei prin..
if (rating_use == 1 && getCookie('inChatC') == 1 && isRated == 0) { // prosoxi to setCookie('inChatC', 0, 0.166); na mpei meta apo auto to if
toggleModal("onwcRatingChatModal", true); // to emfanizo
}
setCookie('inChatC', 0, 0.166);
sessionStorageSet("servingOpImage", "");
operatorImage = "";
if (showOperatorImages == 1){
operatorImage = "0_support_man.png";
}
sessionStorageSet('hasTriggeredNoReply', 0); // episis an to chattext den einai keno, exei arxisei enas dialogos, tote oxi trigger!
setCookie('hasTriggeredNoReplyC', 0, 0.166);
disableMenuItem('onwebchat-endchat-li');
endChatButtonEnabled = false;
isRated = 0;
sessionStorageSet('isRated', 0);
//sessionStorageSet('chattext', ''); // to svino apo to session. oxi den to thelo auto edo, giati otan allaxei selida xanontai ola ta keimena kai den mporei episis na kanei save se arxeio..
dialogid = dialogidtemp;
// if (logging) console.log(" dialogid:" + dialogid);
} else if (command == 'serve_dialog') { // agent serve served by
if (agentinfo == "androidapp") {
isAgentFromAndroid = 1; // o agent pou ton apantise einai apo Android app
} else {
isAgentFromAndroid = 0;
}
// if (logging) console.log("served_by command.. isAgentFromAndroid:" + isAgentFromAndroid + " agentImage:" + agentimage);
previous_chat = "served_by";
if (getText('max_served', language) != "") {
if (!sessionStorageGet('hasWrSeByTr')) { // na min to xanagrapso (k me allo onoma..)
printChat('
' + getText('max_served', language).replace('{{operator}}', agentname) + '
');
}
}
// if (logging) console.log("agent name:" + agentname);
if ( agentimage == "" || !agentimage){
agentimage = "0_support_man.png"; // default operator image
}
operatorImage = agentimage;
sessionStorageSet("servingOpImage", agentimage);
//$ ('#operatorImage').attr('src', protocol + '//' + serverIP + '/filesUpload/operatorImages/' + agentimage); // allagi tis eikona tou xeiristi
if (document.getElementById("operatorImage")) document.getElementById("operatorImage").setAttribute('src', protocol + '//' + serverIP + '/filesUpload/operatorImages/' + agentimage); // allagi tis eikonas otan to status allazei se online
} else if (command == 'no_agent') {
printChat('
No agent is online now, but we will reply to you asap.
');
}
}); // socket.on servercommand
socket.on('disablesendbutton', function () { // otan perimeno apantisi apo to bot, na min mporei na steilei o visitor
//if (chatWithBot == 1){
// if (logging) console.log("disabling send button (wait ai bot response)..");
disableSendButton('aibot');
//}
})
//update this chat widget (with visitor's msg) if the visitor send a msg from chat widget on another browser tab..
socket.on('updatechatvisitor', function (data, dialogid) {
var bubble_st = "";
bubble_st = " me-bubble ";
if (previous_chat != 'me') {
bubble_st = bubble_st + " me-first ";
}
var rtlCss = "";
if (isRTLlanguage(data.substr(0, 1)) == true) {
rtlCss = ' style="direction: rtl;text-align:right;" ';
}
printChat('
' + getText('max_me', language) + ' ' + escapeHtml(data) + '
', "me");
previous_chat = "me";
})
// listener, whenever the server emits 'updatechat', this updates the chat body // agent ao ai bot send chat
socket.on('updatechat', function (fromSocket, dialog, data, agentname) {
if (agentname == null || agentname == "") agentname = "operator";
if (agentname == 'aibot'){
chatWithBot = 1;
sessionStorageSet("chatWithBot", 1);
operatorImage = ai_bot_image;
document.getElementById('onwbtxtarea').maxLength = textAreaMaxLengthWithBot;
// allagi tis eikonas pano sto header
if (document.getElementById("operatorImage")) document.getElementById("operatorImage").setAttribute('src', protocol + '//' + serverIP + '/filesUpload/operatorImages/' + ai_bot_image);
sessionStorageSet("servingOpImage", ai_bot_image);
} else {
chatWithBot = 0;
sessionStorageSet("chatWithBot", 0);
}
// if (logging) console.log(" on updatechat: data:" + data + " agentname:" + agentname + " showChatApi:" + showChatApi);
//agentSocket=fromSocket;
if (data == 'command:typing...') {
///$ ('#onwbchat_window .chat_info p').text(getText('max_typing', language).replace('{{operator}}',agentname));
//$ ('#agenttypingimage').remove();
if (document.getElementById('agenttypingimage')) document.getElementById('agenttypingimage').remove();
let bigMarginLeft = "";
if (showOperatorImages == 1) {
bigMarginLeft = " big-margin-left ";
}
// document.getElementById('chat_area_id').insertAdjacentHTML("beforeend", "
");
//vazo edo section k oxi div , giati me to div den edeixne tin ora sosta sto teleutaio message. dld den douleue sosta to css rule : .onwcouter:last-of-type .onwctime{ opacity : 1 !important; }
document.getElementById('chat_area_id').insertAdjacentHTML("beforeend", "
");
setTimeout(function() { document.getElementById("chat_area_id").scrollTop = 9999999; }, 0);
// setTimeout(function() {
// //Start the animation
// //window.requestAnimationFrame(smoothScroll);
// startSmoothScroll()
// }, 0);
// setTimeout(function() { my_animate2(document.getElementById("chat_area_id"), 1, 10); }, 20);
//$ ('#onwbchat_window .chat_area').animate({ scrollTop: 9999999 }, 200);
//setTimeout(function() { document.getElementById("chat_area_id").scrollTop = 9999999; }, 0); // evala 40 ms edo, giati kamia fora den emfanize tin eikona typing.gif // telika to evala stin eikona me onload pou einai pio sosto
} else if (data == 'command:notyping...') {
try {
if (document.getElementById('agenttypingimage') != null)
document.getElementById('agenttypingimage').style.visibility = 'hidden';
} catch (err) { //console.log(e);
}
///$ ('#onwbchat_window .chat_info p').text('');
} else if (showChatApi == 0) {
// if (logging) console.log("den emfanizetai epeidi showchatapi=0");
} else { // operator send message agent send message
//dialogid=dialog;
//setCookie("chatdialogid", dialogid , 30);
// // if (logging) console.log("on updatechat: dialogid:"+dialogid);
//if (chatWithBot == 1){
// if (logging) console.log("enabling send button..");
enableSendButton();
//}
playSoundNew();
clearTimeout(timerNoReply); // disable to trigger "no reply by operator"
enableWriting(); // an o operator einai offline k omos steilei minima ston visitor, o visitor na mporei na apantisei
//$ ('#agenttypingimage').remove();
if (document.getElementById('agenttypingimage')) document.getElementById('agenttypingimage').remove();
var bubble_st = "";
var operatorImageStTemp = '';
var bigMarginLeft = "";
//if (bubbles_use == 1)
bubble_st = " agent-bubble ";
if (previous_chat != 'agent') {
bubble_st = bubble_st + " agent-first ";
if (showOperatorImages == 1) {
operatorImageStTemp = '
';
}
}
if (showOperatorImages == 1) {
bigMarginLeft = " big-margin-left ";
}
callbackOnNewMessage(data, "operator");
setCookie('inChatC', 1, 0.166); // 0.166 (=4 hours) to prosthesa 6/3/2018. auto giati polloi visitors anoigan ena site se allo tab kai pali energopoioutan to trigger.. Auto itan provlima eidika an eixe idi kanei chat giati, eno eixe milisi me xiristi, xafnika tou emfanizetai ena asxeto trigger
var rtlCss = "";
if (isRTLlanguage(data.substr(0, 1)) == true) {
rtlCss = ' style="direction: rtl;text-align:right;" ';
}
//show message on chat window
printChat('
' + operatorImageStTemp + '' + getText('max_agent', language).replace('{{operator}}', agentname) + ' ' + escapeHtml(data) + '
');
previous_chat = "agent";
//if ((fromSocket!="")&&(//$ ('.chat_area').css("height")=='0px')) {
if ((fromSocket != "") && (sessionStorageGet('maxChat') != 1)) {
// if (logging) console.log(" MaximizeWindowInit , giati: fromSocket!=0 kai maxChat!=1! fromSocket:" + fromSocket + " maxChat:" + sessionStorageGet("maxChat"));
MaximizeWindowInit(); // otan erxetai minima apo ton agent, k einai minimized to chat window
}
if (agentOnline != 1) { // otan erxetai minima apo agent kai einai to site status offline (agentOnline==0)(o agent einai aoratos), den prepei na dixei tin offline form
// if (logging) console.log("agentOnline!=1 !!!");
if (sessionStorageGet('chattext') != null && sessionStorageGet('chattext') != '') {
// if (logging) console.log("sessionstorage.chattext!=null");
}
showChatWindow(); // to elegxo se autin tin sinartisi, alla omos prepei na tin kaleso edo , gia na exo valei me tin printChat to text sto sessionStorage.chattext
}
// // if (logging) console.log(" prechatform -> display:" + $ ("#onwbchat_window").find("#prechat_form").css("display"));
//if ($ ("#onwbchat_window").find("#prechat_form").css("display") == 'block') { // an emfanizetai i prechat form, tote na tin kripso k na emfaniso to chat
if (document.getElementById('prechat_form').style.display == 'block') { // an emfanizetai i prechat form, tote na tin kripso k na emfaniso to chat
showChatWindow();
}
/*if (//$ ("#onwbchat_window").css("display") == "none") { // if chat window is not shown
// if (logging) console.log("#onwbchat_window. dislplay == none so call showChatWindow()!");
showChatWindow();
}*/
}
});
removeLoadingImage = function (imageId) {
//$ ('#' + imageId).css('background', 'none');
if (document.getElementById(imageId)) document.getElementById(imageId).style.background = "none";
my_animate2(document.getElementById('chat_area_id'), 10, 10);
}
//SEND USER MESSAGE
var typing = 0;
var timer = 0;
var timerInsights = 0; // gia typing insights
var lastSentMsg = "";
function onwebSendText() { // visitor send message
if (isMobile) { // force soft keyboard to close (min) on mobiles
document.getElementById("onwbtxtarea").blur();
}
//var msg = $ ('#onwbtxtarea').val();
if (blocked == 1){
return;
}
var msg = document.getElementById('onwbtxtarea').value;
//msg = msg.replace(/<(?:.|\n)*?>/gm, ''); //remove HTML
//$ ('#onwbtxtarea').val(''); //remove text from textarea
document.getElementById('onwbtxtarea').value = ""; //remove text from textarea
//add to chat area
if (msg.trim() != "") { // gia na min stelno to keno string i mono spaces...
var bubble_st = "";
//if (bubbles_use == 1)
bubble_st = " me-bubble";
var new_line = "";
if (previous_chat != "me") {
bubble_st = bubble_st + " me-first ";
//new_line = "
"
}
lastSentMsg = msg;
callbackOnNewMessage(msg, "visitor");
//to replaceAll den iparxei stin JavaScript k se merikous browsers den pezei!!
//px petaei error stous: opera ie11.., opote xrisimopio to replace(/xxxxxx/g,"..
msg = msg.replace(/\n/g, "{{newline}}"); // otan patao shift+key, vazo to {{newline}}, oste na fainetai sosta kai sto oper.console
var rtlCss = "";
if (isRTLlanguage(msg.substr(0, 1)) == true) {
rtlCss = ' style="direction: rtl;text-align:right;" ';
}
printChat('
' + getText('max_me', language) + ' ' + escapeHtml(msg) + '
', "me");
//printChat('
' + getText('max_me', language) + ' ' + escapeHtml(msg) + '
');
previous_chat = "me";
// if (logging) console.log("send normal text, msg:" + msg);
enableNoReplyTrigger();
endTime = getCurrentTime();
obj={};
obj.vesrion = version;
obj.durationInSeconds = (endTime - startTime) / 1000;
obj.socketDurationInSeconds = (endTime - startConnectTime) / 1000;
obj.isConnected = isConnected;
obj.tryToReconnect = tryToReconnect;
obj.firstConnection = firstConnection;
obj.timeoutTime_userconnect = timeoutTime_userconnect;
obj.pos = 5183;
if (sessionStorageGet('chattext')){
obj.chattext = sessionStorageGet('chattext').substring(0,20);
}
let sendChatDelay = 300;
if (!isConnected){
sendChatDelay = 900;
if ((isConnected == false) && (tryToReconnect == false)) {
// if (logging) console.log("isConnected = false! Try to connect now...")
obj.socketReconnect = 1;
socketReconnect();
}
}
if (sessionStorageGet('mustSendTriggerText') && mustSendTriggerTextJs == true) {
const triggerTextTemp = sessionStorageGet('triggerText'); // save to temp, as we remove it, some lines below!
setTimeout(function () { socket.emit('sendchat', msg, triggerTextTemp, 0, 0, 5183, num_connected, clientId, secretKey, obj) }, sendChatDelay);
// if (logging) console.log("emit sendchat mustsendtrigger..");
sessionStorageSet('mustSendTriggerText', false);
mustSendTriggerTextJs = false; // to elegxo kai auto me mia js metavliti, giati
// ipirxe bug, mallon me ton safari (Mac) se private mode, opou den ekane sessionStorageSet kai kathe fora pou estelne o visitor kati, estlene kai to trigger! (vevea autos o elegxos isxei gia to trexon tab k an den kanei refresh klp..)
sessionStorageRemove('triggerText');
} else {
setTimeout(function () { // 2 nesting setTimout for fix bug 2023_12_8
endTime = getCurrentTime();
obj.durationInSeconds2 = (endTime - startTime) / 1000;
obj.socketDurationInSeconds2 = (endTime - startConnectTime) / 1000;
obj.isConnected2 = isConnected;
obj.tryToReconnect2 = tryToReconnect;
obj.firstConnection2 = firstConnection;
obj.timeoutTime_userconnect2 = timeoutTime_userconnect;
obj.sendChatDelay = sendChatDelay;
obj.pos = 5191;
let sendChatDelay2 = 300;
if (!isConnected) { // may connection is not still available after calling socketReconnect, so wait again for some time
sendChatDelay2 = 5300;
}
setTimeout(function () {
endTime = getCurrentTime();
obj.durationInSeconds3 = (endTime - startTime) / 1000;
obj.socketDurationInSeconds3 = (endTime - startConnectTime) / 1000;
obj.isConnected3 = isConnected;
obj.tryToReconnect3 = tryToReconnect;
obj.firstConnection3 = firstConnection;
obj.timeoutTime_userconnect3 = timeoutTime_userconnect;
obj.sendChatDelay2 = sendChatDelay2;
obj.pos = 5191;
socket.emit('sendchat', msg, undefined, 0, 0, 5191, num_connected, clientId, secretKey, obj);
}, sendChatDelay2); // to dialogid den to apothikeuo topika , to vrisko ston server apo to socketsession
}, sendChatDelay); // to dialogid den to apothikeuo topika , to vrisko ston server apo to socketsession
// if (logging) console.log("emit sendchat.");
//setTimeout(triggerNow, triggers[i].delay*1000, triggers[i].text, triggers[i].agentName);
}
// else if (sessionStorageGet('mustSendTriggerNoReplyText') && mustSendTriggerNoReplyTextJs==true){
//
// socket.emit('sendchat', msg, sessionStorageGet('triggerTextNoReply'));
// sessionStorageSet('mustSendTriggerNoReplyText', false);
// mustSendTriggerNoReplyTextJs = false; // to elegxo kai auto me mia js metavliti, giati
// // ipirxe bug, mallon me ton safari (Mac) se private mode, opou den ekane sessionStorageSet kai kathe fora pou estelne o visitor kati, estlene kai to trigger! (vevea autos o elegxos isxei gia to trexon tab k an den kanei refresh klp..)
// sessionStorageRemove('triggerTextNoReply');
//
// }
}
typing = 0;
}
function onwebSendTextInsights() {
//var msg = $ ('#onwbtxtarea').val();
var msg = document.getElementById('onwbtxtarea').value;
// if (logging) console.log("onwebSendTextInsights:: msg:" + msg);
if (msg.trim() != "" && blocked == 0) { // gia na min stelno to keno string i mono spaces...
endTime = getCurrentTime();
obj={};
obj.vesrion = version;
obj.durationInSeconds = (endTime - startTime) / 1000;
obj.socketDurationInSeconds = (endTime - startConnectTime) / 1000;
obj.isConnected = isConnected;
obj.firstConnection = firstConnection;
obj.timeoutTime_userconnect = timeoutTime_userconnect;
obj.tryToReconnect = tryToReconnect;
obj.pos = 5217;
//obj.sendChatDelay = sendChatDelay;
if (sessionStorageGet('chattext')){
obj.chattext = sessionStorageGet('chattext').substring(0,20);
}
socket.emit('sendchat', msg, undefined, 1, 0, 5217, num_connected, clientId, secretKey, obj); // to dialogid den to apothikeuo topika , to vrisko ston server apo to socketsession
// to 1 simainei oti einai typing insights
}
}
//$ ('.chat_message textarea').on('paste', function (e) { // gia na liso to bug, otan meta apo disconnect ekane paste kai send o visitor, den douleue
document.getElementById("onwc_chat_message_div").addEventListener("paste", function(e){
// if (logging) console.log(" on paste..");
if ((isConnected == false) && (tryToReconnect == false)) {
// if (logging) console.log(" isConnected = false , so try to connect now..")
socketReconnect();
}
setTimeout(function() { checkText2ShowSendButton() } , 0); //fix issue: paste on empty textarea, the send icon was not shown
})
//$ ('.chat_message textarea').on('keypress', function (e) { //keypress deprecated..
document.getElementById("onwc_chat_message_div").addEventListener("keydown", function(e){ // oxi keyup, giati prosthetei allagi grammis sto telos tou text..
// // if (logging) console.log(" on keydown..");
if (e.key == "Enter" && !e.shiftKey) { // enter key
e.preventDefault();
if (!disabledSendButton){
onwebSendText();
clearTimeout(timerInsights);
timerInsights = 0;
}
} else { // oxi enter key
if (hasStartedWriting != 1 && sessionStorageGet('hasStartedWriting') != 1) {
callbackOnStartWriting();
sessionStorageSet('hasStartedWriting', 1);
}
hasStartedWriting = 1;
if ((isConnected == false) && (tryToReconnect == false)) {
// if (logging) console.log(" isConnected = false , so try to connect now..")
socketReconnect();
}
if (typing == 0 && blocked == 0) {
if (chatWithBot != 1){
endTime = getCurrentTime();
obj={};
obj.vesrion = version;
obj.durationInSeconds = (endTime - startTime) / 1000;
obj.socketDurationInSeconds = (endTime - startConnectTime) / 1000;
obj.isConnected = isConnected;
obj.firstConnection = firstConnection;
obj.timeoutTime_userconnect = timeoutTime_userconnect;
obj.tryToReconnect = tryToReconnect;
obj.pos = 5265;
//obj.sendChatDelay = sendChatDelay;
if (sessionStorageGet('chattext')){
obj.chattext = sessionStorageGet('chattext').substring(0,20);
}
socket.emit('sendchat', 'command:typing...', undefined, 0, 0, 5265, num_connected, clientId, secretKey, obj);
}
typing = 1;
}
if (plan != 'free') {
if (timerInsights == 0) {
timerInsights = setTimeout(function () { onwebSendTextInsights(); timerInsights = 0; }, 250); // itan 500!!
}
}
clearTimeout(timer);// paei sto apo kato, an exei meinei allo timer apo prin na svisei to proigoumeno!
timer = setTimeout(function () {
typing = 0;
clearTimeout(timerInsights);
if (chatWithBot != 1){
endTime = getCurrentTime();
obj={};
obj.vesrion = version;
obj.durationInSeconds = (endTime - startTime) / 1000;
obj.socketDurationInSeconds = (endTime - startConnectTime) / 1000;
obj.isConnected = isConnected;
obj.firstConnection = firstConnection;
obj.timeoutTime_userconnect = timeoutTime_userconnect;
obj.tryToReconnect = tryToReconnect;
obj.pos = 5281;
//obj.sendChatDelay = sendChatDelay;
if (sessionStorageGet('chattext')){
obj.chattext = sessionStorageGet('chattext').substring(0,20);
}
socket.emit('sendchat', 'command:notyping...', undefined, 0, 0, 5281, num_connected, clientId, secretKey, obj);
}
}, 1800); //1800
}
});
//$ ('#wb-send-image').on('click', function (e) {
document.getElementById("wb-send-image").addEventListener("click", function(e){
onwebSendText();
if (!isMobile) document.getElementById("onwbtxtarea").focus(); // for not force soft keyboard to show on mobiles
checkText2ShowSendButton();
});
isRTLlanguage = function (text) {
var pattern = /[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\uFB50-\uFC3F\uFE70-\uFEFC]/;
result = pattern.test(text);
return result;
}
function checkPredefinedRTL() {
if (isRTLlanguage(getText('max_placeholder', language).trim().substring(0, 2))) { // an o protos i deuteros xaraktiras einai aravika, evraika, persian.., tote vazo to direction rtl !
setChatTextareaRTL("rtl", "right");
} else {
setChatTextareaRTL("", "left");
}
}
checkPredefinedRTL();
//$ ('.chat_message textarea').on('keyup', function (e) {
document.getElementById("onwc_chat_message_div").addEventListener("keyup", function(e){
// // if (logging) console.log("keyup code:" + e.key + " lastSentMsg:" + lastSentMsg);
if (e.key == 'ArrowUp' && document.getElementById('onwbtxtarea').value == '') { // otan patisei to pano velaki grafei to last sent keimeno
// if (logging) console.log("keyup2");
document.getElementById('onwbtxtarea').value = lastSentMsg;
}
// // if (logging) console.log("is isRTLlanguage:" + isRTLlanguage(//$ ('#onwbtxtarea').val().trim().substring(0,2)));
if (document.getElementById('onwbtxtarea').value.trim().substring(0, 2) != "") {
if (isRTLlanguage(document.getElementById('onwbtxtarea').value.trim().substring(0, 2))) { // an o protos i deuteros xaraktiras einai aravika, evraika, persian.., tote vazo to direction rtl !
setChatTextareaRTL("rtl", "right");
} else {
setChatTextareaRTL("", "left");
}
} else if (document.getElementById('onwbtxtarea').value == "") { // tote dixnei to predefined text (placeholder)
checkPredefinedRTL();
}
if (consent_use == 1 && getCookie('consentvalue') != 1 && getCookie('consentvalue') != 2) {
//console.log("consent_use:" + consent_use + " consentvalue-cookie:" + getCookie('consentvalue'));
toggleModal("onwcConsentModal", true); // emfanizo to consent modal
//
}
checkText2ShowSendButton();
});
checkText2ShowSendButton = function () {
if (document.getElementById('onwbtxtarea').value == "") { // show/hide send button
document.getElementById("wb-send-image").style.visibility = "hidden";
} else {
document.getElementById("wb-send-image").style.visibility = "visible";
}
}
checkText2ShowSendButton();
function setChatTextareaRTL(direction, textalign) {
//$ ('.chat_message textarea')[0].style.setProperty("direction", direction, "important");
document.getElementById('onwbtxtarea').style.setProperty("direction", direction, "important");
//$ ('.chat_message textarea')[0].style.setProperty("text-align", textalign, "important");
document.getElementById('onwbtxtarea').style.setProperty("text-align", textalign, "important");
}
//$ ('#onwebchatemailtext').on('keyup', function (e) { // elegxos gia rtl sto offline form
document.getElementById('onwebchatemailtext').addEventListener("keyup", function(e) {
//// // if (logging) console.log("is onwebchatemailtext isRTLlanguage:" + isRTLlanguage(//$ ('#onwebchatemailtext').val().substring(0,2)));
//if (isRTLlanguage($ ('#onwebchatemailtext').val().substring(0, 2))) { // an o protos i deuteros xaraktiras einai aravika, evraika, persian.., tote vazo to direction rtl !
if (isRTLlanguage(document.getElementById('onwebchatemailtext').value.substring(0, 2))) { // an o protos i deuteros xaraktiras einai aravika, evraika, persian.., tote vazo to direction rtl!
document.getElementById("onwebchatemailtext").style.setProperty("direction", "rtl", "important");
document.getElementById("onwebchatemailtext").style.setProperty("text-align", "right", "important");
} else {
document.getElementById("onwebchatemailtext").style.setProperty("direction", "", "important");
document.getElementById("onwebchatemailtext").style.setProperty("text-align", "left", "important");
}
});
//$ ('#onprechattext').on('keyup', function (e) { // elegxos gia rtl sto prechat form
document.getElementById('onprechattext').addEventListener("keyup", function(e) {
// // if (logging) console.log("is onprechattext isRTLlanguage:" + isRTLlanguage(//$ ('#onprechattext').val().substring(0,2)));
//if (isRTLlanguage($ ('#onprechattext').val().substring(0, 2))) { // an o protos i deuteros xaraktiras einai aravika, evraika, persian.., tote vazo to direction rtl !
if (isRTLlanguage(document.getElementById("onprechattext").value.substring(0, 2))) { // an o protos i deuteros xaraktiras einai aravika, evraika, persian.., tote vazo to direction rtl !
document.getElementById("onprechattext").style.setProperty("direction", "rtl", "important");
document.getElementById("onprechattext").style.setProperty("text-align", "right", "important");
} else {
document.getElementById("onprechattext").style.setProperty("direction", "", "important");
document.getElementById("onprechattext").style.setProperty("text-align", "left", "important");
}
});
var mouseDownNow = 0;
var diffX, diffY;
var onwebchatWidth = parseInt(document.getElementById("onwbchat_window").style.getPropertyValue('width'));
//var onwebchatHeight = parseInt(//$ ("#onwbchat_window").css('height')); // auto allazei an o xristis kanei min/max ara prepei na mpei mesa stin divMove
function onwbmouseUp() {
window.removeEventListener('mousemove', onwbdivMove, true);
}
function onwbmouseDown(e) {
var targ;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
// if (logging) { console.log("onwbmouseDown: e:" + targ.id); }
if (targ.id != "onweb_minimize_btn_icon_id") { // gia na min to kano move , otan patiso sto min. icon (giati merikes fores to patousame k den epiane to min. - profanos kounouse ligo to mouse)
if (sessionStorageGet('maxChat') == 1) {
mouseDownNow = 1;
window.addEventListener('mousemove', onwbdivMove, true);
//$ ("#webchat_header").css('cursor', 'move'); // den paizei giati exo important sto css to cursor: pointer !important;
document.getElementById("webchat_header").style.setProperty('cursor', 'move'); // den paizei giati exo important sto css to cursor: pointer !important;
}
}
}
function onwbdivMove(e) { // not running for mobiles
var windowHeight = window.innerHeight; //$ (window).height(); // auta prepei na einai mesa stin sinartisi onwbdivMove , giati allios mporei na allaxoun (an kanei resize o visitor ton browser) k meta den paizei sosta
var windowWidth = Math.max( document.documentElement["clientWidth"],document.body["scrollWidth"],document.documentElement["scrollWidth"],document.body["offsetWidth"], document.documentElement["offsetWidth"]);
// // if (logging) console.log("windowHeight:"+windowHeight+ " .. " + window.screen.height + " , " + window.innerHeight);
// if (logging) console.log("windowWidth:"+windowWidth+ " .. " + window.screen.width + " , " + window.innerWidth);
var onwebchatHeight = parseInt(document.getElementById("onwbchat_window").style.getPropertyValue('height'));
var onwebchatWidth = parseInt(document.getElementById("onwbchat_window").offsetWidth);
var posX = e.clientX, posY = e.clientY;
if (mouseDownNow == 1) { // tin proti fora (molis..) pou paei na kounisei to mouse ..
var scrollTop = document.body.scrollTop; //$ (window).scrollTop(); //Get the current vertical position of the scroll bar for the first element in the set of matched elements
var scrollLeft = document.body.scrollLeft; //$ (window).scrollLeft();
divTop = document.getElementById('onwbchat_window').offsetTop - scrollTop; //document.body.offsetTop - scrollTop; //$ ("#webchat_header").offset().top - scrollTop; // to scrolltop giati allios lathos ipologismos se megali selida me scroll ..
divLeft = document.getElementById('onwbchat_window').offsetLeft - scrollLeft; //$ ("#webchat_header").offset().left - scrollLeft;
diffX = posX - divLeft;
diffY = posY - divTop;
////////////
// divBottom = windowHeight-(divTop + onwebchatHeight);
// divRight = windowWidth-(divLeft + onwebchatWidth);
/////////////
// // if (logging) console.log("divTop:"+divTop + " divLeft:"+ divLeft);
// // if (logging) console.log("divBottom:"+divBottom + " divRight:"+ divRight);
}
// // if (logging) console.log("posY:"+posY + " posX:"+posX);
mouseDownNow = 0;
isMoving = 1;
var onwbchat_windowDiv = document.getElementById('onwbchat_window');
onwbchat_windowDiv.style.position = 'absolute';
onwbchtMaxY = posY - diffY; // to apothikeuo se global metavliti (tin dilono pano pano) gia na mporo na epistrefo stin thesi auti otan kanei maximize
if ((posY - diffY) < 0) onwbchtMaxY = 0; //vazo ta if gia na min xanetai to chat parathiro ektos tis othonis k meta den mporo na to fero piso!
if ((posY - diffY) > windowHeight - onwebchatHeight) onwbchtMaxY = windowHeight - onwebchatHeight;
onwbchat_windowDiv.style.top = onwbchtMaxY + 'px';
//onwbchat_windowDiv.style.bottom = (windowHeight-onwbchtMaxY-onwebchatHeight) + 'px';
// // if (logging) console.log(windowHeight-onwbchtMaxY-onwebchatHeight);
onwbchtMaxX = posX - diffX;
// if (logging) console.log("posX-diffX:"+ (posX - diffX) + " windowWidth - onwebchatWidth:" + (windowWidth - onwebchatWidth));
if ((posX - diffX) < 0) onwbchtMaxX = 0;
if ((posX - diffX) > windowWidth - onwebchatWidth) onwbchtMaxX = windowWidth - onwebchatWidth;
onwbchat_windowDiv.style.left = onwbchtMaxX + 'px';
/////////////
//$ ('.onwebchatbox').css('right', 'initial'); isos auto diorthonei to provlima me ta aravika site, pu den kanei move to open windget dexia - aristera... thelei kalo testing..
}
try {
if (!isMobile) { // for mobiles I don't need moving chat widget feature (also causes some issues on some sites)
document.getElementById('webchat_header').addEventListener('mousedown', onwbmouseDown, false);
}
document.getElementById('onweb_minimize_btn_icon_id').removeEventListener('mousedown', onwbmouseDown);
window.addEventListener('mouseup', onwbmouseUp, false);
} catch (err) {
// if (logging) console.log("error on 11112 : " + err);
}
//callbackOnWebChatLoaded(); // callback oti exei ginei loaded to chat widget
setTimeout(function () { callbackOnWebChatLoaded(); }, 500);
//telika evala kathisterisi 0,5 sec (16/7/2021) giati ithela prota na stelnei o server to updateclientdetails (an xreiazetai), k meta na trexei to callback,
//etsi oste i onWebChat.set("onWebChatLoaded",function(){ console.log(" getname:" + onWebChat.get("name")); }) na epistrefei to sosto apotelesma
} //ioconnect
//ADD TO CHAT AREA
function printChat(text, class_name, inOuterAgentBubble) { // addchat addmessage class_name:'me' or '' // to ekana etsi function printChat( ... gia na paizei to "go to definition" tou visual studio code
//to pureText einai mono to keimeno, xoris to agent image klp. gia to outer_agent_bubble
//printChat = function (text, class_name) {
if (inOuterAgentBubble && (sessionStorageGet('maxChat') == 1) ){ // not show the outer agent bubble if the chat widget is maximized
inOuterAgentBubble = false;
}
// if (logging) console.log("prinChat printchat! " + text);
if (class_name == undefined) class_name ="";
let onwcouter_class ="onwcouter_agent";
if (class_name == "me"){
onwcouter_class ="onwcouter_me";
}
// if (logging) console.log("princhat: text:" + text + " class_name: " + class_name);
if (document.getElementById("onwc_welcome_message")) document.getElementById('onwc_welcome_message').style.display = "none";
if (document.getElementById("triangle_down")) document.getElementById("triangle_down").style.setProperty("display", "none");
text = convertMarkdownLinksToHTML(text); // Replace found markdown links with HTML
tags
// eg [Link Text](http://link) or [Link Text](https://link) to Link Text for ai chatbot answers mainly
// if (logging) console.log("after convertMarkdownLinksToHTML: text:" + text );
//replace links starting with http https ftp or file
// check the link not already be inside an
.. element
//var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; // auto eixa mexri tin 15/3/2019
// meta evala k to (?![-A-Z0-9+\/:.]*smsbox.gr) gia na MIN antikathisto ta url ton operator images!
//var exp = /(\b(https?|ftp|file):\/\/(?![-A-Z0-9+\/:.]*filesUpload\/operatorImages)[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; // up to 28/3/24
//var exp = /(?]*href=["'])(\b(https?|ftp|file):\/\/(?![-A-Z0-9+\/:.]*filesUpload\/operatorImages)[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])(?!<\/a>)/ig; // up to 18/5/24
var exp = /(?]*href=["'])(?)/ig; //up to 6/7/24 (problem sta iphone 14 (ios 16.2), error and not showing the chat widget)
//var exp = /((https?|ftp|file):\/\/(?![-A-Z0-9+&@#\/:.]*filesUpload\/operatorImages)[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])(?![^<]*<\/a>)/ig; // new one?
var urlst1 = exp.exec(text);
if (urlst1 != null) {
urlst1 = urlst1[0];
var urldomain = extractDomain(urlst1);
// if (logging) console.log("urlDomain (a): " + urldomain + " url:" + urlst1);
if (urldomain == extractDomain(window.location.href)) {// idio domain , ara to anoigo sto idio tab
text = text.replace(exp, "$1 ");
// if (logging) console.log("urlDomain (a): " + urldomain + " href:"+ extractDomain(window.location.href));
} else
text = text.replace(exp, "$1 "); // neo tab (allo domain - den thelo na figei apo tin selida..)
}
// if (logging) console.log("after urlst1 link update:: text:" + text );
//=====================================================================================================================
// replace urls starting with www. (den prepei na exei prin // , giati tha evaze kai apo to proigoumeno exp)
// check the link not already be inside an .. element
//var exp = /(^|[^\/])(www\.[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; // up to 28/3/24
var exp = /(?]*href=["'])(?)/ig; // up to 6/7/2024 //problem with iphone 14 , ios 16.2
var urlst2 = exp.exec(text);
// function filterUrls(text) { // added on 6/7/2024
// // Match URLs using the regular expression
// var exp = /(^|[^\/])(www\.[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|])|(https?|ftp|file):\/\/(?![-a-zA-Z0-9+&@#\/:.]*filesUpload\/operatorImages)[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]/ig;
// var matches = text.match(exp) || [];
// // Filter out URLs that are within tags
// return matches.filter(function(url) {
// var escapedUrl = url.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// var withinATagRegex = new RegExp(' ]*href=["\'].*' + escapedUrl + '.*["\']', 'i');
// return !withinATagRegex.test(text);
// });
// }
///
// function processText(text) {
// var urls = filterUrls(text);
// urls.forEach(function(url) {
// url = url.trim(); // trim spaces
// var urldomain = extractDomain(url);
// // if (logging) console.log("urlDomain (b):" + urldomain + " i am in : " + extractDomain(window.location.href));
// if (urldomain == extractDomain(window.location.href))
// text = text.replace(url, " " + url + " ");
// else
// text = text.replace(url, "" + url + " ");
// });
// // if (logging) console.log("after urlst2 link update:: text:" + text);
// return text;
// }
// text = processText(text);
if (urlst2 != null) { // up to 6/7/2024
urlst2 = urlst2[0];
var urldomain = extractDomain(urlst2);
// if (logging) console.log("urlDomain (b):" + urldomain + " i am in : " + extractDomain(window.location.href));
if (urldomain == extractDomain(window.location.href))
text = text.replace(exp, "$1$2 ");
else
text = text.replace(exp, "$1$2 ");
}
// if (logging) console.log("after urlst2 link update:: text:" + text );
// operator send file
var isImage = false;
while (text.indexOf("{{fileuploaded:") > -1) { // an iparxei to .. // px {{fileuploaded:agent_gAFhdETWXQ5eAhqKmjjcarFS/image.png}}
var pos1 = text.indexOf("{{fileuploaded:") + 1;
var pos2 = text.indexOf("{{fileuploaded:") + 15;
var pos3 = text.indexOf("}}", pos2); // start search from pos2
var fileUrl = text.substring(pos2, pos3);
var filename = fileUrl.replace(/^.*[\\\/]/, '');
// if (logging) console.log("filename:" + filename);
var temp = "";
if (filename.toLowerCase().endsWith(".png") || (filename.toLowerCase().endsWith(".jpg")) || (filename.toLowerCase().endsWith(".jpeg")) || (filename.toLowerCase().endsWith(".svg")) || (filename.toLowerCase().endsWith(".gif"))) {
isImage = true;
imageNumberId++;
//
//$ ('#onwbchat_window .chat_area').animate({scrollTop: 9999999},200);
temp = ' ';
//setTimeout(function(){ document.getElementById('chat_area_id').scrollTop=document.getElementById('chat_area_id').scrollHeight; },1000); //10 msec
} else {
temp = ' ' + filename + ' ';
}
text = text.replace("{{fileuploaded:" + fileUrl + "}}", temp);
}
var allemoticons = "😀😬😁😂😃😄😅😆😇😉😊🙂🙃😋😌😍😘😗😙😚😜😝😛🤑🤓😎🤗😏😶😐😒🙄🤔😳😞😟😠😡😔😕🙁😣😖😫😩😤😱😨😰😯😦😧😢😪😓😭😵😲🤐🤒🤕😴😮👍👎👏🤝💓🙏🙋😈😷";
// //if (String.fromCodePoint){
// //for (var i=0; i' + emoti + '');
// //text = text.replace(/😁/g,'😁 ');
}
text = text.replace('[loading...]', ' ');
text = text.replace(/{{newline}}/g, ' '); // otan o operator pataei shift+enter
var current = new Date();
var hours = current.getHours();
var minutes = current.getMinutes();
if (minutes<10) minutes = "0"+ minutes;
if (inOuterAgentBubble){
let pureOuterBubbleText = cleanHtmlString(text);
if (document.getElementById('outer_agent_bubble_span')){
document.getElementById("outer_agent_bubble").style.setProperty("display", "grid", "important");
//document.getElementById('outer_agent_bubble_span').insertAdjacentHTML("beforeend", pureText);
document.getElementById('outer_agent_bubble_span').insertAdjacentHTML("beforeend", pureOuterBubbleText );
}
sessionStorageSet('outeragentbubbletext', pureOuterBubbleText); // save the text, so if the visitor goes to another page (without any more texts) it will be shown again
} else { // if not the first message, the clear the outeragentbubbletext, so it will not shown again
sessionStorageRemove('outeragentbubbletext');
}
//edo allages mono an to session chattext einai keno na to emfanizo sto outer_agent_bubble_span
// if (logging) console.log("session chattext 1");
// if (logging) console.log("session chattext:" + sessionStorageGet('chattext'));
//gia tin emfanisi tis oras
if (text.indexOf("server_messages") == -1) {
text = " " + text + "
"+ hours +":" + minutes + "
";
}
// INSERT-APPEND TEXT TO CHAT AREA
if (document.getElementById('agenttypingimage') != null) {
//$ ('#onwbchat_window .chat_area #agenttypingimage').before(text); // an fenetai i typing eikona, tote valto prin autin, oxi sto telos!
document.getElementById('agenttypingimage').insertAdjacentHTML("beforebegin", text); // an fenetai i typing eikona, tote valto prin autin, oxi sto telos!
} else {
//$ ('#onwbchat_window .chat_area').append(text);
if (document.getElementById('chat_area_id')) document.getElementById('chat_area_id').insertAdjacentHTML("beforeend", text);
}
//$ ('#onwbchat_window .chat_area').animate({ scrollTop: 9999999 }, 200);
//var countLines = (text.match(/ /g) || []).length; //metrao tis allages grammis
//countLines = countLines + parseInt(text.length/40); // an einai megalo keimeno , prostheto kai merikes grammes akoma, analogos to megethos tou keimenou..
// // if (logging) console.log("countlines:" + countLines + " text length:" + text.length + " " + parseInt(text.length/40) + " text:" + text);
//my_animate(document.getElementById("chat_area_id"), 1, 60 * countLines, 4); // scrollaro gia na fainontai auta pou egrapse..
my_animate2(document.getElementById("chat_area_id"), 20, 4);
//startSmoothScroll();
setTimeout(function () { my_animate2(document.getElementById("chat_area_id"), 20, 1); }, 500); //mono me to pano den douleue panta..
if (sessionStorageGet('chattext')) { // if (localStorage.chattext)
sessionStorageSet('chattext', sessionStorageGet('chattext') + text);
// // if (logging) console.log("1");
} else {
sessionStorageSet('chattext', text);
// // if (logging) console.log("2");
}
if (isIE() != 8) { // to socket.close ston ie8 petaei ena error ston browser (stack overflow, out of memory..), den xero an mporei o server na kleisei to connection..
clearTimeout(socketTimeoutTimer); // kathe fora pou kano print ena chat, katharizo kai theto to socketTimeOutmsec
socketTimeoutTimer = setTimeout(function () {
// if (logging) console.log("socketTimeoutTimer3.. will disconnect now");
socket.io.disconnect();
minimizeChatWindow();
}, socketTimeOutmsec); //close socket if client is more than 6 hours on the same page
}
enableMenuItem("onwebchat-print-li");
enableMenuItem("onwebchat-savetofile-li");
if (emailsSentLastHour < 6) {
enableMenuItem("onwebchat-email-li");
}
enableMenuItem('onwebchat-endchat-li');
endChatButtonEnabled = true;
//addEndChat2Menu();
// ftiaxno ta grafika gia mikra chat window!
if (chatWidth < 340) {
//$ (".operatorImageSmallClass").css("zoom", "0.9");
var els = document.getElementsByClassName('operatorImageSmallClass');
[].forEach.call(els, function (el) { el.style.zoom = "0.9";});
}
checkMobileChatHeight();
} // end printChat function
function cleanHtmlString(htmlString) {
// Create a temporary DOM element to parse the HTML string
var tempDiv = document.createElement('div');
tempDiv.innerHTML = htmlString;
// Remove the img element
var imgElement = tempDiv.querySelector('img');
if (imgElement) {
imgElement.remove();
}
// Remove the span with class 'spanbold'
var spanBoldElement = tempDiv.querySelector('span.spanbold');
if (spanBoldElement) {
spanBoldElement.remove();
}
// Get the inner HTML of the temporary div, which contains the cleaned content
var cleanedHtml = tempDiv.innerHTML;
// Remove the outer tags
cleanedHtml = cleanedHtml.replace(/^
]*>/, '').replace(/<\/p>$/, '');
return cleanedHtml;
}
function convertMarkdownLinksToHTML(inputText) {
// Regular expression to find markdown links in the input text
// This regex matches patterns like [Link Text](http://link) or [Link Text](https://link)
//const markdownLinkRegex = /\[([^\]]+)\]\((http:\/\/|https:\/\/[^\)]+)\)/g; // up to 18/5/24
if (inputText) {
// Regular expression to find markdown links in the input text
// This regex matches patterns like [Link Text](http://link), [Link Text](https://link), or [Link Text](www.link)
const markdownLinkRegex = /\[([^\]]+)\]\(((http:\/\/|https:\/\/|www\.)[^\)]+)\)/g;
// Replace found markdown links with HTML tags
const convertedText = inputText.replace(markdownLinkRegex, (match, text, link) => {
// Ensure the href has a protocol
if (link.startsWith("www.")) {
link = "https://" + link; // ??
}
return ` ${text} `;
});
return convertedText;
} else return "";
}
// Set the animation duration
let duration = 900; // 1000ms = 1s
let startTimeScroll = null;
// exo ftiaxei kai tin my_animate2!!
// function startSmoothScroll() {
// let element = document.getElementById('chat_area_id');
// let startY = element.scrollTop;
// let targetY = element.scrollHeight - element.clientHeight; // target is bottom of div
// // Reset variables for new scroll
// startY = element.scrollTop;
// targetY = element.scrollHeight - element.clientHeight;
// startTimeScroll = null;
// // Start the animation
// window.requestAnimationFrame(smoothScroll);
// }
// function smoothScroll(currentTime) {
// let element = document.getElementById('chat_area_id');
// let startY = element.scrollTop;
// let targetY = element.scrollHeight - element.clientHeight; // target is bottom of div
// console.log("-----------------------------------");
// console.log("startY:" + startY);
// console.log("targetY:" + startY);
// console.log("currentTime:" + currentTime);
// console.log("startTimeScroll:" + startTimeScroll);
// // Capture the start time
// if (!startTimeScroll) {
// startTimeScroll = currentTime;
// }
// // Calculate elapsed time
// const timeElapsed = currentTime - startTimeScroll;
// console.log("timeElapsed:" + timeElapsed);
// // Calculate the current Y position
// const newY = easeInOutQuad(timeElapsed, startY, targetY - startY, duration);
// console.log("newY:" + newY);
// // Scroll to new Y position
// element.scrollTop = newY;
// // Continue to animate if we're still within the duration
// if (timeElapsed < duration) {
// window.requestAnimationFrame(smoothScroll);
// }
// }
// Easing function (easeInOutQuad)
// function easeInOutQuad(t, b, c, d) {
// t /= d / 2;
// if (t < 1) return c / 2 * t * t + b;
// t--;
// return -c / 2 * (t * (t - 2) - 1) + b;
// }
//} // loadAllAfterJquery
// if (window.jQuery){
// // if (logging) { if ($ && $.fn) { console.log("$ jquery already loaded from the webpage, version: " + $.fn.jquery); } }
// }
// if (window.jQuery && $ && $(document).on ) {
// // elegxo an iparxei i sinartisi //$ (document).on , giati den iparxei sta jquery apo 1.0 eos 1.6, opote tote fortono to diko mou .. episis thema me to mouseenter mouseleave..
// // if (logging) { if ($ && $.fn) { console.log("$ jquery already loaded from the webpage, version: " + $.fn.jquery + " iparxei kai i //$ (document).on "); } }
// loadAllAfterJquery();
// }
// else {
// // if (logging) { console.log(" jquery not loaded from the page, so load it now"); }
// loadJS(protocol + '//ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.slim.min.js', loadAllAfterJquery );
// }
return {
init : function(Args) {
_args = Args;
// some other initialising
},
/*setLanguage : function(lang) { //only set clientName , not save to cookie
// if (logging) {
console.log(" setLanguage (2)** : " + lang);
}
if (document.getElementById("div_chat_min_title")!=null) {
//document.getElementById("div_chat_min_title").innerHTML = '
'+getText('title', language) '
'; thelei diorthosi!!!
}
},
setName : function(name) {
//setNameApi = true;
clientName = name;
//setCookie('clientname', name, 365);
},
//setName2 : function(Args) { //only set clientName , not save to cookie
// clientName = Args;
//},
getName : function() {
return clientName;
},*/
// episis na kano search gia to "try{ // set api for chrome, firefox, ie.." , opou ekei kano set otan kanei load to widget
set : function(pro, value){ // for opera (on chat load) and for all after widget has loaded (episis mono edo ta get functions, afou prepei na ektelestoun, meta pou exei ginei load!)
if (pro=="name" && blocked == 0) {
clientName = value;
// if (logging) console.log("set name:"+value);
try{ // try mipos den iparxei to socket? pote? sto preconnect=0?
socket.emit('setclientdetails', clientId, siteId, clientName, "", "", ""); // exei ginei connect tora ara prepei na kano emit ta nea stoixeia
}catch(err){
// if (logging) console.log("error on set : " + err);
}
} else if (pro=="email" && blocked == 0) {
clientEmail = value;
try{
socket.emit('setclientdetails', clientId, siteId, "", clientEmail, "", ""); // exei ginei connect tora ara prepei na kano emit ta nea stoixeia
}catch(err){
// if (logging) console.log("error on set : " + err);
}
} else if (pro=="phone" && blocked == 0) {
clientPhone = value;
try {
socket.emit('setclientdetails', clientId, siteId, "", "", clientPhone, ""); // exei ginei connect tora ara prepei na kano emit ta nea stoixeia
}catch(err){
// if (logging) console.log("error on set : " + err);
}
} else if (pro=="notes" && blocked == 0) {
clientNotes = value;
try{
socket.emit('setclientdetails', clientId, siteId, "", "", "", clientNotes); // exei ginei connect tora ara prepei na kano emit ta nea stoixeia
}catch(err){
// if (logging) console.log("error on set : " + err);
}
} else if (pro=="pageUrl" && blocked == 0) {
try{
socket.emit('setclientpageurl', clientId, siteId, "", value); // exei ginei connect tora ara prepei na kano emit ta nea stoixeia
}catch(err){
// if (logging) console.log("error on set : " + err);
}
} else if (pro=="pageTitle" && blocked == 0) {
try {
socket.emit('setclientpageurl', clientId, siteId, value, ""); // exei ginei connect tora ara prepei na kano emit ta nea stoixeia
}catch(err){
// if (logging) console.log("error on set : " + err);
}
} else if (pro=="max" && blocked == 0) {
if (value == 1) {
//socket.emit('chatWindowMax', 1);
//sessionStorage.maxChat=1;
maximizeChatWindow();
document.getElementById("onwbtxtarea").focus(); // focus chat textarea
}else if (value == 0) {
//socket.emit('chatWindowMax', 0);
//sessionStorage.maxChat=0;
minimizeChatWindow();
}
} else if (pro=="show" && blocked == 0) {
if (value == 1) {
showChatApi =1;
showChatWindow();
}else if (value == 0) {
showChatApi = 0;
hideChatWindow();
}
} else if (pro=="online" && blocked == 0) { // only for me (testing) // BUG 8-7-23 => telika to evgala, giati mporei na to eidan k alloi kai na stelnoun polla msg se diafora offline sites..
// if (value == 1) {
// agentOnline=1;
// showChatWindow();
// }else if (value == 0) {
// agentOnline=0;
// showChatWindow();
// }
} else if (pro=="hideImage" && blocked == 0) {
if (value == 1) {
// if (logging) console.log(" set hideImage: )!!! : " + value);
}else if (value == 0) {
// if (logging) console.log(" set hideImage: )!!! : " + value);
}
} else if (pro=="language" && blocked == 0) {
language = value;
// if (logging) console.log(" setLanguage (2)!!! : " + language);
if (language == 'gr' || language == 'el') {
language = 'l1';
}
if (language == 'en') {
language = 'l2';
}
if (language!='l1' && language != 'l2') {
language= 'l1';
}
// if (logging) console.log(" final language : " + language);
} else if ( pro =="languageFile" && blocked == 0) {
languageFile=""; //value
// if (logging) console.log("prosoxi !! languageFile set (set function..) : " + languageFile+ " mallon me opera, opote den to ipostririzo pros to paron " );
} else if ( pro =="onClick" && blocked == 0) {
callbackOnClick=value;
} else if ( pro =="onMaximize" && blocked == 0) {
callbackOnMaximize=value;
} else if ( pro =="onMinimize" && blocked == 0) {
callbackOnMinimize=value;
} else if ( pro =="onTrigger" && blocked == 0) {
callbackOnTrigger=value;
} else if ( pro =="onStartWriting" && blocked == 0) {
callbackOnStartWriting=value;
} else if ( pro =="onUpdateOperators" && blocked == 0) { // temp!!! check!!!
callbackOnUpdateOperators=value;
} else if ( pro =="onNewMessage" && blocked == 0) {
callbackOnNewMessage=value;
} else if ( pro =="onWebChatLoaded" && blocked == 0) {
callbackOnWebChatLoaded=value;
} else if ( pro =="onlineColor" && blocked == 0) {
onlineColor=value;
if (agentOnline==1 && onlineColor!=""){
document.getElementById("webchat_header").style.setProperty('background-color',onlineColor, 'important');
}
} else if ( pro =="offlineColor" && blocked == 0) {
offlineColor=value;
if (agentOnline!=1 && offlineColor!=""){
document.getElementById("webchat_header").style.setProperty('background-color',offlineColor, 'important');
document.getElementById("offlineform_btn").style.setProperty('background-color',offlineColor, 'important');
}
}
},
get : function(pro){
if (pro=="name") {
// if (logging) console.log(" get name:"+clientName);
return clientName;
} else if (pro=="email") {
return clientEmail;
} else if (pro=="phone") {
return clientPhone;
} else if (pro=="notes") {
return clientNotes;
} else if (pro=="status") {
if (agentOnline==1)
return "online";
else
return "offline";
}
else return "";
}
};
}()); // reveal module pattern (define a function and then calling it with module name)