现在的位置: 首页 > 综合 > 正文

MainPage_JavascriptCodes

2012年08月11日 ⁄ 综合 ⁄ 共 8897字 ⁄ 字号 评论关闭
 <script>

ShowPageStatus("Hello world!",true);
//IncludeJSFile("http://blog.csdn.net/norsd/archive/2006/10/02/1315583.aspx",[]);
//IncludeJSFile("http://blog.csdn.net/norsd/archive/2006/10/02/1315584.aspx",[]);
//IncludeJSFile("http://blog.csdn.net/norsd/archive/2006/10/02/1315585.aspx",[]);
//IncludeJSFile("http://blog.csdn.net/norsd/archive/2006/10/02/1315593.aspx",["ChangeEssayStyle()"]);
//IncludeJSFile("http://blog.csdn.net/norsd/archive/2006/09/09/1199148.aspx",["ChangeEssayStyle()"]);

var IJSFS_gnJSFileNumber = 0;
var IJSFS_gnGotContentJSFileNumber = 0;
var IJSFS_gstrJSFileContent = '';
IncludeJSFiles(["http://blog.csdn.net/norsd/archive/2006/10/02/1315583.aspx",
                "http://blog.csdn.net/norsd/archive/2006/10/02/1315585.aspx",
                "http://blog.csdn.net/norsd/archive/2006/09/09/1199148.aspx"],
               ["ChangeEssayStyle()"]);
