Z-Blog中用到的js代码


Posted in Javascript onMarch 15, 2007

///////////////////////////////////////////////////////////////////////////////
//              Z-Blog
// 作    者:    朱煊(zx.asd)
// 版权所有:    RainbowSoft Studio
// 技术支持:    rainbowsoft@163.com
// 程序名称:    
// 程序版本:    
// 单元名称:    common.js
// 开始时间:    2004.07.25
// 最后修改:    
// 备    注:    全局脚本
///////////////////////////////////////////////////////////////////////////////

//*********************************************************
// 目的:    加载样式表
// 输入:    无
// 返回:    无
//*********************************************************
function LoadActiveStyleSheet(){

    var title=GetCookie("sk")
    var a;

    if (title) {

        a = document.getElementsByTagName("link")[0];

        a.href=str00+"style/"+title+".css"

    }

}
//*********************************************************

//*********************************************************
// 目的:    设置样式表
// 输入:    title
// 返回:    无
//*********************************************************
function SetActiveStyleSheet(title){

    var a;

    if (title) {

        {
            SetCookie("sk",title,365);
        }
        a = document.getElementsByTagName("link")[0];

        a.href=str00+"style/"+title+".css"

    }

}
//*********************************************************

//*********************************************************
// 目的:    设置Cookie
// 输入:    sName, sValue,iExpireDays
// 返回:    无
//*********************************************************
function SetCookie(sName, sValue,iExpireDays) {
    if (iExpireDays){
        var dExpire = new Date();
        dExpire.setTime(dExpire.getTime()+parseInt(iExpireDays*24*60*60*1000));
        document.cookie = sName + "=" + escape(sValue) + "; expires=" + dExpire.toGMTString();
    }
    else{
        document.cookie = sName + "=" + escape(sValue);
    }
}
//*********************************************************

//*********************************************************
// 目的:    返回Cookie
// 输入:    Name
// 返回:    Cookie值
//*********************************************************
function GetCookie(sName) {

    var arr = document.cookie.match(new RegExp("(^| )"+sName+"=([^;]*)(;|$)"));
    if(arr !=null){return unescape(arr[2])};
    return null;

}
//*********************************************************

//*********************************************************
// 目的:    验证信息
// 输入:    无
// 返回:    无
//*********************************************************
var strFormAction;
var objImageValid;
function VerifyMessage() {

    var strName=document.getElementById("inpName").value;
    var strEmail=document.getElementById("inpEmail").value;
    var strHomePage=document.getElementById("inpHomePage").value;
    var strArticle;

    if(document.getElementById("txaArticle").value){
        strArticle=document.getElementById("txaArticle").value;
    }
    else{
        strArticle=document.getElementById("txaArticle").innerText;
    }

    if(strName==""){
        alert(str01);
        return false;
    }
    else{
        re = new RegExp("^[.A-Za-z0-9\u4e00-\u9fa5]+$");
        if (!re.test(strName)){
            alert(str02);
            return false;
        }
    }

    if(strEmail==""){
        //alert(str01);
        //return false;
    }
    else{
        re = new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
        if (!re.test(strEmail)){
            alert(str02);
            return false;
        }
    }

    if(typeof(strArticle)=="undefined"){
        alert(str03);
        return false;
    }

    if(typeof(strArticle)=="string"){
        if(strArticle==""){
            alert(str03);
            return false;
        }
        if(strArticle.length>intMaxLen)
        {
            alert(str03);
            return false;
        }
    }

    document.getElementById("inpArticle").value=strArticle;
    document.getElementById("inpLocation").value=parent.window.location.href;
    if(document.getElementById("frmSumbit").action.search("act=cmt")>0){
        strFormAction=document.getElementById("frmSumbit").action;
    }

    var bolRemember=document.getElementById("chkRemember").checked;

    if(bolRemember==true){
        SaveRememberInfo();
    }
    else{
        SetCookie("chkRemember",bolRemember,365);
    }

    //ajax comment begin
    $.post(document.getElementById("frmSumbit").action,
        {
        "inpAjax":true,
        "inpID":$("#inpId").val(),
        "inpVerify":(document.getElementById("inpVerify")?$("#inpVerify").val():""),
        "inpEmail":strEmail,
        "inpName":strName,
        "inpArticle":strArticle,
        "inpHomePage":strHomePage
        },
        function(data){
            var s =data;
            if((s.search("faultCode")>0)&&(s.search("faultString")>0))
            {
                alert(s.match("<string>.+?</string>")[0].replace("<string>","").replace("</string>",""))
            }
            else{
                var i=Math.round(Math.random()*1000)
                var s ="<div id=\"divAjaxComment"+i+"\">"+data+"</div>";
                $(s).insertBefore("#divAjaxComment");
                $("#divAjaxComment"+i).fadeIn("slow");
                //$("#divAjaxComment"+i).fadeTo("normal", 0);
                //$("#divAjaxComment"+i).fadeTo("normal", 1);
                //$("#divAjaxComment"+i).show("slow");
                if(strFormAction){
                    document.getElementById("frmSumbit").action=strFormAction;
                }
                $("#txaArticle").val("");
            }
            if(document.getElementById("inpVerify")){
                $("#inpVerify").val("");
                if(!objImageValid){
                    objImageValid=$("img[@src='"+str00+"function/c_validcode.asp?name=commentvalid']");
                }
                objImageValid.src(str00+"function/c_validcode.asp?name=commentvalid"+"&random="+Math.random());
            }
        }
    );

    return false;
    //ajax comment end

}
//*********************************************************

