;!function(win, doc) { "use strict"; var config = { domain: "http://a.b885.com", uid: '', name: '', avatar: '', f: '', y: '', x: '', userType: 0, } , scm_d1 , scm_chat_div , scm_d2 , ck_style = "" , chat_style = "position:fixed;z-index:9999;right:20px;bottom:10px;padding:0;margin:0;overflow:hidden;background-color:transparent;" , scmkfChat = function () {} , getCustomer = function () { return { uid: config.uid, name: config.name, avatar: config.avatar, xx: config.x, userType: config.userType, url: window.location.href, ua1: window.screen.width + '×' + window.screen.height + '【' + window.screen.colorDepth + '】', ua2: navigator.userAgent, ua3: "0", ua4: document.referrer, }; } , showChat = function () { doc.getElementById("kf-kf").onclick = function () { scm_d1.setAttribute("style", ck_style + "display:none"); scm_chat_div.setAttribute("style", chat_style + "display:block"); doc.getElementById("scm_Iframe").contentWindow.postMessage(JSON.stringify({cmd: 'scm_chat'}), 'http://a.b885.com'); }; } , createBox = function () { scm_d1 = document.createElement("div"); scm_d1.setAttribute("style", ck_style); scm_d1.setAttribute("id", "kf-kf"); doc.body.appendChild(scm_d1); scm_chat_div = document.createElement("div"); scm_chat_div.setAttribute("style", chat_style + "display:none"); scm_chat_div.setAttribute("id", "scm_kfv2"); doc.body.appendChild(scm_chat_div); scm_d2 = document.createElement("div"); scm_d2.setAttribute("style", "width: 280px;height: 40px;z-index:99999;position:absolute;cursor: move;"); scm_d2.setAttribute("id", "scm_kftitle"); scm_chat_div.appendChild(scm_d2); var ws_iframe = document.createElement("iframe"); ws_iframe.scrolling = "no"; ws_iframe.setAttribute("frameborder", "0", 0); ws_iframe.setAttribute("id", "scm_Iframe"); ws_iframe.setAttribute("width", "400px"); ws_iframe.setAttribute("height", "500px"); ws_iframe.setAttribute("allow", "camera;microphone"); ws_iframe.src = config.domain + "/k/62fce21189610?type=1&y="+ config.y+"&f="+ config.f; scm_chat_div.appendChild(ws_iframe); showChat(); } , hideChatDiv = function () { scm_d1.setAttribute("style", ck_style + "display:block"); scm_chat_div.setAttribute("style", chat_style + "display:none"); }; win.addEventListener('message', function(event){ var scm_kfv2=document.querySelector('#scm_kfv2'); var scm_kftitle=document.querySelector('#scm_kftitle'); scm_kftitle.addEventListener('mousedown',function(e){ var x=e.pageX-scm_kfv2.offsetLeft; var y=e.pageY-scm_kfv2.offsetTop; document.addEventListener('mousemove',kk) function kk(e){ scm_kfv2.style.left=e.pageX-x+'px' scm_kfv2.style.top=e.pageY-y+'px' } document.addEventListener('mouseup',function(e){ document.removeEventListener('mousemove',kk) }) }) if('xxx_kf' == event.data) { hideChatDiv(); } else if('zzz_kf' == event.data) { doc.getElementById("kf-kf").click(); } }, false); win.onload = function() { doc.getElementById("scm_Iframe").contentWindow.postMessage(JSON.stringify({cmd: 'scm_hhzz', data: getCustomer()}), '*'); }; scmkfChat.prototype.init = function (conf) { for(var key in conf){ if(config.hasOwnProperty(key) === true){ config.userType = 1; config[key] = conf[key]; } } createBox(); }; win.kf = new scmkfChat(); }(window, document);