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

📄 init.js

📁 SugarCRM5.1 开源PHP客户关系管理系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
                    obj=new ActiveXObject("Msxml2.XMLHTTP");                }catch(e){                    try{// to get the old MS HTTP request object                        obj = new ActiveXObject("microsoft.XMLHTTP");                     }catch(e){                        throw new mod.Exception("Unable to get an HTTP request object.");                    }                }                }        }        return obj;    }    /**        Retrieves a file given its URL.        @param url             The url to load.        @param headers=[]  The headers to use.        @return                 The content of the file.    */    var getFile=function(url, headers) {         //if callback is defined then the operation is done async        headers = (headers != null) ? headers : [];        //setup the request        try{            var xmlhttp= getHTTP();            xmlhttp.open("GET", url, false);            for(var i=0;i< headers.length;i++){                xmlhttp.setRequestHeader(headers[i][0], headers[i][1]);                }            xmlhttp.send("");        }catch(e){            throw new mod.Exception("Unable to load URL: '%s'.".format(url), e);        }        if(xmlhttp.status == 200 || xmlhttp.status == 0){            return xmlhttp.responseText;        }else{             throw new mod.Exception("File not loaded: '%s'.".format(url));        }    }        Error.prototype.toTraceString = function(){        if(this.message){            return "%s\n".format(this.message);        }        if (this.description){           return "%s\n".format(this.description);        }        return "unknown error\n";     }           /**        Thrown when a module could not be found.    */    mod.ModuleImportFailed=Class(mod.Exception, function(publ, supr){        /**            Initializes a new ModuleImportFailed Exception.            @param name      The name of the module.            @param url          The url of the module.            @param trace      The error cousing this Exception.        */        publ.init=function(moduleName, url, trace){            supr(this).init("Failed to import module: '%s' from URL:'%s'".format(moduleName, url), trace);            this.moduleName = moduleName;            this.url = url;        }        ///The  name of the module that was not found.        publ.moduleName;        ///The url the module was expected to be found at.        publ.url;    })        /**        Thrown when a source could not be loaded due to an interpretation error.    */    mod.EvalFailed=Class(mod.Exception, function(publ, supr){        /**            Initializes a new EvalFailed exception.            @param url                   The url of the module.            @param trace               The exception that was thrown while interpreting the module's source code.        */        publ.init=function(url, trace){            supr(this).init("File '%s' Eval of script failed.".format(url), trace);            this.url = url;        }        ///The url the module was expected to be found at.        publ.url;    })        /**        Displays an exception and it's trace.        This works better than alert(e) because traces are taken into account.        @param exception  The exception to display.    */    mod.reportException=function(exception){        if(exception.toTraceString){            var s= exception.toTraceString();        }else{            var s = exception.toString();        }        var ws = null;        try{//see if WScript is available            ws = WScript;        }catch(e){        }        if(ws != null){            WScript.stderr.write(s);        }else{            alert(s);        }    }        ///The global exception report method;    reportException = mod.reportException;})//stringmod/**    String formatting module.    It allows python like string formatting ("some text %s" % "something").    Also similar to sprintf from C.*/Module("stringformat", "0.1.0", function(mod){    /**        Creates a format specifier object.     */    var FormatSpecifier=function(s){        var s = s.match(/%(\(\w+\)){0,1}([ 0-]){0,1}(\+){0,1}(\d+){0,1}(\.\d+){0,1}(.)/);        if(s[1]){            this.key=s[1].slice(1,-1);        }else{            this.key = null;        }        this.paddingFlag = s[2];        if(this.paddingFlag==""){            this.paddingFlag =" "         }        this.signed=(s[3] == "+");        this.minLength = parseInt(s[4]);        if(isNaN(this.minLength)){            this.minLength=0;        }        if(s[5]){            this.percision = parseInt(s[5].slice(1,s[5].length));        }else{            this.percision=-1;        }        this.type = s[6];    }    /**        Formats a string replacing formatting specifiers with values provided as arguments        which are formatted according to the specifier.        This is an implementation of  python's % operator for strings and is similar to sprintf from C.        Usage:            resultString = formatString.format(value1, v2, ...);                Each formatString can contain any number of formatting specifiers which are        replaced with the formated values.                specifier([...]-items are optional):             "%(key)[flag][sign][min][percision]typeOfValue"                        (key)  If specified the 1st argument is treated as an object/associative array and the formating values                      are retrieved from that object using the key.                            flag:                0      Use 0s for padding.                -      Left justify result, padding it with spaces.                        Use spaces for padding.            sign:                +      Numeric values will contain a +|- infront of the number.            min:                l      The string will be padded with the padding character until it has a minimum length of l.             percision:               .x     Where x is the percision for floating point numbers and the lenght for 0 padding for integers.            typeOfValue:                d    Signed integer decimal.  	                 i     Signed integer decimal. 	                 b    Unsigned binary.                       //This does not exist in python!                o    Unsigned octal. 	                u    Unsigned decimal. 	                 x    Unsigned hexidecimal (lowercase). 	                X   Unsigned hexidecimal (uppercase). 	                e   Floating point exponential format (lowercase). 	                 E   Floating point exponential format (uppercase). 	                 f    Floating point decimal format. 	                 F   Floating point decimal format. 	                 c   Single character (accepts byte or single character string). 	                 s   String (converts any object using object.toString()). 	                Examples:            "%02d".format(8) == "08"            "%05.2f".format(1.234) == "01.23"            "123 in binary is: %08b".format(123) == "123 in binary is: 01111011"                    @param *  Each parameter is treated as a formating value.         @return The formated String.    */    String.prototype.format=function(){        var sf = this.match(/(%(\(\w+\)){0,1}[ 0-]{0,1}(\+){0,1}(\d+){0,1}(\.\d+){0,1}[dibouxXeEfFgGcrs%])|([^%]+)/g);        if(sf){            if(sf.join("") != this){                throw new mod.Exception("Unsupported formating string.");            }        }else{            throw new mod.Exception("Unsupported formating string.");        }        var rslt ="";        var s;        var obj;        var cnt=0;        var frmt;        var sign="";                for(var i=0;i<sf.length;i++){            s=sf[i];            if(s == "%%"){                s = "%";            }else if(s.slice(0,1) == "%"){                frmt = new FormatSpecifier(s);//get the formating object                if(frmt.key){//an object was given as formating value                    if((typeof arguments[0]) == "object" && arguments.length == 1){                        obj = arguments[0][frmt.key];                    }else{                        throw new mod.Exception("Object or associative array expected as formating value.");                    }                }else{//get the current value                    if(cnt>=arguments.length){                        throw new mod.Exception("Not enough arguments for format string");                    }else{                        obj=arguments[cnt];                        cnt++;                    }                }                                    if(frmt.type == "s"){//String                    if (obj == null){                        obj = "null";                    }                    s=obj.toString().pad(frmt.paddingFlag, frmt.minLength);                                    }else if(frmt.type == "c"){//Character                    if(frmt.paddingFlag == "0"){                        frmt.paddingFlag=" ";//padding only spaces                    }                    if(typeof obj == "number"){//get the character code                        s = String.fromCharCode(obj).pad(frmt.paddingFlag , frmt.minLength) ;                    }else if(typeof obj == "string"){                        if(obj.length == 1){/*make sure it's a single character*/                            s=obj.pad(frmt.paddingFlag, frmt.minLength);                        }else{                            throw new mod.Exception("Character of length 1 required.");                        }                    }else{                        throw new mod.Exception("Character or Byte required.");                    }                }else if(typeof obj == "number"){                    //get sign of the number                    if(obj < 0){                        obj = -obj;                        sign = "-"; //negative signs are always needed                    }else if(frmt.signed){                        sign = "+"; // if sign is always wanted add it                     }else{                        sign = "";                    }                    //do percision padding and number conversions                    switch(frmt.type){                        case "f": //floats                        case "F":                            if(frmt.percision > -1){                                s = obj.toFixed(frmt.percision).toString();                            }else{                                s = obj.toString();                            }                            break;                        case "E"://exponential                        case "e":                            if(frmt.percision > -1){                                s = obj.toExponential(frmt.percision);                            }else{                                s = obj.toExponential();                            }                            s = s.replace("e", frmt.type);                            break;                        case "b"://binary                            s = obj.toString(2);                            s = s.pad("0", frmt.percision);                            break;                        case "o"://octal                            s = obj.toString(8);                            s = s.pad("0", frmt.percision);                            break;                        case "x"://hexadecimal                            s = obj.toString(16).toLowerCase();                            s = s.pad("0", frmt.percision);                            break;                        case "X"://hexadecimal                            s = obj.toString(16).toUpperCase();                            s = s.pad("0", frmt.percision);                            break;                        default://integers                            s = parseInt(obj).toString();                            s = s.pad("0", frmt.percision);                            break;                    }                    if(frmt.paddingFlag == "0"){//do 0-padding                        //make sure that the length of the possible sign is not ignored                        s=s.pad("0", frmt.minLength - sign.length);                    }                    s=sign + s;//add sign                    s=s.pad(frmt.paddingFlag, frmt.minLength);//do padding and justifiing                }else{                    throw new mod.Exception("Number required.");                }            }            rslt += s;        }        return rslt;    }        /**        Padds a String with a character to have a minimum length.                @param flag   "-":      to padd with " " and left justify the string.                            Other: the character to use for padding.         @param len    The minimum length of the resulting string.    */    String.prototype.pad = function(flag, len){        var s = "";        if(flag == "-"){            var c = " ";        }else{            var c = flag;        }        for(var i=0;i<len-this.length;i++){            s += c;        }        if(flag == "-"){            s = this + s;        }else{            s += this;        }        return s;    }        /**        Repeats a string.        @param c  The count how often the string should be repeated.    */    String.prototype.mul = function(c){        var a = new Array(this.length * c);        var s=""+ this;        for(var i=0;i<c;i++){            a[i] = s;        }        return a.join("");    }})//let jsolait do some startup initializationjsolait.init();

⌨️ 快捷键说明

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