function IncludeJSFiles( arrFilePath, arrExeFns)
{
   IJSFS_gnJSFileNumber = arrFilePath.length;
   for( var i=0; i<IJSFS_gnJSFileNumber; i++ )
   {
       var xmlhttp = new _xmlhttp(arrFilePath[i],true);
        xmlhttp.OnStatus200 = IncludeJSFiles_CallBack(arrFilePath[i],arrExeFns);
    xmlhttp.openRef("GET",true,null,null);
    xmlhttp.sendRef();
   }
}
function IncludeJSFiles_CallBack( strJSFilePath,arrExeFns )
{
  return function()
  {
    IJSFS_gnGotContentJSFileNumber++;
    var strResText = this.getResponseText();
    var re = /////SCRIPT_START[/w|/W|]*////SCRIPT_END/i;
    var arrIndex = re.exec(strResText);
    if( arrIndex == null )
        alert("RegExp JSFile Error!");
    var strHtmlText =  arrIndex[0];
    var strText = HtmlToString(strHtmlText);
    IJSFS_gstrJSFileContent += strText;
    if( IJSFS_gnGotContentJSFileNumber == IJSFS_gnJSFileNumber )
    {
       var objTop = document.getElementById("top");
       var objTmp = document.createElement("div");
           objTmp.style.display = "none";
           objTop.appendChild(objTmp);
       DeferScripts( IJSFS_gstrJSFileContent , objTmp );
       for( var i=0; i<arrExeFns.length; i++ )
           eval(arrExeFns[i]);
    }
  }
}
function IncludeJSFile( DstPath )
{    
    var xmlhttp = new _xmlhttp(DstPath,true);
        xmlhttp.OnStatus200 = IncludeJSFile_CallBack(arguments.length==2?arguments[1]:null);
    xmlhttp.openRef("GET",true,null,null);
    xmlhttp.sendRef();
}
function IncludeJSFile_CallBack( arrFn )
{      
       return function()
       {
       var strResText = this.getResponseText();
       var re = /////SCRIPT_START[/w|/W|]*////SCRIPT_END/i;
       var arrIndex = re.exec(strResText);
       var strHtmlText =  arrIndex[0];
       var strText = HtmlToString(strHtmlText);
          
       var objTop = document.getElementById("top");
       var objTmp = document.createElement("div");
           objTmp.style.display = "none";
           objTop.appendChild(objTmp);
       DeferScripts( strText, objTmp );
       //alert(strText);
       if( arrFn.constructor == Array )
           for( var i=0; i<arrFn.length; i++ )
                eval(arrFn[i]);
       }
}
function DeferScripts( strCodes, oElement )
{
    var oDate = new Date();
    var nSeconds = oDate.getTime()
    var strTestFnName = "testCodes_"+nSeconds +"();"
    var testCodes = "/nfunction testCodes_"+nSeconds+"(){return null;}/n";
    oElement.innerHTML = "<br/><"+"SCRIPT defer>/n"+strCodes+testCodes+"/n<//S"+"CRIPT>";
    try
    {//For IE
        eval(strTestFnName);
    }
    catch(e)
    {//For MF    As MF doesn't support the "script defer",but if you reappend child , it will work!
        var oParent = oElement.parentNode;
            oParent.removeChild(oElement);
        oElement.innerHTML = oElement.innerHTML;
        oParent.appendChild(oElement);
        try{eval(strTestFnName);}
        catch(cc){alert("Unsupport browser/n codes: '<script defer>' doesn't work,/nor there are some error at the JS file has been included");}
    }
}
function HtmlToString( strHtml )
{
    var re = /<br.?//>/ig;
    var strTmp = strHtml.replace(re,"/n");
        re = /&nbsp;/ig;
        strTmp = strTmp.replace(re," ");
        re = /&lt;/ig;
        strTmp = strTmp.replace(re,"<");
        re = /&gt;/ig;
        strTmp = strTmp.replace(re,">");
        re = /&quot;/ig;
        strTmp = strTmp.replace(re,'"');
        re = /&amp;/ig;
        strTmp = strTmp.replace(re,'&');
    return strTmp;
}
function ShowPageStatus(strInfo,bDebug)
{
   var oPageInfo;
   if( (oPageInfo = document.getElementById('PageInfo'))==null )
   {
      try
      {  
         var oMain,oPageInfos,oPageInfo;
         if( (oMain = document.getElementById('main'))==null)
              throw "oMain==null";
         if( (oPageInfos= getElementsByClassName(oMain,'dateTitle'))==null)
              throw "cannot find object that class name is [dateTitle]";
         oPageInfo = oPageInfos[0];
         oPageInfo.id = 'PageInfo';
       }
       catch(e2)
       {
           if(bDebug)
               alert(e2);
           return false;
        }
    }
    oPageInfo.innerHTML = strInfo;
    return true;
}
function DebugPrint(strFilePath)
{
    this.strFilePath = typeof(strFilePath)=='undefined'?"c://test.txt":strFilePath;
    try
    {
      this.aoFSO = new ActiveXObject("Scripting.FileSystemObject");
      this.hDebugFile = this.aoFSO.createTextFile(this.strFilePath,"true");
    }
    catch(e1)
    {
      alert(e1);
    }
    this.Show = function(strContent)
    {this.hDebugFile.WriteLine(strContent);}
}
function _xmlhttp( httpRef, bDebug )
{
    this.oXML = null;
    this.httpRef = httpRef;
    this.arrReadyState = new Array("0","1","2","3","4");
    this.OnReadyState0 = function(){return;};
    this.OnReadyState1 = function(){return;};
    this.OnReadyState2 = function(){return;};
    this.OnReadyState3 = function(){return;};
    this.OnReadyState4 = function(){return;};
    this.OnStatus200 = function(){return;};
    this.OnStatus404 = function(){return;};
    this.state = true;
    this.lastErrMsg = null;
    this.bDebug = typeof(bDebug)=='boolean'?bDebug:false;
    try
    {
        this.oXML=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
           this.oXML=new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch(e2)
         {
            try
            {
              this.oXML = new XMLHttpRequest();
            }
            catch(ob)
            {
               this.state = false;
               this.lastErrMsg = "Create XMLHttpRequest Error";
               this.ShowDebug();
             }
          }
     }
      
    //member function define section:
    this.hOnReadyStateChange = function( oSelf )
    {
       return function()
       {
         switch(oSelf.oXML.readyState)
         {  
           case 0:
             oSelf.OnReadyState0();
             break;
           case 1:
             oSelf.OnReadyState1();
             break;
           case 2:
             oSelf.OnReadyState2();
             break;
           case 3:
             oSelf.OnReadyState3();
             break;
           case 4:
             oSelf.OnReadyState4();
             if( oSelf.oXML.status == 200 )
             oSelf.OnStatus200();
             else if( oSelf.oXML.status == 404 )
             oSelf.OnStatus404();
             break;
           default:
             break;
         }//switch end
       }//return function end   
    }
    this.oXML.onreadystatechange = this.hOnReadyStateChange (this);
    this.openRef = function( strMethod , varAsync, strUser, strPassword)
    {
        try
        {
           this.oXML.open(strMethod,this.httpRef,varAsync);
        }
        catch(e)
        {
           this.state = false;
           this.lastErrMsg = "uncaught exception : XMLHttpRequest.open";
           this.ShowDebug();
        }
    }
    this.sendRef = function(strContent)
    {
       try
       {
          this.oXML.send(strContent);
       }
       catch(e)
       {
          this.state = false;
          this.lastErrMsg = "uncaught exception : XMLHttpRequest.send";
          this.ShowDebug();
       }
    }
    this.getXMLReadyState = function()
    {
        return Array(this.oXML.readyState, this.arrReadyState.length-1<this.oXML.readyState?null:this.arrReadyState[this.oXML.readyState]);
    }
    this.getResponseText = function()
    {
       return this.oXML.responseText;
    }
    this.getResponseXML = function()
    {
        return this.oXML.responseXML;
    }
    this.setRequestHeader = function( sName, sValue)
    {
        return this.oXML.setRequestHeader(sName, sValue);
    }
    this.ShowDebug = function()
    {
        if( this.bDebug )
            alert(this.lastErrMsg);
    }
    this.SetDebug = function( bDebug )
    {
        this.bDebug = typeof(bDebug)=='undefined'?this.bDebug:bDebug;
    }
}
function getElementsByClassName( oElement, strCls )
{
       var arrRet = new Array();
       for( var i=0; i<oElement.childNodes.length;i++ )
               if( oElement.childNodes[i].className==strCls )
                       arrRet[arrRet.length] = oElement.childNodes[i];
      return arrRet.length?arrRet:null;
}
function getElementById( Id,Doc,nDebug,strErrMsg )
{
    /*
    nDebug =
              0:  no Debug;
              1:  show Debug directly;
              2:  throw Debug ;
    */
    if( typeof(Doc)=='undefined' | Doc==null | Doc=='' )
       Doc = document;
    if( !(Doc.getElementById)  )
    {
          alert( " getElementById of the object is not exist");
          return null;
    }
    if( !nDebug )
    {
          return Doc.getElementById(Id);
    }
    else
    {
 
            var oRet;
            if( (oRet = Doc.getElementById(Id))==null )
            {
                  var strInfo = (typeof(strErrMsg)=='undefined')?"GetElementById:["+Id+"] Error":strErrMsg ;
                  if( nDebug == 1)
                       alert(strInfo);
                  if( nDebug == 2)
                     throw strInfo;
            }
            return oRet;
    }
    return null;
}
</script>

抱歉!评论已关闭.