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

📄 jsutils.js

📁 这是我用QT和TTS写的一个电话本管理系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
/**********************************
*           命名空间               *
**********************************/
var CJB = undefined;
if(!CJB)
{
    CJB = {};
}
else if(typeof(CJB != object))
{
    throw new Error('类型错误');
}


/**********************************
*           公共JS类库             *
**********************************/
CJB.Utils = {};
//是否已经加载了某css文件
CJB.Utils.isLoadCss = function (file)
{
    var flag = false;
    for(i = 0; i < document.getElementsByTagName('link').length; i++)
    {
        if(document.getElementsByTagName('link').item(i).href ==  file)
        {
            flag = true;
            break;
        }
    }
    return flag;
}

//加载某CSS文件
//CJB.Utils.loadCss = function(file)
//{
//    CJB.Utils.LoadCss(file, 'loadCss');
//}
CJB.Utils.loadCss = function(file, linkId)
{
    var cssTag = document.getElementById(linkId);
    var head = document.getElementsByTagName('head').item(0);
    if(cssTag) head.removeChild(cssTag);
    css = document.createElement('link');
    css.href = file; //"../css/mi_"+file+".css";
    css.rel = 'stylesheet';
    css.type = 'text/css';
    css.id = linkId;
    head.appendChild(css);    
}

//加载某JS文件
//CJB.Utils.loadJs = function(file)
//{
//    CJB.Utils.LoadJs(file, 'loadScript');
//}
CJB.Utils.loadJs = function(file, srciptId)
{
    var scriptTag = document.getElementById(srciptId);
    var head = document.getElementsByTagName('head').item(0);
    if(scriptTag) head.removeChild(scriptTag);
    script = document.createElement('script');
    script.src = file;//"../js/mi_"+file+".js";
    script.type = 'text/javascript';
    script.id = srciptId;
    head.appendChild(script);
}

//字符串拼接
CJB.Utils.StringBuffer = function()
{
    this.__strings__ = new Array;
}
CJB.Utils.StringBuffer.prototype.append = function(str)
{
    this.__strings__.push(str);
}
CJB.Utils.StringBuffer.prototype.toString = function()
{
    return this.__strings__.join("");
}

//解决字符串为JSON对象
CJB.Utils.evalJsonString = function(jsonString)
{
    return eval('(' + jsonString + ')');
}

/**********************************
*           EventUtil             *
**********************************/
CJB.EventUtil = {};
CJB.EventUtil.addEventHandler = function(oTarget, sEventType, fnHandler)
{
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
}
CJB.EventUtil.removeEventHandler = function(oTarget, sEventType, fnHandler) 
{
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else { 
        oTarget["on" + sEventType] = null;
    }
};
CJB.EventUtil.formatEvent = function(oEvent) 
{
    var sUserAgent = navigator.userAgent;
    var isOpera = sUserAgent.indexOf("Opera") > -1;
    var isIE = sUserAgent.indexOf("compatible") > -1 
           && sUserAgent.indexOf("MSIE") > -1
           && !isOpera;
           
    var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");           

    if (isIE && isWin) {
        oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
        oEvent.eventPhase = 2;
        oEvent.isChar = (oEvent.charCode > 0);
        oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
        oEvent.pageY = oEvent.clientY + document.body.scrollTop;
        oEvent.preventDefault = function () {
            this.returnValue = false;
        };

        if (oEvent.type == "mouseout") {
            oEvent.relatedTarget = oEvent.toElement;
        } else if (oEvent.type == "mouseover") {
            oEvent.relatedTarget = oEvent.fromElement;
        }

        oEvent.stopPropagation = function () {
            this.cancelBubble = true;
        };

        oEvent.target = oEvent.srcElement;
        oEvent.time = (new Date).getTime();
    }
    return oEvent;
};
CJB.EventUtil.getEvent = function() 
{
    if (window.event) {
        return this.formatEvent(window.event);
    } else {
        return CJB.EventUtil.getEvent.caller.arguments[0];
    }
};


