⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webimpopup.js

📁 马士兵老师的代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
			if(isNaN(tl))
			{this.dragXoffset=e.clientX;}
			else{this.dragXoffset=e.clientX-tl;}
			if(isNaN(tt)){this.dragYoffset=e.clientY;}
			else{this.dragYoffset=e.clientY-tt;}

			document.onmousemove=function(e)
			{
				if(e==null){e=window.event}
				if(e.button<=1&&this.dragOK)
				{
				    var ddLeft=e.clientX-this.dragXoffset;
				    var ddTop=e.clientY-this.dragYoffset;
				    //计算位置
				    var body=webImForm.bodyProperty();
		            var maxTop=(body.scrollTop+body.clientHeight-this.dragDiv.offsetHeight-1);
		            var maxLeft=(body.scrollLeft+body.clientWidth-this.dragDiv.offsetWidth-1);

		            if(ddLeft>maxLeft){this.dragDiv.style.left=maxLeft+'px';}
		            else if(ddLeft<1){this.dragDiv.style.left='1px';}
		            else {this.dragDiv.style.left=ddLeft+'px';}
		            
		            if(ddTop>maxTop){this.dragDiv.style.top=maxTop+'px';}
		            else if(ddTop<1){this.dragDiv.style.top='1px';}
		            else {this.dragDiv.style.top=ddTop+'px';}
		            
		            return false;
				}
			};
			
			document.onmouseup=function(e)
			{
	            if (e == null) { e = window.event;} 
				document.onmousemove=null;
				document.onmouseup=null;
				this.dragOK=false;
                realDiv.style.left=this.dragDiv.style.left;
                realDiv.style.top=this.dragDiv.style.top;
				dd.style.display='none';
			};
			
			return false;
        }
    }
}
webImForm.setDivTop=function(div)
{
    webImForm.zIndex[0]=div.style.zIndex;
    var zi=parseInt(webImForm.zIndex[5]);
    if(zi<65000)
    {
        zi++;webImForm.zIndex[5]=zi.toString();
    }
    else
    {
        webImForm.zIndex[0]="30000";zi=30000;
    }
    div.style.zIndex=zi;
}
webImForm.zIndex=new Array(10000,60001,60002,60003,60004,61000);
webImForm.hasChatWindow=false;
webImForm.rootUrl=csdn_im_defaultDomain+'/Web_References/Provide_Services/CSDN/Popup/';



/********************************************************/
//webimPopup类,共有属性,方法
//var webimPopup=new Object();
var webimPopup=function(){}

webimPopup.divPrefix='im_popupWindow_';
webimPopup.scriptId="webIM_popup_js";
webimPopup.rootUrl=csdn_im_defaultDomain+'/Web_References/Provide_Services/CSDN/Popup/';
webimPopup.requestUrl=webimPopup.rootUrl+'PopupMessages.aspx';
webimPopup.sysMsgDivId=webimPopup.divPrefix + 'sysMsg';
webimPopup.senderDivId=webimPopup.divPrefix + 'sender';
webimPopup.csdnMsgDivId=webimPopup.divPrefix + 'csdnMsg';
webimPopup.chatDivId=webimPopup.divPrefix + 'chat';
webimPopup.hiMsgDivId=webimPopup.divPrefix+'hiMsg';
webimPopup.hiMsgScriptUrl='http://notify1.hi.csdn.net/NotifySummary.ashx?UserName=';