//*********************************************************
// 目的:    加载信息
// 输入:    无
// 返回:    无
//*********************************************************
function LoadRememberInfo() {

    var strName=GetCookie("inpName")
    var strEmail=GetCookie("inpEmail")
    var strHomePage=GetCookie("inpHomePage")
    var bolRemember=GetCookie("chkRemember")

    if(bolRemember=="true"){

        if(strName){document.getElementById("inpName").value=strName;};
        if(strEmail){document.getElementById("inpEmail").value=strEmail;};
        if(strHomePage){document.getElementById("inpHomePage").value=strHomePage;};
        if(bolRemember){document.getElementById("chkRemember").checked=bolRemember;};

    }

    if(GetCookie("username")){
        document.getElementById("inpName").value=unescape(GetCookie("username"))
    }

}
//*********************************************************

//*********************************************************
// 目的:    保存信息
// 输入:    无
// 返回:    无
//*********************************************************
function SaveRememberInfo() {

    var strName=document.getElementById("inpName").value;
    var strEmail=document.getElementById("inpEmail").value;
    var strHomePage=document.getElementById("inpHomePage").value;
    var bolRemember=document.getElementById("chkRemember").checked;

    SetCookie("inpName",strName,365);
    SetCookie("inpEmail",strEmail,365);
    SetCookie("inpHomePage",strHomePage,365);
    SetCookie("chkRemember",bolRemember,365);

}
//*********************************************************

//*********************************************************
// 目的:    输出UBB
// 输入:    无
// 返回:    无
//*********************************************************
function ExportUbbFrame() {

    if(!objActive){objActive="txaArticle"};

    document.write("<p id=\"UbbFrame\" style=\"display:none;\"></p>")

    document.write("<p>")

    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[URL]','[/URL]'),true);\" style=\"padding:2px;cursor:pointer;\">[URL]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[URL=http://]','[/URL]'),true);\" style=\"padding:2px;cursor:pointer;\">[URL2]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[EMAIL]','[/EMAIL]'),true);\" style=\"padding:2px;cursor:pointer;\">[EMAIL]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[EMAIL=@]','[/EMAIL]'),true);\" style=\"padding:2px;cursor:pointer;\">[EMAIL2]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[B]','[/B]'),true);\" style=\"padding:2px;cursor:pointer;\">[B]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[I]','[/I]'),true);\" style=\"padding:2px;cursor:pointer;\">[I]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[U]','[/U]'),true);\" style=\"padding:2px;cursor:pointer;\">[U]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[S]','[/S]'),true);\" style=\"padding:2px;cursor:pointer;\">[S]</a>  ")
    document.write("<a alt=\"\" onmousedown=\"InsertText(objActive,ReplaceText(objActive,'[QUOTE]','[/QUOTE]'),true);\" style=\"padding:2px;cursor:pointer;\">[QUOTE]</a>  ")

    document.write("<u><a style=\"cursor:pointer;text-align:right;\" onclick=\"InsertUbbFace();if(document.getElementById('UbbFrame').style.display=='none'){document.getElementById('UbbFrame').style.display='block';}else{document.getElementById('UbbFrame').style.display='none'};this.style.display='none'\">"+str06+"</a></u> ")

    document.write("</p>")
}
//*********************************************************

//*********************************************************
// 目的:    插入表情图片HTML代码
// 输入:    无
// 返回:    无
//*********************************************************
function InsertUbbFace() {

    if(!document.getElementById("UbbFrame").innerHTML && strFaceName){

        var aryFileName="";
        var strFileName="";
        var strFaceHtml="";

        aryFileName = strFaceName.split("|");

        for (var i=0;i<aryFileName.length;i++)
        {
            strFileName = aryFileName[i];
            strFaceHtml=strFaceHtml + "<img src=\""+str00+"image/face/"+strFileName+".gif\" title=\""+strFileName+"\" alt=\""+strFileName+"\" width=\""+strFaceSize+"\" height=\""+strFaceSize+"\" onclick=\"InsertText(objActive,'[F]'+this.alt+'[/F]',false);\" style=\"padding:2px;cursor:pointer;\">"
        }
        document.getElementById("UbbFrame").innerHTML=strFaceHtml;
    }

}
//*********************************************************

//*********************************************************
// 目的:    自动插入并替换
// 输入:    无
// 返回:    无
//*********************************************************
var objActive;
function GetActiveText(objHTML) {
    objActive=objHTML;
    if(document.selection){
        var obj=document.getElementById(objHTML);
        obj.currPos = document.selection.createRange().duplicate()
    }
}

function InsertText(objHTML,strText,bolReplace) {
    if(strText==""){return("")}
    var obj=document.getElementById(objHTML);
    if(document.selection){
        if (obj.currPos){
            if(bolReplace && (obj.value=="")){
                obj.currPos.text=strText
            }
            else{
                obj.currPos.text+=strText
            }
        }
        else{
            obj.value+=strText
        }
    }
    else{
        if(bolReplace){
            obj.value=obj.value.slice(0,obj.selectionStart) + strText + obj.value.slice(obj.selectionEnd,obj.value.length)
        }
        else{
            obj.value=obj.value.slice(0,obj.selectionStart) + strText + obj.value.slice(obj.selectionStart,obj.value.length)
        }
    }
    //obj.focus();
}

function ReplaceText(objHTML,strPrevious,strNext) {
    var obj=document.getElementById(objHTML);
    var strText;
    if(document.selection && document.selection.type == "Text"){
        if (obj.currPos){
            var range = document.selection.createRange();
            range.text = strPrevious + range.text + strNext;
            return("");
        }
        else{
            strText=strPrevious + strNext;
            return(strText);
        }
    }
    else{
        if(obj.selectionStart || obj.selectionEnd){
            strText=strPrevious + obj.value.slice(obj.selectionStart,obj.selectionEnd) + strNext;
            return(strText);
        }
        else{
            strText=strPrevious + strNext;
            return(strText);
        }
    }
}
//*********************************************************

//*********************************************************
// 目的:    ShowMedia By UBB
// 输入:    无
// 返回:    无
//*********************************************************
function ShowMedia(objHTML,strURL,strType,intWidth,intHeight) {
    var strMedia="";
    var blnShow = false;
    var objMedia=objHTML;

    if(objMedia.innerHTML){blnShow = true};

    var re = new RegExp("\.[a-z0-9]+$","ig");

    var strExtend = re.exec(strURL);
    strExtend="|"+String(strExtend).toLowerCase()+"|";

    if(strType=="AUTO"){
        if(String("|.swf|").indexOf(strExtend)>=0){strType="SWF"}
        if(String("|.mov|.qt|").indexOf(strExtend)>=0){strType="QT"}
        if(String("|.wmv|.wmp|.wm|.avi|.mp4|.mpg|.mpeg|.m3u|.pls|.wvx|.wax|.wmx|").indexOf(strExtend)>=0){strType="WMV"}
        if(String("|.asf|.wma|.asx|.wav|.mp3|.mpa|.mp2|.m1a|.m2a|.aac|").indexOf(strExtend)>=0){strType="WMA"}
        if(String("|.rm|.ram|.rmvb|.rpm|.amr|.3gp|.3gpp|.3g2|.3gp2|.rt|.rp|.smi|.smil|").indexOf(strExtend)>=0){strType="RM"}
        if(String("|.ra|").indexOf(strExtend)>=0){strType="RA"}
    }

    if(blnShow){
        objMedia.innerHTML = strMedia;
    }
    else{
        switch(strType){
            case "SWF":
                strMedia="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+intWidth+"\" height=\""+intHeight+"\"><param name=\"movie\" value=\""+strURL+"\"><param name=\"quality\" value=\"high\"><param name=\"play\" value=\"true\"><embed src=\""+strURL+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+intWidth+"\" height=\""+intHeight+"\" play=\"true\"></embed></object>"
                break;
            case "QT":
                strMedia="<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+intWidth+"\" height=\""+intHeight+"\" ><param name=\"src\" value=\""+strURL+"\" ><param name=\"autoplay\" value=\"true\" ><embed  src=\"qtmimetype.pntg\" type=\"image/x-macpaint\"pluginspage=\"http://www.apple.com/quicktime/download\" qtsrc=\""+strURL+"\" width=\""+intHeight+"\" height=\""+intHeight+"\" autoplay=\"true\" ></embed></object>"
                break;
            case "WMV":
                strMedia="<object classid=\"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" width=\""+intWidth+"\" height=\""+intHeight+"\"><param name=\"ShowStatusBar\" value=\"-1\"><param name=\"AutoStart\" value=\"true\"><param name=\"Filename\" value=\""+strURL+"\"><embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\""+strURL+"\" autostart=\"true\" width=\""+intWidth+"\" height=\""+intHeight+"\"></embed></object>"
                break;
            case "WMA":
                strMedia="<object classid=\"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" height=\"68\" width=\"350\"><param name=\"ShowStatusBar\" value=\"-1\"><param name=\"AutoStart\" value=\"true\"><param name=\"Filename\" value=\""+strURL+"\"><embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\""+strURL+"\" autostart=\"true\" width=\"350\" height=\"45\"></embed></object>"
                break;
            case "RM":
                strMedia="<object classid=\"clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA\" width=\""+intWidth+"\" height=\""+intWidth+"\"><param name=\"src\" value=\""+strURL+"\"><param name=\"controls\" value=\"imagewindow\"><param name=\"console\" value=\"one\"><param name=\"AutoStart\" value=\"true\"><embed src=\""+strURL+"\" width=\""+intWidth+"\" height=\""+intWidth+"\" type=\"audio/x-pn-realaudio-plugin\" nojava=\"true\" controls=\"imagewindow,ControlPanel,StatusBar\" console=\"one\" autostart=\"true\"></object>"
                break;
            case "RA":
                strMedia="<object classid=\"clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA\" width=\"350\" height=\"36\"><param name=\"src\" value=\""+strURL+"\"><param name=\"controls\" value=\"ControlPanel\"><param name=\"console\" value=\"one\"><param name=\"AutoStart\" value=\"true\"><embed src=\""+strURL+"\" type=\"audio/x-pn-realaudio-plugin\" nojava=\"true\" controls=\"ControlPanel,StatusBar\" console=\"one\" autostart=\"true\" width=\"350\" height=\"36\"></object>"
        }
        objMedia.innerHTML = strMedia;
    }
}
//*********************************************************