/**********************************
*           AsyncTooltip          *
**********************************/
CJB.AsyncTooltip = {};
CJB.AsyncTooltip.ApplictionPath = function()//布署必须按实现修改
{
    return "http://blog.csdn.net/";
    //return "/";
    //return "";
}
CJB.AsyncTooltip.asyncInvokePath = function()//布署必须按实现修改
{
    //针对会员中以的异步调用路径
    //return "/";
    //return "http://my2.csdn.net/";
    return "http://blog.csdn.net/";
}
CJB.AsyncTooltip.getCssPath = function(cssFile)
{
    return CJB.AsyncTooltip.ApplictionPath() + 'script/Tooltip/css/' + cssFile;
    //return "css/AsyncTooltip.css";//Debug状态,真实布署时必须修改
}
//根据_requestUrl的URL获取请求的JSON对像,以供动态加载内容显示
CJB.AsyncTooltip.requestContent = function(requestUrl, targetId)
{
    if(requestUrl != null)
    {
        var srciptId = targetId + '_Script';
        CJB.Utils.loadJs(requestUrl, srciptId);//动态加载内容JSON
    }
}
CJB.AsyncTooltip.init = function(options, text)
{
    //加载样式表(布署时需改变路径)
    if(!CJB.Utils.isLoadCss(CJB.AsyncTooltip.getCssPath('AsyncTooltip.css')))
    {
        CJB.Utils.loadCss(CJB.AsyncTooltip.getCssPath('AsyncTooltip.css'), 'AsyncTooltip_css');
    }
    
    var _popupId = options.PopupId != null ? options.PopupId : 'cjb_pid' + Math.round(Math.random()*100000000);//如果连弹出框Id也没有指定,则创建一个随机的
    var _text = text;
    var _direction = options.Direction != null ? options.Direction : 'right';
    var _targetId = options.TargetId;
    var _offsetY = options.OffsetY != null ? options.OffsetY : -20;
    var _offsetX = options.OffsetX != null ? options.OffsetX : (_direction == 'right') ? 0 : 0;//15;//针对个人中心的调整
    var _requestUrl = options.RequestUrl;
    var _formater = options.Formater;
    var _async = options.Async != null ? options.Async : false;
    var _contentCssClass = options.ContentCssClass != null ? options.ContentCssClass : 'cjb_AsyncTooltip_ContentCssClass';
    
    //异步加载的内容,放置到CJB.AsyncTooltip.showTooltip进行
    
    //动态创建弹出框
    if(document.getElementById(_popupId) == null)
    {
       var theDiv = document.createElement("div");
       theDiv.setAttribute("id", _popupId);
       theDiv.setAttribute("className", (_direction == "right") ? "tipRightPanel2" : "tipLeftPanel2");
       theDiv.setAttribute("class", (_direction == "right") ? "tipRightPanel2" : "tipLeftPanel2");
       theDiv.setAttribute("style", "display:none;");
       theDiv.style.cssText = "display:none;";
       theDiv.style.cssText = "display:none;z-index:9999;";
       
       //把创建的动态div加载为body下的第一个元素
       document.body.insertBefore(theDiv, document.body.childNodes[0]);
    }
    
    //创建圆角边框
    CJB.AsyncTooltip.createAngledRoundPanel(_direction, _popupId, _text, _contentCssClass);
    
    //添加隐藏事件
    CJB.EventUtil.addEventHandler(document, "mouseover", function()
        {
            CJB.AsyncTooltip.hideTooltip(_popupId);
        });
        
    //为popupId元素添加onmouseover事件,不需要客户端添加
    CJB.EventUtil.addEventHandler(document.getElementById(_popupId), "mouseover", function()
        {
            CJB.AsyncTooltip.mouseoverPanel(CJB.EventUtil.getEvent());
        });
        
    //为targetId元素添加onmouseover事件,不需要客房端添加
    CJB.EventUtil.addEventHandler(document.getElementById(_targetId), "mouseover", function()
        {
            var tar = document.getElementById(_targetId);
            CJB.AsyncTooltip.showTooltip(tar, CJB.EventUtil.getEvent(), _popupId, _direction, _offsetX, _offsetY, _async, _formater, _requestUrl);
            //CJB.AsyncTooltip.mouseoverPanel(CJB.EventUtil.getEvent());
        });          
        
}
//初始化论坛专家分
CJB.AsyncTooltip.initForumExpertInfo = function(options)
{
    options.Async = true;
    options.RequestUrl = CJB.AsyncTooltip.asyncInvokePath() + "JSForumExpertInfo.aspx?UserName=" + options.UserName;
    options.Formater = "CJB.AsyncTooltip.formatForumExpertInfo('" + options.UserName +"')";
    options.ContentCssClass = "cjb_AsyncTooltip_ForumExpertInfo";
    
    CJB.AsyncTooltip.init(options, null);
}
CJB.AsyncTooltip.formatForumExpertInfo = function(userName)
{
    var jsonObj = null;
    try{ jsonObj = eval('forumExpertInfo_'+userName); }catch(exception){ return null; }

    var sb = new CJB.Utils.StringBuffer();
    sb.append(jsonObj.Content);

    return sb.toString();
}
//初始化博客访问量
CJB.AsyncTooltip.initBlogCommentInfo = function(options)
{
    options.Async = true;
    options.RequestUrl = CJB.AsyncTooltip.asyncInvokePath() + "JSBlogCommentInfo.aspx?UserName=" + options.UserName;
    options.Formater = "CJB.AsyncTooltip.formatBlogCommentInfo('" + options.UserName +"')";
    options.ContentCssClass = "cjb_AsyncTooltip_BlogCommentInfo";
    
    CJB.AsyncTooltip.init(options, null);
}
CJB.AsyncTooltip.formatBlogCommentInfo = function(userName)
{
    var jsonObj = null;
    try{ jsonObj = eval('blogCommentInfo_'+userName); }catch(exception){ return null; }
    
    var sb = new CJB.Utils.StringBuffer();
    sb.append(jsonObj.Content);
    
    return sb.toString();
}
//初始化个人信息
CJB.AsyncTooltip.initProfileInfo = function(options)
{
    options.Async = true;
    options.RequestUrl = CJB.AsyncTooltip.asyncInvokePath() + "JSProfileInfo.aspx?UserName=" + options.UserName;
    options.Formater = "CJB.AsyncTooltip.formatProfileInfo('" + options.UserName +"')";
    options.ContentCssClass = "cjb_AsyncTooltip_ProfileInfo";
    
    CJB.AsyncTooltip.init(options, null);
}
CJB.AsyncTooltip.formatProfileInfo = function(userName)
{
    var jsonObj = null;
    try{ jsonObj = eval('profileInfo_'+userName); }catch(exception){ return null; }
    
    var sb = new CJB.Utils.StringBuffer();
    sb.append(jsonObj.Content);

⌨️ 快捷键说明

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