webimPopup.dispose=function(eleID)
{
	var eleObj=document.getElementById(eleID);
	if(eleObj&&eleObj.parentNode)
	{
		eleObj.parentNode.removeChild(eleObj);
	}
}
webimPopup.render=function(jsonMsg)///该方法被加载的script自动调用
{
    if(jsonMsg)
	{
		webimPopup.renderWindow(jsonMsg);
//	    //加载hi的新鲜事
//	    if(!webim$username){return;}
//	    this.loadScript(this.hiMsgScriptUrl+webim$username, this.renderHiMsg);
	    
		webImForm.resizeHandler();
	    document.onmousedown=webImForm.dragHandler;
	    window["onresize"]=webImForm.resizeHandler;
	    window["onscroll"]=webImForm.resizeHandler;
    		
		var pv=document.createElement('img');
		pv.src='http://counter.csdn.net/pv.aspx?id=227';
		pv.alt='';
		pv.style.display='none';
		document.body.appendChild(pv);
	}
}
webimPopup.renderWindow=function(json)
{
    var f;
    if(json.sysMsg&&json.sysMsg.Content&&json.sysMsg.Content.length>0)//全站消息
    {
        f=new webImForm();
        f.title='系统消息';
        f.content=json.sysMsg.Content;
        f.divId=this.sysMsgDivId;
        f.width='500px';
        f.height='240px';
        f.position=false;
        f.zIndex=webImForm.zIndex[3];
        f.maxHeight='240';
        f.show();
    }
    if(json.csdnMsg)//csdn帐号的消息
    {
        f=new webImForm();
        f.title='csdn的未读消息';
        f.content=webimPopup.getCsdnMsg(json.csdnMsg);
        f.divId=this.csdnMsgDivId;
        f.width='180px';
        f.position=true;
        f.zIndex=webImForm.zIndex[2];
        f.maxHeight='126';
        f.show();
    }
    if(json.sender)//用户消息
    {
        f=new webImForm();
        f.title='未读消息';
        f.content=webimPopup.getSender(json.sender);
        f.divId=this.senderDivId;
        f.width='180px';
        f.position=true;
        f.zIndex=webImForm.zIndex[1];
        f.maxHeight='126';
        f.show();
    }
}
webimPopup.renderHiMsg=function()
{
    if('undefined'==typeof notifySummary){return;}
    if(notifySummary)
    {
        f=new webImForm();
        f.title='我的新鲜事';
        f.content=notifySummary.replace(/&amp;/g,'&').replace(/&quot;/g,'\"').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
        f.divId=webimPopup.hiMsgDivId;
        f.width='270px';
        f.position=true;
        f.zIndex=webImForm.zIndex[1];
        f.maxHeight='126';
        f.show();
        webImForm.setToRightCorner(document.getElementById(webimPopup.hiMsgDivId));
    }
}
//入口函数->
webimPopup.request=function()
{
    if(!this.checkUrl()) return;
	this.loadScript(this.requestUrl,null);
}
webimPopup.loadScript=function(scriptUrl,callback)
{
    var scp=document.createElement("script");
	scp.type="text/javascript";
	scp.id=this.scriptId+new Date().getMilliseconds();
	scp.src=scriptUrl;
	document.getElementsByTagName("head")[0].appendChild(scp);
	
	if(scp.readyState)
	{
		scp.onreadystatechange=function()
		{
			if(scp.readyState=="loaded")
			{
			    if(callback && 'function'==typeof callback)callback();
				webimPopup.dispose(scp.id);
			}
		}
	}	
	else
	{
		scp.onload=function()
		{
			if(callback && 'function'==typeof callback)callback();
            webimPopup.dispose(scp.id);
		}
	}
}
webimPopup.getCsdnMsg=function(arr)
{
    if(arr && arr.length && arr.length>0)
    {
        var l=[];
        for(var i=0;i<arr.length;i++)
	    {
		    l.push('.&nbsp;'+ arr[i] +'<br/>');
	    }
	    return l.join('');
    }
}
webimPopup.getSender=function(arr)
{
    if(arr && arr.length && arr.length>0)
    {
        var l=[];
        for(var i=0;i<arr.length;i++)
	    {
	        l.push('<a href="http://hi.csdn.net/'+escape(arr[i])+'" target="_blank"><img class="userAvatar" src="http://profile.csdn.net/'+ escape(arr[i]) +'/picture/4.jpg" alt=""/></a>');
	        //fanwx 081030 修改
		    //l.push('&nbsp;<a href="#" onclick="webimPopup.showChat(\''+ arr[i] +'\');return false;">'+ arr[i] +'</a><br/>');
            l.push('&nbsp;<a href="'+csdn_im_defaultDomain+'/messages/'+escape(arr[i])+'.ashx" target="_blank">'+ arr[i] +'</a><br/>');
	    }
	    return l.join('');
    }
}
webimPopup.showChat=function(name)
{
//    if(webImForm.hasChatWindow)
//    {
//        if(confirm("该操作将关闭当前聊天窗口,打开新窗口,您确定吗?"))
//        {
//            webImForm.close(this.chatDivId);
//            webImForm.renderChat(name);
//	        webImForm.hasChatWindow=true;
//	    }
//    }
//    else
//    {
//	    webImForm.renderChat(name);
//	    webImForm.hasChatWindow=true;
//	}
}
webimPopup.checkUrl=function()
{
    var currentUrl=window.location.href;
    if(currentUrl.indexOf('http://')!=0)
    {
        currentUrl+='http://';
    }
    for(var i=0;i<this.nullityUrlArray.length;i++)
    {
        if(currentUrl.indexOf(this.nullityUrlArray[i])==0) return false;
    }
    return true;
}
webimPopup.nullityUrlArray=new Array("http://passport.csdn.net/", "http://webim.csdn.net/MessageList/IFrame/", "http://webim-local.csdn.net/MessageList/IFrame/");

//run
webimPopup.request();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -