chat-widget

master
taoshihan 2 weeks ago
parent 85adb1baf2
commit 48398aede7

@ -109,7 +109,7 @@ func PostVisitorLogin(c *gin.Context) {
if kefuInfo.ID == 0 {
c.JSON(200, gin.H{
"code": 400,
"msg": "客服不存在",
"msg": "The customer service account does not exist",
})
return
}

@ -88,18 +88,25 @@ http://127.0.0.1:8081/livechat?user_id=agent
Popup Integration
```
(function(a, b, c, d) {
let h = b.getElementsByTagName('head')[0];let s = b.createElement('script');
s.type = 'text/javascript';s.src = c+"/static/js/kefu-front.js";s.onload = s.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") d(c);
};h.appendChild(s);
})(window, document,"http://127.0.0.1:8081",function(u){
KEFU.init({
KEFU_URL:u,
KEFU_KEFU_ID: "agent",
})
<script>
(function(global, document, scriptUrl, callback) {
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptUrl + "/static/js/chat-widget.js";
script.onload = script.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
callback(scriptUrl);
}
};
head.appendChild(script);
})(window, document, "http://127.0.0.1:8081", function(baseUrl) {
CHAT_WIDGET.initialize({
API_URL: baseUrl,
AGENT_ID: "agent",
});
});
</script>
```
### Important Notice
The use of this project for illegal or non-compliant purposes, including but not limited to viruses, trojans, pornography, gambling, fraud, prohibited items, counterfeit products, false information, cryptocurrencies, and financial violations, is strictly prohibited.

@ -0,0 +1,236 @@
const CHAT_WIDGET = {
API_URL: "",
AGENT_ID: "",
AUTO_OPEN: true,
DISPLAY_MODE: 1,
USER_ID: "",
USER_NAME: "",
USER_AVATAR: "",
isChatOpen: false,
originalPageTitle: document.title,
chatWindowTitle: "Chat with us",
isOffline: false,
iframeId: "chat-widget-iframe",
containerId: "chat-widget-container"
};
CHAT_WIDGET.initialize = function(config) {
// Apply configuration
for (let key in config) {
if (this.hasOwnProperty(key)) {
this[key] = config[key];
}
}
// Normalize URL by removing trailing slash
if (this.API_URL) {
this.API_URL = this.API_URL.replace(/\/$/, "");
}
// Add required CSS styles
this.injectStyles();
// Display the chat button
this.createChatButton();
// Set up event handlers
this.setupEventHandlers();
};
CHAT_WIDGET.injectStyles = function() {
const style = document.createElement('style');
style.textContent = `
#chat-widget-button {
position: fixed;
bottom: 20px;
right: 20px;
width: 60px;
height: 60px;
background-color: #1E88E5;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
z-index: 9999;
}
#chat-widget-button .notification-badge {
position: absolute;
top: -5px;
right: -5px;
background-color: #FF5722;
color: white;
border-radius: 50%;
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
}
#chat-widget-container {
position: fixed;
bottom: 90px;
right: 20px;
width: 350px;
height: 500px;
background: white;
border-radius: 8px;
box-shadow: 0 5px 20px rgba(0,0,0,0.2);
display: none;
flex-direction: column;
z-index: 9998;
overflow: hidden;
}
#chat-widget-header {
padding: 15px;
background: #1E88E5;
color: white;
display: flex;
align-items: center;
}
#chat-widget-iframe {
flex: 1;
border: none;
}
.close-button {
margin-left: auto;
cursor: pointer;
font-size: 20px;
}
`;
document.head.appendChild(style);
};
CHAT_WIDGET.createChatButton = function() {
const button = document.createElement('div');
button.id = 'chat-widget-button';
button.innerHTML = `
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21 15C21 15.5304 20.7893 16.0391 20.4142 16.4142C20.0391 16.7893 19.5304 17 19 17H7L3 21V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H19C19.5304 3 20.0391 3.21071 20.4142 3.58579C20.7893 3.96086 21 4.46957 21 5V15Z" fill="white"/>
</svg>
<div class="notification-badge" style="display: none;">0</div>
`;
document.body.appendChild(button);
button.addEventListener('click', () => {
this.openChatWindow();
});
// Open automatically if configured
if (this.AUTO_OPEN) {
setTimeout(() => {
this.openChatWindow();
}, 3000);
}
};
CHAT_WIDGET.openChatWindow = function() {
if (this.isChatOpen) return;
const badge = document.querySelector('#chat-widget-button .notification-badge');
badge.style.display = 'none';
badge.textContent = '0';
// Create container if it doesn't exist
if (!document.getElementById(this.containerId)) {
const container = document.createElement('div');
container.id = this.containerId;
container.innerHTML = `
<div id="chat-widget-header">
<span>chat with us</span>
<span class="close-button">×</span>
</div>
<iframe id="${this.iframeId}" src="${this.buildChatUrl()}"></iframe>
`;
document.body.appendChild(container);
// Add close button handler
document.querySelector(`#${this.containerId} .close-button`).addEventListener('click', () => {
this.closeChatWindow();
});
}
// Show the chat window
document.getElementById(this.containerId).style.display = 'flex';
this.isChatOpen = true;
// Hide the floating button
document.getElementById('chat-widget-button').style.display = 'none';
};
CHAT_WIDGET.closeChatWindow = function() {
document.getElementById(this.containerId).style.display = 'none';
this.isChatOpen = false;
document.getElementById('chat-widget-button').style.display = 'flex';
};
CHAT_WIDGET.buildChatUrl = function() {
let url = `${this.API_URL}/livechat?user_id=${this.AGENT_ID}`;
if (this.USER_ID) {
url += `&user_id=${this.USER_ID}`;
}
if (this.USER_NAME) {
url += `&name=${encodeURIComponent(this.USER_NAME)}`;
}
if (this.USER_AVATAR) {
url += `&avatar=${encodeURIComponent(this.USER_AVATAR)}`;
}
return url;
};
CHAT_WIDGET.setupEventHandlers = function() {
// Handle messages from the chat iframe
window.addEventListener('message', (e) => {
if (!e.data || !e.data.type) return;
switch (e.data.type) {
case 'new_message':
this.handleIncomingMessage(e.data);
break;
case 'close_chat':
this.closeChatWindow();
break;
}
});
};
CHAT_WIDGET.handleIncomingMessage = function(data) {
// Update notification badge
const badge = document.querySelector('#chat-widget-button .notification-badge');
let count = parseInt(badge.textContent || '0');
if (!this.isChatOpen) {
count++;
badge.textContent = count;
badge.style.display = 'flex';
// Flash title if window is not focused
if (!document.hasFocus()) {
this.notifyWithTitleFlash();
}
}
};
CHAT_WIDGET.notifyWithTitleFlash = function() {
let isFlashing = true;
const flashInterval = setInterval(() => {
document.title = isFlashing ? "New message!" : this.originalPageTitle;
isFlashing = !isFlashing;
}, 1000);
// Stop flashing when window regains focus
window.addEventListener('focus', () => {
clearInterval(flashInterval);
document.title = this.originalPageTitle;
}, { once: true });
};

@ -1,335 +0,0 @@
var GOFLY={
GOFLY_URL:"",
GOFLY_KEFU_ID:"",
GOFLY_BTN_TEXT:"Chat with me",
GOFLY_LANG:"en",
GOFLY_EXTRA: {},
GOFLY_AUTO_OPEN:true,
GOFLY_AUTO_SHOW:false,
GOFLY_WITHOUT_BTN:false,
};
GOFLY.launchButtonFlag=false;
GOFLY.titleTimer=0;
GOFLY.titleNum=0;
GOFLY.noticeTimer=null;
GOFLY.originTitle=document.title;
GOFLY.chatPageTitle="GOFLY";
GOFLY.kefuName="";
GOFLY.kefuAvator="";
GOFLY.init=function(config){
var _this=this;
if(typeof config=="undefined"){
return;
}
if (typeof config.GOFLY_URL!="undefined"){
this.GOFLY_URL=config.GOFLY_URL.replace(/([\w\W]+)\/$/,"$1");
}
this.dynamicLoadCss(this.GOFLY_URL+"/static/css/gofly-front.css?v=1");
if (typeof config.GOFLY_KEFU_ID!="undefined"){
this.GOFLY_KEFU_ID=config.GOFLY_KEFU_ID;
}
if (typeof config.GOFLY_BTN_TEXT!="undefined"){
this.GOFLY_BTN_TEXT=config.GOFLY_BTN_TEXT;
}
if (typeof config.GOFLY_EXTRA!="undefined"){
this.GOFLY_EXTRA=config.GOFLY_EXTRA;
}
if (typeof config.GOFLY_AUTO_OPEN!="undefined"){
this.GOFLY_AUTO_OPEN=config.GOFLY_AUTO_OPEN;
}
if (typeof config.GOFLY_AUTO_SHOW!="undefined"){
this.GOFLY_AUTO_SHOW=config.GOFLY_AUTO_SHOW;
}
if (typeof config.GOFLY_WITHOUT_BTN!="undefined"){
this.GOFLY_WITHOUT_BTN=config.GOFLY_WITHOUT_BTN;
}
var refer=document.referrer?document.referrer:"无";
this.GOFLY_EXTRA.refer=refer;
this.GOFLY_EXTRA.host=document.location.href;
this.GOFLY_EXTRA=JSON.stringify(_this.GOFLY_EXTRA);
this.dynamicLoadJs(this.GOFLY_URL+"/assets/js/functions.js?v=1",function(){
if (typeof config.GOFLY_LANG!="undefined"){
_this.GOFLY_LANG=config.GOFLY_LANG;
}else{
_this.GOFLY_LANG=checkLang();
}
_this.GOFLY_EXTRA=utf8ToB64(_this.GOFLY_EXTRA);
});
if (typeof $!="function"){
this.dynamicLoadJs("https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js",function () {
_this.dynamicLoadJs("https://cdn.staticfile.org/layer/3.4.0/layer.min.js",function () {
_this.jsCallBack();
});
});
}else{
this.dynamicLoadJs("https://cdn.staticfile.org/layer/3.4.0/layer.min.js",function () {
_this.jsCallBack();
});
}
_this.addEventlisten();
}
GOFLY.jsCallBack=function(){
this.showKefuBtn();
this.addClickEvent();
this.getNotice();
}
GOFLY.showKefuBtn=function(){
var _this=this;
if(_this.GOFLY_WITHOUT_BTN){
return;
}
var html="<div class='launchButtonBox'>" +
'<div id="launchButton" class="launchButton">' +
'<div id="launchIcon" class="launchIcon animateUpDown">1</div> ' +
'<div class="launchButtonText">'+_this.GOFLY_BTN_TEXT+'</div></div>' +
'<div id="launchButtonNotice" class="launchButtonNotice"></div>' +
'</div>';
$('body').append(html);
}
GOFLY.addClickEvent=function(){
var _this=this;
$(".launchButton").on("click",function() {
_this.GOFLY_AUTO_SHOW=true;
_this.showKefu();
$("#launchIcon").text(0).hide();
});
$("body").on("click","#launchNoticeClose",function() {
$("#launchButtonNotice").hide();
});
$("body").click(function () {
clearTimeout(_this.titleTimer);
document.title = _this.originTitle;
});
}
GOFLY.addEventlisten=function(){
var _this=this;
window.addEventListener('message',function(e){
var msg=e.data;
if(msg.type=="message"){
clearInterval(_this.noticeTimer);
var width=$(window).width();
if(width>768){
_this.flashTitle();//标题闪烁
}
if (_this.launchButtonFlag){
return;
}
var welcomeHtml="<div class='flyUser'><img class='flyAvatar' src='"+_this.GOFLY_URL+msg.data.avator+"'/> <span class='flyUsername'>"+msg.data.name+"</span>" +
"<span id='launchNoticeClose' class='flyClose'>×</span>" +
"</div>";
welcomeHtml+="<div id='launchNoticeContent'>"+replaceContent(msg.data.content,_this.GOFLY_URL)+"</div>";
$("#launchButtonNotice").html(welcomeHtml).show();
var news=$("#launchIcon").text();
$("#launchIcon").text(++news).show();
}
if(msg.type=="focus"){
clearTimeout(_this.titleTimer);
_this.titleTimer=0;
document.title = _this.originTitle;
}
});
window.onfocus = function () {
clearTimeout(_this.titleTimer);
_this.titleTimer=0;
document.title = _this.originTitle;
};
}
GOFLY.dynamicLoadCss=function(url){
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.type='text/css';
link.rel = 'stylesheet';
link.href = url;
head.appendChild(link);
}
GOFLY.dynamicLoadJs=function(url, callback){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
if(typeof(callback)=='function'){
script.onload = script.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"){
callback();
script.onload = script.onreadystatechange = null;
}
};
}
head.appendChild(script);
}
GOFLY.getNotice=function(){
var _this=this;
$.get(this.GOFLY_URL+"/notice?kefu_id="+this.GOFLY_KEFU_ID,function(res) {
if(res.result.status=='offline'){
_this.chatPageTitle="<div class='launchPointer offline'></div>";
}else{
_this.chatPageTitle="<div class='launchPointer'></div>";
setTimeout(function(){
var userInfo="<img style='margin-top: 5px;' class='flyAvatar' src='"+_this.GOFLY_URL+res.result.avatar+"'/> <span class='flyUsername'>"+res.result.username+"</span>"
$('.launchButtonText').html(userInfo);
},3000);
}
_this.kefuAvator=res.result.avatar;
_this.kefuName=res.result.username;
_this.chatPageTitle+="<img src='"+_this.GOFLY_URL+res.result.avatar+"' class='flyAvatar'>"+res.result.username;
if(_this.GOFLY_AUTO_OPEN&&_this.isIE()<=0){
_this.showKefu();
$(".launchButtonBox").show();
_this.launchButtonFlag=false;
}
if (res.result.welcome != null) {
var msg = res.result.welcome;
var len=msg.length;
var i=0;
if(len>0){
_this.noticeTimer=setInterval(function(){
if(i>=len||typeof msg[i]=="undefined"||msg[i]==null){
clearInterval(_this.noticeTimer);
return;
}
var content = msg[i];
if(typeof content.content =="undefined"){
return;
}
var welcomeHtml="<div class='flyUser'><img class='flyAvatar' src='"+_this.GOFLY_URL+res.result.avatar+"'/> <span class='flyUsername'>"+res.result.username+"</span>" +
"<span id='launchNoticeClose' class='flyClose'>×</span>" +
"</div>";
welcomeHtml+="<div id='launchNoticeContent'>"+replaceContent(content.content,_this.GOFLY_URL)+"</div>";
var obj=$("#launchButtonNotice");
if(obj[0]){
obj[0].innerHTML=welcomeHtml;
obj.show();
}
i++;
$("#launchIcon").text(i).show();
},4000);
}
}
});
}
GOFLY.isIE=function(){
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7) {
return 7;
} else if(fIEVersion == 8) {
return 8;
} else if(fIEVersion == 9) {
return 9;
} else if(fIEVersion == 10) {
return 10;
} else {
return 6;//IE版本<=7
}
} else if(isEdge) {
return 'edge';//edge
} else if(isIE11) {
return 11; //IE11
}else{
return -1;//不是ie浏览器
}
}
GOFLY.showPanel=function (){
var width=$(window).width();
this.GOFLY_AUTO_SHOW=true;
if(this.isIE()>0){
this.windowOpen();
return;
}
if(width<768){
this.layerOpen("100%","100%");
return;
}
this.layerOpen("400px","530px");
this.launchButtonFlag=true;
}
GOFLY.showKefu=function (){
if (this.launchButtonFlag) return;
var width=$(window).width();
if(this.isIE()>0){
this.windowOpen();
return;
}
if(width<768){
this.layerOpen("100%","100%");
return;
}
this.layerOpen("400px","530px");
this.launchButtonFlag=true;
$(".launchButtonBox").hide();
}
GOFLY.layerOpen=function (width,height){
if (this.launchButtonFlag) return;
var layBox=$("#layui-layer19911116");
if(layBox.css("display")=="none"){
layBox.show();
return;
}
var _this=this;
layer.index="19911115";
layer.open({
type: 2,
title: this.chatPageTitle,
closeBtn: 1, //不显示关闭按钮
shade: 0,
area: [width, height],
offset: 'rb', //右下角弹出
anim: 2,
content: [this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&lang='+this.GOFLY_LANG+'&refer='+window.document.title+'&extra='+this.GOFLY_EXTRA , 'yes'], //iframe的urlno代表不显示滚动条
success:function(){
var layBox=$("#layui-layer19911116");
if(_this.GOFLY_AUTO_SHOW&&layBox.css("display")=="none"){
_this.launchButtonFlag=true;
layBox.show();
}
},
end: function(){
_this.launchButtonFlag=false;
$(".launchButtonBox").show();
},
cancel: function(index, layero){
$("#layui-layer19911116").hide();
_this.launchButtonFlag=false;
$(".launchButtonBox").show();
return false;
}
});
}
GOFLY.windowOpen=function (){
window.open(this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&lang='+this.GOFLY_LANG+'&refer='+window.document.title+'&extra='+this.GOFLY_EXTRA);
}
GOFLY.flashTitle=function () {
if(this.titleTimer!=0){
return;
}
this.titleTimer = setInterval("GOFLY.flashTitleFunc()", 500);
}
GOFLY.flashTitleFunc=function(){
this.titleNum++;
if (this.titleNum >=3) {
this.titleNum = 1;
}
if (this.titleNum == 1) {
document.title = '【】' + this.originTitle;
}
if (this.titleNum == 2) {
document.title = '【new message】' + this.originTitle;
}
}

@ -1,368 +0,0 @@
const KEFU={
KEFU_URL:"",
KEFU_KEFU_ID:"",
KEFU_ENT:"",
KEFU_LANG:"en",
KEFU_EXTRA: {},
KEFU_AUTO_OPEN:true,//是否自动打开
KEFU_SHOW_TYPES:1,//展示样式1普通右下角2圆形icon
KEFU_AUTO_SHOW:false,
KEFU_WITHOUT_BOX:false,
VISITOR_ID:"",
VISITOR_NAME:"",
VISITOR_AVATOR:"",
};
KEFU.launchButtonFlag=false;
KEFU.titleTimer=0;
KEFU.titleNum=0;
KEFU.noticeTimer=null;
KEFU.originTitle=document.title;
KEFU.chatPageTitle="KEFU";
KEFU.kefuName="";
KEFU.kefuAvator="";
KEFU.kefuIntroduce="";
KEFU.kefuDialogDelay="3000";
KEFU.offLine=false;
KEFU.TEXT={
"cn":{
"online_notice":"在线咨询",
"offline_notice":"离线留言",
},
"en":{
"online_notice":"chat with us",
"offline_notice":"we are offline",
},
"ru":{
"online_notice":"Разговор с нами",
"offline_notice":"Мы оффлайн",
},
};
KEFU.init=function(config){
var _this=this;
if (!config) { config = {}; }
for (var key in KEFU) {
if (typeof config[key] !== 'undefined') {
this[key] = config[key];
} else {
this[key] = KEFU[key];
}
}
if (typeof config.KEFU_URL!="undefined"){
this.KEFU_URL=config.KEFU_URL.replace(/([\w\W]+)\/$/,"$1");
}
this.dynamicLoadCss(this.KEFU_URL+"/static/css/kefu-front.css?v="+Date.now());
this.dynamicLoadCss(this.KEFU_URL+"/static/css/layui/css/layui.css?v="+Date.now());
var refer=document.referrer?document.referrer:"none";
this.KEFU_EXTRA.refer=refer;
this.KEFU_EXTRA.host=document.location.href;
this.KEFU_EXTRA=JSON.stringify(_this.KEFU_EXTRA);
this.dynamicLoadJs(this.KEFU_URL+"/static/js/functions.js?v=1",function(){
_this.dynamicLoadJs("https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js",function () {
jQuery.noConflict();
_this.dynamicLoadJs(_this.KEFU_URL+"/static/js/layer/layer.js",function () {
_this.jsCallBack();
});
});
//}
});
_this.addEventlisten();
}
KEFU.jsCallBack=function(){
var _this=this;
_this.showPcTips();
_this.addClickEvent();
}
//pc端的样式
KEFU.showPcTips=function(){
var _this=this;
//自动展开
if(_this.KEFU_AUTO_OPEN&&_this.isIE()<=0){
setTimeout(function () {
_this.showKefu();
},_this.kefuDialogDelay);
}
var html=`
<div class='launchButtonBox'>
<div id="launchButton" class="launchButton">
<div id="launchIcon" class="launchIcon">1</div>
<div class="launchButtonText">
<img src="`+_this.KEFU_URL+`/static/images/wechatLogo.png"/>
<span class='flyUsername'>在线咨询</span>
</div>
</div>
<div id="launchButtonNotice" class="launchButtonNotice"></div>
</div>
`
jQuery('body').append(html);
if(_this.KEFU_AUTO_OPEN){
return;
}
}
KEFU.addClickEvent=function(){
var _this=this;
var launchButton=jQuery("#launchButton");
if(launchButton){
launchButton.on("click",function() {
if(_this.launchButtonFlag){
return;
}
_this.KEFU_AUTO_SHOW=true;
_this.showKefu();
jQuery("#launchIcon").text(0).hide();
});
}
}
KEFU.postMessageToIframe=function(str){
var msg={}
msg.type='inputing_message';
msg.content=str;
this.postToIframe(msg);
}
KEFU.postToIframe=function(messageObj){
var obj=document.getElementById('layui-layer-iframe19911116');
if(!obj||!messageObj){
return;
}
document.getElementById('layui-layer-iframe19911116').contentWindow.postMessage(messageObj, "*");
}
KEFU.addEventlisten=function(){
var _this=this;
window.addEventListener('message',function(e){
var msg=e.data;
if(msg.type=="message"){
clearInterval(_this.noticeTimer);
var width=jQuery(window).width();
if(width>768){
_this.flashTitle();//标题闪烁
}
if (_this.launchButtonFlag){
return;
}
var welcomeHtml="<div id='launchNoticeClose' class='flyClose'>×</div>"
+"<div class='flexBox'><div class='flyUser'><img class='flyAvatar' src='"+_this.kefuAvator+"'/>"
+ "</div>"
+"<div class='launchNoticeContent' id='launchNoticeContent'>"
+replaceSpecialTag(msg.data.content,_this.KEFU_URL)+"</div></div>";
var obj=jQuery("#launchButtonNotice");
if(obj){
obj.html(welcomeHtml).fadeIn();
// setTimeout(function (obj) {
// obj.fadeOut();
// },3000,obj);
}
var news=jQuery("#launchIcon").text();
jQuery("#launchIcon").text(++news).show();
}
if(msg.type=="focus"){
clearTimeout(_this.titleTimer);
_this.titleTimer=0;
document.title = _this.originTitle;
}
if(msg.type=="force_close"){
kayer.close(kayer.index);
}
});
window.onfocus = function () {
clearTimeout(_this.titleTimer);
_this.titleTimer=0;
document.title = _this.originTitle;
_this.postToIframe({type:"focus"});
};
}
KEFU.dynamicLoadCss=function(url){
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.type='text/css';
link.rel = 'stylesheet';
link.href = url;
head.appendChild(link);
}
KEFU.dynamicLoadJs=function(url, callback){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.defer = true;
if(typeof(callback)=='function'){
script.onload = script.onreadystatechange = function () {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"){
callback();
script.onload = script.onreadystatechange = null;
}
};
}
head.appendChild(script);
}
KEFU.isIE=function(){
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7) {
return 7;
} else if(fIEVersion == 8) {
return 8;
} else if(fIEVersion == 9) {
return 9;
} else if(fIEVersion == 10) {
return 10;
} else {
return 6;//IE版本<=7
}
} else if(isEdge) {
return 'edge';//edge
} else if(isIE11) {
return 11; //IE11
}else{
return -1;//不是ie浏览器
}
}
KEFU.showPanel=function (){
var width=jQuery(window).width();
this.KEFU_AUTO_SHOW=true;
if(this.isIE()>0){
this.windowOpen();
return;
}
if(width<768){
this.layerOpen("100%","72%","rb");
return;
}
var width=380;
var height=580;
var x=document.documentElement.clientWidth-parseInt(width)-20;
var y=document.documentElement.clientHeight-parseInt(height)-20;
this.layerOpen(width+"px",height+"px",[y,x]);
this.launchButtonFlag=true;
}
KEFU.showKefu=function (){
if (this.launchButtonFlag) return;
var width=jQuery(window).width();
if(this.isIE()>0){
this.windowOpen();
return;
}
if(width<768){
this.layerOpen("100%","72%","rb");
return;
}
var width=380;
var height=580;
var x=document.documentElement.clientWidth-parseInt(width)-20;
var y=document.documentElement.clientHeight-parseInt(height)-20;
this.layerOpen(width+"px",height+"px",[y,x]);
this.launchButtonFlag=true;
jQuery(".launchButtonBox").hide();
}
KEFU.layerOpen=function (width,height,offset){
if (this.launchButtonFlag) return;
var layBox=jQuery("#layui-layer19911116");
if(layBox.css("display")=="none"){
this.launchButtonFlag=true;
layBox.show();
return;
}
var onlineStatus="<i class='kfBarStatus'></i>";
if(this.offLine){
onlineStatus="<i class='offline kfBarStatus'></i>";
}
var title=`
<div class="kfBar">
<div class="kfBarAvator">
<img src="`+this.KEFU_URL+`/static/images/4.jpg" class="kfBarLogo">
</div>
<div class="kfBarText">
<div class="kfName">在线客服系统</div>
</div>
</div>
`;
var _this=this;
if(!offset){
offset="rb";
}
var chatUrl=this.KEFU_URL+'/chatIndex?kefu_id='+this.KEFU_KEFU_ID+'&lang='+this.KEFU_LANG+'&extra='+this.KEFU_EXTRA;
if(this.VISITOR_ID!=""){
chatUrl+="&visitor_id="+this.VISITOR_ID;
}
if(this.VISITOR_NAME!=""){
chatUrl+="&visitor_name="+this.VISITOR_NAME;
}
if(this.VISITOR_AVATOR!=""){
chatUrl+="&avator="+this.VISITOR_AVATOR;
}
kayer.index="19911115";
kayer.open({
type: 2,
title: title,
skin:"kfLayer",
closeBtn: 1, //不显示关闭按钮
shade: 0,
area: [width, height],
offset: offset, //右下角弹出
anim: 2,
content: [chatUrl , 'yes'], //iframe的urlno代表不显示滚动条
move:false,
success:function(layero, index){
var layBox=jQuery("#layui-layer19911116");
_this.launchButtonFlag=true;
if(!_this.KEFU_WITHOUT_BOX&&_this.KEFU_AUTO_SHOW&&layBox.css("display")=="none"){
layBox.show();
}
jQuery("#layui-layer-iframe19911116 .chatEntTitle").hide();
},
end: function(){
_this.launchButtonFlag=false;
jQuery(".launchButtonBox").show();
},
cancel: function(index, layero){
jQuery("#layui-layer19911116").hide();
_this.launchButtonFlag=false;
jQuery(".launchButtonBox").show();
return false;
}
});
}
KEFU.windowOpen=function (){
window.open(this.KEFU_URL+'/chatIndex?kefu_id='+this.KEFU_KEFU_ID+'&lang='+this.KEFU_LANG+'&refer='+window.document.title+'&ent_id='+this.KEFU_ENT+'&extra='+this.KEFU_EXTRA);
}
KEFU.flashTitle=function () {
flashTitle();
}
/**
* 判断是否是手机访问
* @returns {boolean}
*/
KEFU.isMobile=function () {
if( /Mobile|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
return true;
}
return false;
}
Loading…
Cancel
Save