//*********************************************************
// 目的:    InsertQuote To txaArticle
// 输入:    无
// 返回:    无
//*********************************************************
function InsertQuote(strName,strText) {
    if(!objActive){objActive="txaArticle"};

    var re;
    re=new RegExp("<br/?>","ig");
    strText=strText.replace(re, "\n");
    re=new RegExp("<[^>]*>","ig");
    strText=strText.replace(re, "");

    InsertText(objActive,"[QUOTE=",false);
    InsertText(objActive,strName,false);
    InsertText(objActive,"]",false);
    InsertText(objActive,strText,false);
    InsertText(objActive,"[/QUOTE]",false);
}
//*********************************************************

//*********************************************************
// 目的:    全选
// 输入:    无
// 返回:    无
//*********************************************************
function BatchSelectAll() {
    var aryChecks = document.getElementsByTagName("input");

    for (var i = 0; i < aryChecks.length; i++){
        if((aryChecks[i].type=="checkbox")&&(aryChecks[i].id.indexOf("edt")!==-1)){
            if(aryChecks[i].checked==true){
                aryChecks[i].checked=false;
            }
            else{
                aryChecks[i].checked=true;
            };
        }
    }
}
//*********************************************************

//*********************************************************
// 目的:    
// 输入:    无
// 返回:    无
//*********************************************************
function BatchDeleteAll(objEdit) {

    objEdit=document.getElementById(objEdit)
    objEdit.value=""
    var aryChecks = document.getElementsByTagName("input");
    for (var i = 0; i < aryChecks.length; i++){
        if((aryChecks[i].type=="checkbox")&&(aryChecks[i].id.indexOf("edt")!==-1)){
            if(aryChecks[i].checked){
                objEdit.value=aryChecks[i].value+","+objEdit.value
            }
        }
    }

}
//*********************************************************

//*********************************************************
// 目的:    图片自动缩小 点击放大
// 输入:    无
// 返回:    无
//*********************************************************
function ResizeImage(objImage,maxWidth) {
    try{
        if(maxWidth>0){
            if(objImage.width>maxWidth){
                objImage.width=maxWidth;
                objImage.attachEvent('onclick', function(){try{showModelessDialog(objImage.src);}catch(e){window.open(objImage.src);}});
                objImage.attachEvent('onmouseover', function(){objImage.style.cursor='pointer';});
            }
        }
    }catch(e){};
}
//*********************************************************

//*********************************************************
// 目的:    回复留言
// 输入:    无
// 返回:    无
//*********************************************************
function RevertComment(intRevertID) {
    var f;
    if(objActive){
        f=document.getElementById(objActive).form
    }
    else{
        f=document.getElementsByTagName("form")[document.getElementsByTagName("form").length-1]
    }

    if(f.action.search("act=cmt")>0){
        f.action=f.action.replace("cmd.asp?act=cmt","cmd.asp?act=CommentRev&id="+intRevertID);
        return true;
    }
    else{
        f.action=f.action.substr(0,f.action.search("id=")) + "id="+intRevertID +"&" + f.action.substr(f.action.search("key="))
        return true;
    }
}

