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

📄 button.js

📁 当前比较流行的,漂亮的JS框架,这里面用到的API文档
💻 JS
📖 第 1 页 / 共 2 页
字号:
	            btn.removeAllListeners();	        }	    }        if(this.menu){            Ext.destroy(this.menu);        }    },    // private    onDestroy : function(){        if(this.rendered){            Ext.ButtonToggleMgr.unregister(this);        }    },    // private    autoWidth : function(){        if(this.el){            this.el.setWidth("auto");            if(Ext.isIE7 && Ext.isStrict){                var ib = this.el.child(this.buttonSelector);                if(ib && ib.getWidth() > 20){                    ib.clip();                    ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));                }            }            if(this.minWidth){                if(this.el.getWidth() < this.minWidth){                    this.el.setWidth(this.minWidth);                }            }        }    },    /**     * Assigns this button's click handler     * @param {Function} handler The function to call when the button is clicked     * @param {Object} scope (optional) Scope for the function passed in     */    setHandler : function(handler, scope){        this.handler = handler;        this.scope = scope;    },    /**     * Sets this button's text     * @param {String} text The button text     */    setText : function(text){        this.text = text;        if(this.el){            this.el.child("td.x-btn-center " + this.buttonSelector).update(text);        }        this.autoWidth();    },    /**     * Gets the text for this button     * @return {String} The button text     */    getText : function(){        return this.text;    },    /**     * If a state it passed, it becomes the pressed state otherwise the current state is toggled.     * @param {Boolean} state (optional) Force a particular state     */    toggle : function(state){        state = state === undefined ? !this.pressed : state;        if(state != this.pressed){            if(state){                this.el.addClass("x-btn-pressed");                this.pressed = true;                this.fireEvent("toggle", this, true);            }else{                this.el.removeClass("x-btn-pressed");                this.pressed = false;                this.fireEvent("toggle", this, false);            }            if(this.toggleHandler){                this.toggleHandler.call(this.scope || this, this, state);            }        }    },    /**     * Focus the button     */    focus : function(){        this.el.child(this.buttonSelector).focus();    },    // private    onDisable : function(){        if(this.el){            if(!Ext.isIE6 || !this.text){                this.el.addClass(this.disabledClass);            }            this.el.dom.disabled = true;        }        this.disabled = true;    },    // private    onEnable : function(){        if(this.el){            if(!Ext.isIE6 || !this.text){                this.el.removeClass(this.disabledClass);            }            this.el.dom.disabled = false;        }        this.disabled = false;    },    /**     * Show this button's menu (if it has one)     */    showMenu : function(){        if(this.menu){            this.menu.show(this.el, this.menuAlign);        }        return this;    },    /**     * Hide this button's menu (if it has one)     */    hideMenu : function(){        if(this.menu){            this.menu.hide();        }        return this;    },    /**     * Returns true if the button has a menu and it is visible     * @return {Boolean}     */    hasVisibleMenu : function(){        return this.menu && this.menu.isVisible();    },    // private    onClick : function(e){        if(e){            e.preventDefault();        }        if(e.button != 0){            return;        }        if(!this.disabled){            if(this.enableToggle && (this.allowDepress !== false || !this.pressed)){                this.toggle();            }            if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){                this.showMenu();            }            this.fireEvent("click", this, e);            if(this.handler){                //this.el.removeClass("x-btn-over");                this.handler.call(this.scope || this, this, e);            }        }    },    // private    isMenuTriggerOver : function(e, internal){        return this.menu && !internal;    },    // private    isMenuTriggerOut : function(e, internal){        return this.menu && !internal;    },    // private    onMouseOver : function(e){        if(!this.disabled){            var internal = e.within(this.el,  true);            if(!internal){                this.el.addClass("x-btn-over");                Ext.getDoc().on('mouseover', this.monitorMouseOver, this);                this.fireEvent('mouseover', this, e);            }            if(this.isMenuTriggerOver(e, internal)){                this.fireEvent('menutriggerover', this, this.menu, e);            }        }    },    // private    monitorMouseOver : function(e){        if(e.target != this.el.dom && !e.within(this.el)){            Ext.getDoc().un('mouseover', this.monitorMouseOver, this);            this.onMouseOut(e);        }    },    // private    onMouseOut : function(e){        var internal = e.within(this.el) && e.target != this.el.dom;        this.el.removeClass("x-btn-over");        this.fireEvent('mouseout', this, e);        if(this.isMenuTriggerOut(e, internal)){            this.fireEvent('menutriggerout', this, this.menu, e);        }    },    // private    onFocus : function(e){        if(!this.disabled){            this.el.addClass("x-btn-focus");        }    },    // private    onBlur : function(e){        this.el.removeClass("x-btn-focus");    },    // private    getClickEl : function(e, isUp){       return this.el;    },    // private    onMouseDown : function(e){        if(!this.disabled && e.button == 0){            this.getClickEl(e).addClass("x-btn-click");            Ext.getDoc().on('mouseup', this.onMouseUp, this);        }    },    // private    onMouseUp : function(e){        if(e.button == 0){            this.getClickEl(e, true).removeClass("x-btn-click");            Ext.getDoc().un('mouseup', this.onMouseUp, this);        }    },    // private    onMenuShow : function(e){        this.ignoreNextClick = 0;        this.el.addClass("x-btn-menu-active");        this.fireEvent('menushow', this, this.menu);    },    // private    onMenuHide : function(e){        this.el.removeClass("x-btn-menu-active");        this.ignoreNextClick = this.restoreClick.defer(250, this);        this.fireEvent('menuhide', this, this.menu);    },    // private    restoreClick : function(){        this.ignoreNextClick = 0;    }    /**     * @cfg {String} autoEl @hide     */});Ext.reg('button', Ext.Button);// Private utility class used by ButtonExt.ButtonToggleMgr = function(){   var groups = {};   function toggleGroup(btn, state){       if(state){           var g = groups[btn.toggleGroup];           for(var i = 0, l = g.length; i < l; i++){               if(g[i] != btn){                   g[i].toggle(false);               }           }       }   }   return {       register : function(btn){           if(!btn.toggleGroup){               return;           }           var g = groups[btn.toggleGroup];           if(!g){               g = groups[btn.toggleGroup] = [];           }           g.push(btn);           btn.on("toggle", toggleGroup);       },       unregister : function(btn){           if(!btn.toggleGroup){               return;           }           var g = groups[btn.toggleGroup];           if(g){               g.remove(btn);               btn.un("toggle", toggleGroup);           }       }   };}();

⌨️ 快捷键说明

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