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 相关文章推荐
js的闭包的一个示例说明
Nov 18 Javascript
js数组去重的常用方法总结
Jan 24 Javascript
JS调用页面表格导出excel示例代码
Mar 18 Javascript
jQuery实现iframe父窗体和子窗体的相互调用
Jun 17 Javascript
避免jQuery名字冲突 noConflict()方法
Jul 30 Javascript
node.js中express-session配置项详解
May 31 Javascript
Angular 4依赖注入学习教程之ValueProvider的使用(七)
Jun 04 Javascript
基于JavaScript实现带数据验证和复选框的表单提交
Aug 23 Javascript
jQuery实现的鼠标滚轮控制图片缩放功能实例
Oct 14 jQuery
JS函数节流和函数防抖问题分析
Dec 18 Javascript
快速解决bootstrap下拉菜单无法隐藏的问题
Aug 10 Javascript
JavaScript中变量提升和函数提升的详解
Aug 07 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常用文件操作函数和简单实例分析
2016/06/03 PHP
PHP基于自定义类随机生成姓名的方法示例
2017/08/05 PHP
js编码、解码函数介绍及其使用示例
2013/09/05 Javascript
jquery中获取id值方法小结
2013/09/22 Javascript
基于百度地图实现产品销售的单位位置查看功能设计与实现
2016/10/21 Javascript
jQuery设置和获取select、checkbox、radio的选中值方法
2017/01/01 Javascript
Bootstrap中glyphicons-halflings-regular.woff字体报404错notfound的解决方法
2017/01/19 Javascript
NodeJS实现微信公众号关注后自动回复功能
2017/05/31 NodeJs
Vue.js上下滚动加载组件的实例代码
2017/07/17 Javascript
SeaJS中use函数用法实例分析
2017/10/10 Javascript
vue checkbox 全选 数据的绑定及获取和计算方法
2018/02/09 Javascript
微信小程序使用swiper组件实现层叠轮播图
2018/11/04 Javascript
vue请求本地自己编写的json文件的方法
2019/04/25 Javascript
javascript实现倒计时效果
2020/02/17 Javascript
小程序富文本提取图片可放大缩小
2020/05/26 Javascript
ES5和ES6中类的区别总结
2020/12/21 Javascript
[28:28]Ti4 冒泡赛第二天NEWBEE vs NaVi 2
2014/07/15 DOTA
python实现通过shelve修改对象实例
2014/09/26 Python
分享Python开发中要注意的十个小贴士
2016/08/30 Python
详谈Python中列表list,元祖tuple和numpy中的array区别
2018/04/18 Python
Python迭代器模块itertools使用原理解析
2019/12/11 Python
Python代码中如何读取键盘录入的值
2020/05/27 Python
python实现密码验证合格程序的思路详解
2020/06/01 Python
keras Lambda自定义层实现数据的切片方式,Lambda传参数
2020/06/11 Python
用python写PDF转换器的实现
2020/10/29 Python
英国最大的在线床超市:Bed Star
2019/01/24 全球购物
波兰在线杂货店:Polski Koszyk
2019/11/02 全球购物
毕业生精彩的自我评价分享
2013/10/06 职场文书
简历中求职的个人自我评价
2013/12/03 职场文书
销售团队获奖感言
2014/08/14 职场文书
招标承诺书
2014/08/30 职场文书
学生打架检讨书
2014/10/20 职场文书
六五普法先进个人主要事迹材料
2015/11/03 职场文书
确保减税降费落地生根,用实实在在措施
2019/07/19 职场文书
Python 如何将integer转化为罗马数(3999以内)
2021/06/05 Python
SpringBoot项目多数据源及mybatis 驼峰失效的问题解决方法
2022/07/07 Java/Android