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

📄 triggerfield.js

📁 EXT2.0的中文API源代码
💻 JS
字号:
/** * @class Ext.form.TriggerField * @extends Ext.form.TextField * 为添加了带有可触发事件的按钮的TextFields(文本域)提供一个方便的封装(很像一个默认combobox)。 * 触发器没有默认行为(action),因此你必须通过重写方法{@link #onTriggerClick}的方式,指派一个方法实现触发器的点击事件处理。 * 你可以直接创建一个TriggerField(触发域),由于它会呈现与combobox相像的效果,你可以通过它提供一种自定义的实现。例如: * <pre><code>var trigger = new Ext.form.TriggerField();trigger.onTriggerClick = myTriggerFn;trigger.applyTo('my-field');</code></pre> * * 然而,你可能会更倾向于将TriggerField作为一个可复用容器的基类。 * {@link Ext.form.DateField}和{@link Ext.form.ComboBox}就是两个较好的样板. * @cfg {String} triggerClass  配置项triggerClass(字符串)是一个附加的CSS类,用于为触发器按钮设置样式。 * 配置项triggerClass(触发器样式)如果被指定则会被<b>附加</b>,否则默认为“x-form-trigger” * @constructor * 创建一个新TriggerField的对象。 * @param {Object} config 配置选择(对于有效的{@Ext.form.TextField}配置项也会被传入到TextField) *//** * @class Ext.form.TriggerField * @extends Ext.form.TextField * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default). * The trigger has no default action, so you must assign a function to implement the trigger click handler by * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox * for which you can provide a custom implementation.  For example: * <pre><code>var trigger = new Ext.form.TriggerField();trigger.onTriggerClick = myTriggerFn;trigger.applyTo('my-field');</code></pre> * * However, in general you will most likely want to use TriggerField as the base class for a reusable component. * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this. * @cfg {String} triggerClass An additional CSS class used to style the trigger button.  The trigger will always get the * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified. * @constructor * Create a new TriggerField. * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied * to the base TextField) */Ext.form.TriggerField = function(config){    this.mimicing = false;    Ext.form.TriggerField.superclass.constructor.call(this, config);};Ext.extend(Ext.form.TriggerField, Ext.form.TextField,  {    /**     * @cfg {String} triggerClass 应用到触发器身上的CSS样式类     */    /**     * @cfg {String} triggerClass A CSS class to apply to the trigger     */    /**     * @cfg {String/Object} autoCreate  一个DomHelper创建元素的对象,或者为true,表示采用默认的方式创建元素。(默认为     * {tag: "input", type: "text", size: "16", autocomplete: "off"})     */    /**     * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to     * {tag: "input", type: "text", size: "16", autocomplete: "off"})     */    defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},    /**     * @cfg {Boolean} hideTrigger 为true时隐藏触发元素,只显示基本文本域(默认为false)。     */    /**     * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)     */    hideTrigger:false,    /** @cfg {Boolean} grow @hide */    /** @cfg {Number} growMin @hide */    /** @cfg {Number} growMax @hide */    /**     * @hide      * @method autoSize     */    autoSize: Ext.emptyFn,    // private    monitorTab : true,    // private    deferHeight : true,    // private    onResize : function(w, h){        Ext.form.TriggerField.superclass.onResize.apply(this, arguments);        if(typeof w == 'number'){            this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth()));        }    },    // private    adjustSize : Ext.BoxComponent.prototype.adjustSize,    // private    getResizeEl : function(){        return this.wrap;    },    // private    getPositionEl : function(){        return this.wrap;    },    // private    alignErrorIcon : function(){        this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);    },    // private    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(this.triggerConfig ||                {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});        if(this.hideTrigger){            this.trigger.setDisplayed(false);        }        this.initTrigger();        if(!this.width){            this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());        }    },    // private    initTrigger : function(){        this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});        this.trigger.addClassOnOver('x-form-trigger-over');        this.trigger.addClassOnClick('x-form-trigger-click');    },    // private    onDestroy : function(){        if(this.trigger){            this.trigger.removeAllListeners();            this.trigger.remove();        }        if(this.wrap){            this.wrap.remove();        }        Ext.form.TriggerField.superclass.onDestroy.call(this);    },    // private    onFocus : function(){        Ext.form.TriggerField.superclass.onFocus.call(this);        if(!this.mimicing){            this.wrap.addClass('x-trigger-wrap-focus');            this.mimicing = true;            Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {delay: 10});            if(this.monitorTab){                this.el.on("keydown", this.checkTab, this);            }        }    },    // private    checkTab : function(e){        if(e.getKey() == e.TAB){            this.triggerBlur();        }    },    // private    onBlur : function(){        // do nothing    },    // private    mimicBlur : function(e){        if(!this.wrap.contains(e.target) && this.validateBlur(e)){            this.triggerBlur();        }    },    // private    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);        }        this.beforeBlur();        this.wrap.removeClass('x-trigger-wrap-focus');        Ext.form.TriggerField.superclass.onBlur.call(this);    },    beforeBlur : Ext.emptyFn,     // private    // This should be overriden by any subclass that needs to check whether or not the field can be blurred.    validateBlur : function(e){        return true;    },    // private    onDisable : function(){        Ext.form.TriggerField.superclass.onDisable.call(this);        if(this.wrap){            this.wrap.addClass('x-item-disabled');        }    },    // private    onEnable : function(){        Ext.form.TriggerField.superclass.onEnable.call(this);        if(this.wrap){            this.wrap.removeClass('x-item-disabled');        }    },    // private    onShow : function(){        if(this.wrap){            this.wrap.dom.style.display = '';            this.wrap.dom.style.visibility = 'visible';        }    },    // private    onHide : function(){        this.wrap.dom.style.display = 'none';    },    /**     * 该方法应该用于处理触发器的click事件。默认为空方法,要被某个实现的方法重写后才会有效。     * @method     * @param {EventObject} e 参数e是({EventObject}类型)     */    /**     * The function that should handle the trigger's click event.  This method does nothing by default until overridden     * by an implementing function.     * @method     * @param {EventObject} e     */    onTriggerClick : Ext.emptyFn});// TwinTriggerField is not a public class to be used directly.  It is meant as an abstract base class// to be extended by an implementing class.  For an example of implementing this class, see the custom// SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.htmlExt.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {    initComponent : function(){        Ext.form.TwinTriggerField.superclass.initComponent.call(this);        this.triggerConfig = {            tag:'span', cls:'x-form-twin-triggers', cn:[            {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},            {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}        ]};    },    getTrigger : function(index){        return this.triggers[index];    },    initTrigger : function(){        var ts = this.trigger.select('.x-form-trigger', true);        this.wrap.setStyle('overflow', 'hidden');        var triggerField = this;        ts.each(function(t, all, index){            t.hide = function(){                var w = triggerField.wrap.getWidth();                this.dom.style.display = 'none';                triggerField.el.setWidth(w-triggerField.trigger.getWidth());            };            t.show = function(){                var w = triggerField.wrap.getWidth();                this.dom.style.display = '';                triggerField.el.setWidth(w-triggerField.trigger.getWidth());            };            var triggerIndex = 'Trigger'+(index+1);            if(this['hide'+triggerIndex]){                t.dom.style.display = 'none';            }            t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});            t.addClassOnOver('x-form-trigger-over');            t.addClassOnClick('x-form-trigger-click');        }, this);        this.triggers = ts.elements;    },    onTrigger1Click : Ext.emptyFn,    onTrigger2Click : Ext.emptyFn});Ext.reg('trigger', Ext.form.TriggerField);

⌨️ 快捷键说明

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