From 77ce6ef3a676c583f366ba077987fe32e6743c96 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Mon, 11 Jan 2021 16:24:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AFjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/html/chat_page.html | 2 +- static/html/index.html | 10 +- static/js/chat-page.js | 2 - static/js/gofly-front.js | 210 ++++++++++++++++++------------------- 4 files changed, 110 insertions(+), 114 deletions(-) diff --git a/static/html/chat_page.html b/static/html/chat_page.html index 060571c..0af88a7 100644 --- a/static/html/chat_page.html +++ b/static/html/chat_page.html @@ -79,5 +79,5 @@ var KEFU_ID='{{.KEFU_ID}}'; var REFER='{{.Refer}}'; - + diff --git a/static/html/index.html b/static/html/index.html index 7a7701c..293598e 100644 --- a/static/html/index.html +++ b/static/html/index.html @@ -19,12 +19,14 @@ + - diff --git a/static/js/chat-page.js b/static/js/chat-page.js index 1b21759..3bb9f99 100644 --- a/static/js/chat-page.js +++ b/static/js/chat-page.js @@ -433,7 +433,6 @@ new Vue({ alertSound:function(){ var b = document.getElementById("chatMessageAudio"); if (b.canPlayType('audio/ogg; codecs="vorbis"')) { - alert(1); b.type= 'audio/mpeg'; b.src= '/static/images/alert2.ogg'; var p = b.play(); @@ -445,7 +444,6 @@ new Vue({ sendSound:function(){ var b = document.getElementById("chatMessageSendAudio"); if (b.canPlayType('audio/ogg; codecs="vorbis"')) { - alert(2); b.type= 'audio/mpeg'; b.src= '/static/images/sent.ogg'; var p = b.play(); diff --git a/static/js/gofly-front.js b/static/js/gofly-front.js index 3a397f3..8312b7c 100644 --- a/static/js/gofly-front.js +++ b/static/js/gofly-front.js @@ -1,60 +1,82 @@ -var launchButtonFlag=false; -var titleTimer,titleNum=0; -var originTitle = document.title; -if (typeof GOFLY_URL=="undefined"){ - var GOFLY_URL="https://gofly.sopans.com"; -} -if (typeof GOFLY_KEFU_ID=="undefined"){ - var GOFLY_KEFU_ID=""; -} -if (typeof GOFLY_BTN_TEXT=="undefined"){ - var GOFLY_BTN_TEXT="Chat with me"; -} -dynamicLoadCss(GOFLY_URL+"/static/css/gofly-front.css"); -if (typeof $!="function"){ - dynamicLoadJs("https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js",function () { - dynamicLoadJs("https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js",function () { - clickBtn(); +var GOFLY={ + GOFLY_URL:"https://gofly.sopans.com", + GOFLY_KEFU_ID:"", + GOFLY_BTN_TEXT:"Chat with me", +}; +GOFLY.launchButtonFlag=false; +GOFLY.titleTimer=0; +GOFLY.titleNum=0; +GOFLY.originTitle=document.title; +GOFLY.init=function(config){ + if(typeof config=="undefined"){ + return; + } + if (typeof config.GOFLY_URL!="undefined"){ + this.GOFLY_URL=config.GOFLY_URL; + } + 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; + } + this.dynamicLoadCss(this.GOFLY_URL+"/static/css/gofly-front.css"); + if (typeof $!="function"){ + var _this=this; + this.dynamicLoadJs("https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js",function () { + _this.dynamicLoadJs("https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js",function () { + _this.clickBtn(); + }); }); + }else{ + this.dynamicLoadJs("https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js",function () { + _this.clickBtn(); + }); + } + + window.addEventListener('message',function(e){ + var msg=e.data; + if(msg.type=="message"){ + _this.flashTitle();//标题闪烁 + } }); -}else{ - dynamicLoadJs("https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.min.js",function () { - clickBtn(); - }); + window.onfocus = function () { + clearTimeout(this.titleTimer); + 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); } -function clickBtn(){ - $('body').append('
'+GOFLY_BTN_TEXT+'
'); +GOFLY.clickBtn=function (){ + var _this=this; + $('body').append('
'+_this.GOFLY_BTN_TEXT+'
'); $("#launchButton").on("click",function() { - if (launchButtonFlag) return; - var width=$(window).width(); - if(width<768 || isIE()>0){ - window.open(GOFLY_URL+'/chatIndex?kefu_id='+GOFLY_KEFU_ID+'&refer='+window.document.title); - return; - } - layer.open({ - type: 2, - title: GOFLY_BTN_TEXT, - closeBtn: 1, //不显示关闭按钮 - shade: 0, - area: ['520px', '530px'], - offset: 'rb', //右下角弹出 - anim: 2, - content: [GOFLY_URL+'/chatIndex?kefu_id='+GOFLY_KEFU_ID+'&refer='+window.document.title, 'yes'], //iframe的url,no代表不显示滚动条 - end: function(){ - launchButtonFlag=false; - $(".launchButton").show(); - } - }); - launchButtonFlag=true; - $(".launchButton").hide(); - }); - $("body").click(function () { - clearTimeout(titleTimer); - document.title = originTitle; + _this.showKefu(); }); } -function isIE() { +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浏览器 @@ -82,80 +104,54 @@ function isIE() { return -1;//不是ie浏览器 } } -function showKefu(){ - if (launchButtonFlag) return; +GOFLY.showKefu=function (){ + if (this.launchButtonFlag) return; var width=$(window).width(); - if(width<768 || isIE()>0){ - window.open(GOFLY_URL+'/chatIndex?kefu_id='+GOFLY_KEFU_ID+'&refer='+window.document.title); + if(width<768 || this.isIE()>0){ + this.windowOpen(); return; } + this.layerOpen(); + this.launchButtonFlag=true; + $(".launchButton").hide(); + + $("body").click(function () { + clearTimeout(this.titleTimer); + document.title = this.originTitle; + }); +} +GOFLY.layerOpen=function (){ + if (this.launchButtonFlag) return; layer.open({ type: 2, - title: GOFLY_BTN_TEXT, + title: this.GOFLY_BTN_TEXT, closeBtn: 1, //不显示关闭按钮 - shade: [0], + shade: 0, area: ['520px', '530px'], offset: 'rb', //右下角弹出 anim: 2, - content: [GOFLY_URL+'/chatIndex?kefu_id='+GOFLY_KEFU_ID+'&refer='+window.document.title, 'yes'], //iframe的url,no代表不显示滚动条 + content: [this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&refer='+window.document.title, 'yes'], //iframe的url,no代表不显示滚动条 end: function(){ - launchButtonFlag=false; + this.launchButtonFlag=false; $(".launchButton").show(); } }); - launchButtonFlag=true; - $(".launchButton").hide(); - - $("body").click(function () { - clearTimeout(titleTimer); - document.title = originTitle; - }); } -function dynamicLoadCss(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.windowOpen=function (){ + window.open(this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&refer='+window.document.title); } -function dynamicLoadJs(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; - } - }; +GOFLY.flashTitle=function () { + this.titleNum++; + if (this.titleNum >=3) { + this.titleNum = 1; } - head.appendChild(script); -} - -function flashTitle() { - titleNum++; - if (titleNum >=3) { - titleNum = 1; + if (this.titleNum == 1) { + document.title = '【】' + this.originTitle; } - if (titleNum == 1) { - document.title = '【】' + originTitle; + if (this.titleNum == 2) { + document.title = '【你有一条消息】' + this.originTitle; } - if (titleNum == 2) { - document.title = '【你有一条消息】' + originTitle; - } - titleTimer = setTimeout("flashTitle()", 500); + this.titleTimer = setTimeout("this.flashTitle()", 500); } -window.addEventListener('message',function(e){ - var msg=e.data; - if(msg.type=="message"){ - flashTitle();//标题闪烁 - } -}); -window.onfocus = function () { - clearTimeout(titleTimer); - document.title = originTitle; -}; +