Javascript 相关文章推荐
本地对象Array的原型扩展实现代码
Dec 04 Javascript
IE6下CSS图片缓存问题解决方法
Dec 09 Javascript
深入理解JavaScript系列(12) 变量对象(Variable Object)
Jan 16 Javascript
js中switch case循环实例代码
Dec 30 Javascript
javascript函数重载解决方案分享
Feb 19 Javascript
jQuery中closest()函数用法实例
Jan 07 Javascript
javascript将数字转换整数金额大写的方法
Jan 27 Javascript
JavaScript内存管理介绍
Mar 13 Javascript
js+canvas绘制五角星的方法
Jan 28 Javascript
JavaScript实现的贝塞尔曲线算法简单示例
Jan 30 Javascript
JavaScript设计模式之工厂模式和抽象工厂模式定义与用法分析
Jul 26 Javascript
vue 根据数组中某一项的值进行排序的方法
Aug 30 Javascript
htm调用JS代码
Mar 15 #Javascript
QQ邮箱的一个文本编辑器代码
Mar 14 #Javascript
用js实现的一个Flash滚动轮换显示图片代码生成器
Mar 14 #Javascript
js实现的网站首页随机公告随机公告
Mar 14 #Javascript
newxtree.js代码
Mar 13 #Javascript
xtree.js 代码
Mar 13 #Javascript
js资料prototype 属性
Mar 13 #Javascript
You might like
PHP实现执行外部程序的方法详解
2017/08/17 PHP
基于jquery.Jcrop的头像编辑器
2010/03/01 Javascript
Javascript 八进制转义字符(8进制)
2011/04/08 Javascript
JQquery的一些使用心得分享
2012/08/01 Javascript
JS获取随机数函数可自定义最小值最大值
2014/05/08 Javascript
javascript获取checkbox复选框获取选中的选项
2014/08/12 Javascript
详解JavaScript中void语句的使用
2015/06/04 Javascript
jquery实现红色竖向多级向右展开的导航菜单效果
2015/08/31 Javascript
详细解读Jquery各Ajax函数($.get(),$.post(),$.ajax(),$.getJSON())
2016/08/15 Javascript
Vue.js组件tab实现选项卡切换
2020/03/23 Javascript
JS实现无缝循环marquee滚动效果
2017/05/22 Javascript
基于JS代码实现简单易用的倒计时 x 天 x 时 x 分 x 秒效果
2017/07/13 Javascript
js+html5实现侧滑页面效果
2017/07/15 Javascript
浅谈vue中.vue文件解析流程
2018/04/24 Javascript
微信小程序开发问题之wx.previewImage
2018/12/25 Javascript
Vue起步(无cli)的啊教程详解
2019/04/11 Javascript
bootstrap 日期控件 datepicker被弹出框dialog覆盖的解决办法
2019/07/09 Javascript
20多个小事例带你重温ES10新特性(小结)
2019/09/29 Javascript
js实现无缝轮播图特效
2020/05/09 Javascript
JQuery基于FormData异步提交数据文件
2020/09/01 jQuery
ant design中upload组件上传大文件,显示进度条进度的实例
2020/10/29 Javascript
python调用新浪微博API项目实践
2014/07/28 Python
centos 下面安装python2.7 +pip +mysqld
2014/11/18 Python
python检测远程udp端口是否打开的方法
2015/03/14 Python
python实现根据文件关键字进行切分为多个文件的示例
2018/12/10 Python
python搜索包的路径的实现方法
2019/07/19 Python
django model object序列化实例
2020/03/13 Python
python画图时设置分辨率和画布大小的实现(plt.figure())
2021/01/08 Python
世界顶级足球门票网站:Live Football Tickets
2017/10/14 全球购物
ASP.NET中的身份验证有那些
2012/07/13 面试题
行政助理的职责
2013/11/14 职场文书
优秀团支部事迹材料
2014/02/08 职场文书
股权转让意向书
2014/04/01 职场文书
会计学专业自荐信
2014/06/25 职场文书
2014年党委工作总结
2014/11/22 职场文书
2016计算机专业毕业生自荐信
2016/01/28 职场文书