form-debug.js

来自「php绿色服务器,让大家试用greenamp」· JavaScript 代码 · 共 2,414 行 · 第 1/5 页

JS
2,414
字号
        filterKeys : function(e){        var k = e.getKey();        if(!Ext.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){            return;        }        var c = e.getCharCode();        if(!this.maskRe.test(String.fromCharCode(c) || '')){            e.stopEvent();        }    },    setValue : function(v){        if(this.emptyText && v !== undefined && v !== null && v !== ''){            this.el.removeClass(this.emptyClass);        }        Ext.form.TextField.superclass.setValue.apply(this, arguments);    },        validateValue : function(value){        if(value.length < 1 || value === this.emptyText){              if(this.allowBlank){                 this.clearInvalid();                 return true;             }else{                 this.markInvalid(this.blankText);                 return false;             }        }        if(value.length < this.minLength){            this.markInvalid(String.format(this.minLengthText, this.minLength));            return false;        }        if(value.length > this.maxLength){            this.markInvalid(String.format(this.maxLengthText, this.maxLength));            return false;        }        if(this.vtype){            var vt = Ext.form.VTypes;            if(!vt[this.vtype](value)){                this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);                return false;            }        }        if(typeof this.validator == "function"){            var msg = this.validator(value);            if(msg !== true){                this.markInvalid(msg);                return false;            }        }        if(this.regex && !this.regex.test(value)){            this.markInvalid(this.regexText);            return false;        }        return true;    },        selectText : function(start, end){        var v = this.getRawValue();        if(v.length > 0){            start = start === undefined ? 0 : start;            end = end === undefined ? v.length : end;            var d = this.el.dom;            if(d.setSelectionRange){                d.setSelectionRange(start, end);            }else if(d.createTextRange){                var range = d.createTextRange();                range.moveStart("character", start);                range.moveEnd("character", v.length-end);                range.select();            }        }    },        autoSize : function(){        if(!this.grow || !this.rendered){            return;        }        if(!this.metrics){            this.metrics = Ext.util.TextMetrics.createInstance(this.el);        }        var el = this.el;        var v = el.dom.value + "&#160;";        var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) +  10, this.growMin));        this.el.setWidth(w);        this.fireEvent("autosize", this, w);    }});Ext.form.TriggerField = function(config){    Ext.form.TriggerField.superclass.constructor.call(this, config);    this.mimicing = false;    this.on('disable', this.disableWrapper, this);    this.on('enable', this.enableWrapper, this);};Ext.extend(Ext.form.TriggerField, Ext.form.TextField,  {            defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},        hideTrigger:false,                    autoSize: Ext.emptyFn,    monitorTab : true,        customSize : true,        setSize : function(w, h){        if(!this.wrap){            this.width = w;            this.height = h;            return;        }        if(w){            var wrapWidth = w;            w = w - this.trigger.getWidth();            Ext.form.TriggerField.superclass.setSize.call(this, w, h);            this.wrap.setWidth(wrapWidth);            if(this.onResize){                this.onResize(wrapWidth, h);            }        }else{            Ext.form.TriggerField.superclass.setSize.call(this, w, h);            this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());        }    },        alignErrorIcon : function(){        this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);    },        onRender : function(ct, position){        Ext.form.TriggerField.superclass.onRender.call(this, ct, position);        this.wrap = this.el.wrap({cls: "x-form-field-wrap"});        this.trigger = this.wrap.createChild({            tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger "+this.triggerClass});        this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});        this.trigger.addClassOnOver('x-form-trigger-over');        this.trigger.addClassOnClick('x-form-trigger-click');        if(this.hideTrigger){            this.trigger.setDisplayed(false);        }        this.setSize(this.width||'', this.height||'');    },    onDestroy : function(){        if(this.trigger){            this.trigger.removeAllListeners();            this.trigger.remove();        }        if(this.wrap){            this.wrap.remove();        }        Ext.form.TriggerField.superclass.onDestroy.call(this);    },        onFocus : function(){        Ext.form.TriggerField.superclass.onFocus.call(this);        if(!this.mimicing){            this.mimicing = true;            Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);            if(this.monitorTab){                this.el.on("keydown", this.checkTab, this);            }        }    },        checkTab : function(e){        if(e.getKey() == e.TAB){            this.triggerBlur();        }    },        onBlur : function(){            },        mimicBlur : function(e, t){        if(!this.wrap.contains(t) && this.validateBlur()){            this.triggerBlur();        }    },        triggerBlur : function(){        this.mimicing = false;        Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur);        if(this.monitorTab){            this.el.un("keydown", this.checkTab, this);        }        Ext.form.TriggerField.superclass.onBlur.call(this);    },            validateBlur : function(e, t){        return true;    },        disableWrapper : function(){        if(this.wrap){            this.wrap.addClass('x-item-disabled');        }    },        enableWrapper : function(){        if(this.wrap){            this.wrap.removeClass('x-item-disabled');        }    },        onShow : function(){        if(this.wrap){            this.wrap.dom.style.display = '';            this.wrap.dom.style.visibility = 'visible';        }    },        onHide : function(){        this.wrap.dom.style.display = 'none';    },        onTriggerClick : Ext.emptyFn});Ext.form.TextArea = function(config){    Ext.form.TextArea.superclass.constructor.call(this, config);                if(this.minHeight !== undefined){        this.growMin = this.minHeight;    }    if(this.maxHeight !== undefined){        this.growMax = this.maxHeight;    }};Ext.extend(Ext.form.TextArea, Ext.form.TextField,  {        growMin : 60,        growMax: 1000,        preventScrollbars: false,        onRender : function(ct, position){        if(!this.el){            this.defaultAutoCreate = {                tag: "textarea",                style:"width:300px;height:60px;",                autocomplete: "off"            };        }        Ext.form.TextArea.superclass.onRender.call(this, ct, position);        if(this.grow){            this.textSizeEl = Ext.DomHelper.append(document.body, {                tag: "pre", cls: "x-form-grow-sizer"            });            if(this.preventScrollbars){                this.el.setStyle("overflow", "hidden");            }            this.el.setHeight(this.growMin);        }    },        onKeyUp : function(e){        if(!e.isNavKeyPress() || e.getKey() == e.ENTER){            this.autoSize();        }    },        autoSize : function(){        if(!this.grow || !this.textSizeEl){            return;        }        var el = this.el;        var v = el.dom.value;        var ts = this.textSizeEl;        Ext.fly(ts).setWidth(this.el.getWidth());        if(v.length < 1){            v = "&#160;&#160;";        }else{            v += "&#160;\n&#160;";        }        if(Ext.isIE){            v = v.replace(/\n/g, '<br />');        }        ts.innerHTML = v;        var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));        if(h != this.lastHeight){            this.lastHeight = h;            this.el.setHeight(h);            this.fireEvent("autosize", this, h);        }    },        setValue : function(v){        Ext.form.TextArea.superclass.setValue.call(this, v);        this.autoSize();    }});Ext.form.NumberField = function(config){    Ext.form.NumberField.superclass.constructor.call(this, config);};Ext.extend(Ext.form.NumberField, Ext.form.TextField,  {        fieldClass: "x-form-field x-form-num-field",        allowDecimals : true,        decimalSeparator : ".",        decimalPrecision : 2,        allowNegative : true,        minValue : Number.NEGATIVE_INFINITY,        maxValue : Number.MAX_VALUE,        minText : "The minimum value for this field is {0}",        maxText : "The maximum value for this field is {0}",        nanText : "{0} is not a valid number",        initEvents : function(){        Ext.form.NumberField.superclass.initEvents.call(this);        var allowed = "0123456789";        if(this.allowDecimals){            allowed += this.decimalSeparator;        }        if(this.allowNegative){            allowed += "-";        }        var keyPress = function(e){            var k = e.getKey();            if(!Ext.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){                return;            }            var c = e.getCharCode();            if(allowed.indexOf(String.fromCharCode(c)) === -1){                e.stopEvent();            }        };        this.el.on("keypress", keyPress, this);    },        validateValue : function(value){        if(!Ext.form.NumberField.superclass.validateValue.call(this, value)){            return false;        }        if(value.length < 1){              return true;        }        value = String(value).replace(this.decimalSeparator, ".");        if(isNaN(value)){            this.markInvalid(String.format(this.nanText, value));            return false;        }        var num = this.parseValue(value);        if(num < this.minValue){            this.markInvalid(String.format(this.minText, this.minValue));            return false;        }        if(num > this.maxValue){            this.markInvalid(String.format(this.maxText, this.maxValue));            return false;        }        return true;    },        parseValue : function(value){        return parseFloat(String(value).replace(this.decimalSeparator, "."));    },        fixPrecision : function(value){       if(!this.allowDecimals || this.decimalPrecision == -1 || isNaN(value) || value == 0 || !value){           return value;       }                                                 var scale = Math.pow(10, this.decimalPrecision+1);       var fixed = this.decimalPrecisionFcn(value * scale);       fixed = this.decimalPrecisionFcn(fixed/10);       return fixed / (scale/10);    },        decimalPrecisionFcn : function(v){        return Math.floor(v);    }});Ext.form.DateField = function(config){    Ext.form.DateField.superclass.constructor.call(this, config);    if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);    if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);    this.ddMatch = null;    if(this.disabledDates){        var dd = this.disabledDates;        var re = "(?:";        for(var i = 0; i < dd.length; i++){            re += dd[i];            if(i != dd.length-1) re += "|";        }        this.ddMatch = new RegExp(re + ")");    }};Ext.extend(Ext.form.DateField, Ext.form.TriggerField,  {        format : "m/d/y",        disabledDays : null,        disabledDaysText : "Disabled",        disabledDates : null,        disabledDatesText : "Disabled",        minValue : null,        maxValue : null,        minText : "The date in this field must be after {0}",        maxText : "The date in this field must be before {0}",        invalidText : "{0} is not a valid date - it must be in the format {1}",        triggerClass : 'x-form-date-trigger',            defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},        validateValue : function(value){        value = this.formatDate(value);        if(!Ext.form.DateField.superclass.validateValue.call(this, value)){            return false;        }        if(value.length < 1){              return true;        }        var svalue = value;        value = this.parseDate(value);        if(!value){            this.markInvalid(String.format(this.invalidText, svalue, this.format));            return false;        }        var time = value.getTime();        if(this.minValue && time < this.minValue.getTime()){            this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));            return false;        }        if(this.maxValue && time > this.maxValue.getTime()){            this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));            return false;        }        if(this.disabledDays){            var day = value.getDay();            for(var i = 0; i < this.disabledDays.length; i++) {            	if(day === this.disabledDays[i]){            	    this.markInvalid(this.disabledDaysText);                    return false;            	}            }        }        var fvalue = this.formatDate(value);        if(this.ddMatch && this.ddMatch.test(fvalue)){            this.markInvalid(String.format(this.disabledDatesText, fvalue));            return false;        }        return true;    },            validateBlur : function(){        return !this.menu || !this.menu.isVisible();    },

⌨️ 快捷键说明

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