(function(d) {d.innerHTML = '';document.getElementsByTagName('head')[0].appendChild(d.childNodes[0]);})(document.createElement('div'));
(function() {
var server = {
context: 'https://workbench.daokf.cn/kf/',
version: '_1.1',
company: '36',
accountId: '',
srcRes: 'res/customer/',
chatTitle: ''
};
function hasClass(elements, cName) {
return !!elements.className.match( new RegExp( "(\\s|^)" + cName + "(\\s|$)") );
};
function addClass(elements, cName){
if(!hasClass(elements, cName)) {
elements.className += " " + cName;
}
};
function removeClass(elements, cName){
if(hasClass(elements, cName)) {
elements.className = elements.className.replace( new RegExp( "(\\s|^)" + cName + "(\\s|$)" ), " " );
}
};
function $(name) {
if (name[0] == '.')
return document.getElementsByClassName(name.substr(1))[0];
if (name[0] == '#')
return document.getElementById(name.substr(1));
return document.getElementsByTagName(name)[0];
}
function create(tagName) {
return document.createElement(tagName);
}
var chatStartBtn, inited, body;
function anonId() {
function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1);}
return 'anon' + S4()+S4()+S4()+S4()+S4()+S4()+S4()+S4();
}
function getCookieAccountId() {
var k = '_skf_account_id', rex = new RegExp('(?:(?:^|.*;\\s*)' + k + '\\s*\\=\\s*([^;]*).*$)|^.*$'),
v = document.cookie.replace(rex, "$1");
var kv = k + '=' + (v = v || anonId()), expires = new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000).toUTCString;
document.cookie = kv += '; expires=' + expires;
return v;
}
window.onload = function() {
body = $('body');
chatStartBtn = $('.chat_btn');
if(!chatStartBtn) {
chatStartBtn = create('div');
chatStartBtn.setAttribute('style', 'z-index: 100001;position: fixed;bottom: 30px;right: 30px;z-index: 100;width: 50px;height: 50px;background: #52a2ff;border-radius: 50%;color: #fff;font-size: 16px;text-align: center;line-height: 50px;cursor: pointer;box-shadow: 0 10px 20px rgba(0, 0, 0, 0.06);');
chatStartBtn.innerText = '客服';
body.appendChild(chatStartBtn);
}
inited = false;
var wantShow = false;
//联系客服,初始化聊天界面
chatStartBtn.onclick = function() {
if(!inited) {
wantShow = true;
return ;
}
showChatDialog();
}
initWin();
wantShow && showChatDialog();
}
function initWin() {
var company = chatStartBtn.getAttribute("company") || server.company;
var accountId = chatStartBtn.getAttribute("accountId") || chatStartBtn.getAttribute("accountid") || server.accountId || getCookieAccountId();
var fromUrl = window.location.href;
var chatWin = create('div');
chatWin.setAttribute('class', 'chat-win');
chatWin.style.cssText = 'z-index: 10002;box-shadow: 0 10px 20px rgba(0, 0, 0, 0.06);position: fixed;right: 30px;bottom: 30px;font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;color: #fff';
chatWin.style.display = 'none';
// 顶栏
var titleBar = create('div');
titleBar.style.cssText = 'height: 34px;border: none;background-color: #52a2ff;';
chatWin.appendChild(titleBar);
// 创建最小化按钮
var minBtn = create('img');
minBtn.src = server.context + server.srcRes + 'images/chat-header_05.jpg';
minBtn.style.cssText = 'position: absolute;top: 6px;right: 16px;cursor:pointer';
minBtn.onclick = mininate;
chatWin.appendChild(minBtn);
// 标题
var titleContent = create('span');
titleContent.innerText = server.chatTitle || '在线咨询';
titleContent.style.cssText = 'position: absolute;top: 8px;left: 16px;font-size: 12px;';
chatWin.appendChild(titleContent);
// 聊天iframe
var iframeDiv = create('div');
var iframe = create('iframe');
iframe.scrolling= "no";
iframe.src = server.context + "customer/customer_chat?company="+ company +"&accountId="+ accountId + "&fromUrl=" + encodeURIComponent(fromUrl) + "&v=" + server.version;
iframe.style.cssText = 'border: none; width: 320px; height: 448px;';
iframeDiv.appendChild(iframe);
chatWin.appendChild(iframeDiv);
body.appendChild(chatWin);
inited = true;
}
function mininate() {
var chatWin = $('.chat-win');
chatWin.classList.remove('from-kf-auto-css-chat-win-show');
setTimeout(() => {
chatWin.classList.add('from-kf-auto-css-chat-win-hide');
},0);
setTimeout(function() {
chatWin.style.display = 'none';
chatStartBtn.style.display = 'block';
}, 500);
}
function showChatDialog() {
var chatWin = $('.chat-win');
chatWin.classList.remove('from-kf-auto-css-chat-win-hide');
chatWin.classList.add('from-kf-auto-css-chat-win-show');
chatWin.style.display = 'block';
chatStartBtn.style.display = 'none';
}
})();