您好,欢迎访问一九零五行业门户网

Hutia 的 JS 代码集_javascript技巧

main.basic.js
复制代码 代码如下:
/**************************************************
 *        the basic lib for hutia frame work
 * author: hutia
 * e-mail: hutia2@gmail.com
 * create: 2006-08-21
 * last modify: 2006-08-26
 * version: 1.02
 * copyright declare: everybody can use for freely but can not be used in commerce.
 *
 * please keep this information while quote.
**/
//******** before all **************
var currentlibname=main.basic;
try{ // catch all the exceptions during loading
//================= declare constant section === start ===========
var vbok=0;    var vbokcancel=1;    var vbabortretryignor=2;    var vbyesnocancel=3;
var vbyesno=4;    var vbretrycacel=5;    var vbstop=16;    var vbquest=32;    var vbalert=48;
var vbinfo=64;    var vbreturnok=1;    var vbreturncacel=2;    var vbreturnabort=3;
var vbreturnretry=4;    var vbreturnignor=5;    var vbreturnyes=6;    var vbreturnno=7;
var vbcrlf=\r\n;
//----------------- declare constant section - end ---------------
/////////////////////////////////////////////////////////////////////////
//================= declare global variable section === start ===========
var site_root=e:\\hutia\\program\\developing\\gjs_v3.replace(/\\/g,\/).replace(/([^\/])$/,$1\/);
//----------------- declare global variable section - end ---------------
/////////////////////////////////////////////////////////////////////////
//================= declare global function section === start ===========
// alia name for asynloader.depend
$depend=function(str,currentlibname,defer){
    asynloader.depend(str,currentlibname,defer);
}
// alia name for asynloader.include
$include=function(str){
    asynloader.include(str);
}
function say(str){
    alert(str);
}
function uid(){
    return(u+(new date()).gettime().tostring(35)+parseint(math.random()*999999).tostring(35));
}
//----------------- declare global function section - end ---------------
/////////////////////////////////////////////////////////////////////////
//================= declare global object section === start ===========
// the asynchronous loader
var asynloader= new function(){
    // delare private variable
    var alias, currentpath, dependences, dependent, libs, paths;
}
asynloader.alertloadresult=function(){
    var str=;
    for(var i in libs){if(libs[i]==loaded){str+=load \+i+\ successfully.\r\n;}else{str+=libs[i]+\r\n;}}
    say(str);
}
asynloader.alias=function(aliasname,strpath,singleinstance){
    strpath=this.getpath(strpath);
    if(!strpath||typeof(aliasname)!=string||aliasname==)return;
    alias[aliasname]=strpath;
    alias[aliasname][2]=boolean(singleinstance);
}
asynloader.depend=function(strlibname,strsrclibname,defer){
    if(typeof(strlibname)!=string||strlibname==)throw(invalid lib name.);
    if(libs[strlibname]!=loaded){
        if(defer&&alias[strlibname]){
            asynloader.include(strlibname);
        }else throw(dependence validation failure.\r\n+libs[strlibname]);
    }
    if(typeof(strsrclibname)==string&&strsrclibname!=){
        temp=strsrclibname+ => +strlibname;
        dependences.push(temp);
    }
}
asynloader.getdependby=function(str){
    var re=new array();
    for(var i=0;i )[1]==str)re.push(dependences[i].split( => )[0]);
    return(re.join(;));
}
asynloader.getdependon=function(str){
    var re=new array();
    for(var i=0;i )[0]==str)re.push(dependences[i].split( => )[1]);
    return(re.join(;));
}
asynloader.getlibs=function(){
    var re=new array(), hash=new array();
    for(var i in libs)if(!hash[i]){hash[i]=true;re.push(i);}
    re.sort();
    return(re.join(;));
}
asynloader.getpath=function(strpath){
    var ext, i, re, strpath;
    if(typeof(strpath)!=string||strpath==)return(false);
    ext=js;
    if(strpath.indexof(:)==-1)if(this.pathtype==absolute){strpath=site_root+currentpath+strpath;}else{strpath=currentpath+strpath;}
    i=strpath.lastindexof(.);
    if(i!=-1&&i        ext=strpath.substring(i+1).tolowercase();
    }else{
        strpath=strpath+.+ext;
    }
    return([strpath,ext]);
}
asynloader.include=function(strpath,classname){
    var ext, i, singleinstance, strpath;
    if(alias[strpath]){
        strpath=alias[strpath];
    }else{
        strpath=this.getpath(strpath);
    }
    if(!strpath)return(false);
    ext=strpath[1];
    singleinstance=boolean(strpath[2])||classname==singleinstance||paths[strpath]==singleinstance;
    strpath=strpath[0];
    if(singleinstance&&paths[strpath])return;
    paths[strpath]=singleinstance?singleinstance:true;
    switch(ext){
        case js:
            document.write();
        break;
        case vbs:
            document.write();
        break;
        case css:
            document.write();
        break;
        case jpg: case gif: case bmp: case jpeg: case png:
            document.write();
        break;
        default:
            document.write();
        break;
    }
}
asynloader.init=function(){
    alias=new array();
    currentpath=;
    dependences=new array();
    dependent=new array();
    libs=new array();
    paths=new array();
this.pathtype=absolute;
}
asynloader.libs=function(blnnotloaded){
    var re=new array();
    for(var i in libs)if((libs[i]==loaded)^blnnotloaded)re.push(i);
    return(re);
}
asynloader.loadfailure=function(strlibname,e){
    if(e==exit)return;
    libs[strlibname]=loading +strlibname+ model failed:\r\n;
    for(var i in e)libs[strlibname]+=  +i+:+e[i]+\r\n;
}
asynloader.loadsuccess=function(strlibname){
    libs[strlibname]=loaded;
}
asynloader.setpath=function(strpath){
    if(typeof(strpath)!=string)return;
    currentpath=strpath.replace(/\\/g,\/).replace(/([^\/])$/,$1\/);
}
asynloader.singleinstance=function(strpath){
    if(alias[strpath]){
        strpath=alias[strpath];
    }else{
        strpath=this.getpath(strpath);
    }
    if(!strpath)return(false);
    strpath=strpath[0];
    if(paths[strpath]){
        throw(exit);
    }else{
        paths[strpath]=true;
    }
}
asynloader.init();
//----------------- declare global object section - end ---------------
/////////////////////////////////////////////////////////////////////////
//================= initialization section === start ===========
asynloader.pathtype=relative;
asynloader.include(js/main.alias.js);
//----------------- initialization section - end ---------------
//***************** after all ***********************
asynloader.loadsuccess(currentlibname);
}catch(e){ asynloader.loadfailure(currentlibname); }
////////////////////////////////////////////////////////////////
///////////////////       file end    //////////////////////////
////////////////////////////////////////////////////////////////
其它类似信息

推荐信息