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

📄 tabpanel.js

📁 当前比较流行的,漂亮的JS框架,这里面用到的API文档
💻 JS
📖 第 1 页 / 共 3 页
字号:
        if(!item || this.fireEvent('beforetabchange', this, item, this.activeTab) === false){            return;        }        if(!this.rendered){            this.activeTab = item;            return;        }        if(this.activeTab != item){            if(this.activeTab){                var oldEl = this.getTabEl(this.activeTab);                if(oldEl){                    Ext.fly(oldEl).removeClass('x-tab-strip-active');                }                this.activeTab.fireEvent('deactivate', this.activeTab);            }            var el = this.getTabEl(item);            Ext.fly(el).addClass('x-tab-strip-active');            this.activeTab = item;            this.stack.add(item);            this.layout.setActiveItem(item);            if(this.layoutOnTabChange && item.doLayout){                item.doLayout();            }            if(this.scrolling){                this.scrollToTab(item, this.animScroll);            }            item.fireEvent('activate', item);            this.fireEvent('tabchange', this, item);        }    },    /**     * Gets the currently active tab.     * @return {Panel} The active tab     */    getActiveTab : function(){        return this.activeTab || null;    },    /**     * Gets the specified tab by id.     * @param {String} id The tab id     * @return {Panel} The tab     */    getItem : function(item){        return this.getComponent(item);    },    // private    autoScrollTabs : function(){        var count = this.items.length;        var ow = this.header.dom.offsetWidth;        var tw = this.header.dom.clientWidth;        var wrap = this.stripWrap;        var wd = wrap.dom;        var cw = wd.offsetWidth;        var pos = this.getScrollPos();        var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;        if(!this.enableTabScroll || count < 1 || cw < 20){ // 20 to prevent display:none issues            return;        }        if(l <= tw){            wd.scrollLeft = 0;            wrap.setWidth(tw);            if(this.scrolling){                this.scrolling = false;                this.header.removeClass('x-tab-scrolling');                this.scrollLeft.hide();                this.scrollRight.hide();                if(Ext.isAir){                    wd.style.marginLeft = '';                    wd.style.marginRight = '';                }            }        }else{            if(!this.scrolling){                this.header.addClass('x-tab-scrolling');                if(Ext.isAir){                    wd.style.marginLeft = '18px';                    wd.style.marginRight = '18px';                }            }            tw -= wrap.getMargins('lr');            wrap.setWidth(tw > 20 ? tw : 20);            if(!this.scrolling){                if(!this.scrollLeft){                    this.createScrollers();                }else{                    this.scrollLeft.show();                    this.scrollRight.show();                }            }            this.scrolling = true;            if(pos > (l-tw)){ // ensure it stays within bounds                wd.scrollLeft = l-tw;            }else{ // otherwise, make sure the active tab is still visible                this.scrollToTab(this.activeTab, false);            }            this.updateScrollButtons();        }    },    // private    createScrollers : function(){        var h = this.stripWrap.dom.offsetHeight;        // left        var sl = this.header.insertFirst({            cls:'x-tab-scroller-left'        });        sl.setHeight(h);        sl.addClassOnOver('x-tab-scroller-left-over');        this.leftRepeater = new Ext.util.ClickRepeater(sl, {            interval : this.scrollRepeatInterval,            handler: this.onScrollLeft,            scope: this        });        this.scrollLeft = sl;        // right        var sr = this.header.insertFirst({            cls:'x-tab-scroller-right'        });        sr.setHeight(h);        sr.addClassOnOver('x-tab-scroller-right-over');        this.rightRepeater = new Ext.util.ClickRepeater(sr, {            interval : this.scrollRepeatInterval,            handler: this.onScrollRight,            scope: this        });        this.scrollRight = sr;    },    // private    getScrollWidth : function(){        return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();    },    // private    getScrollPos : function(){        return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;    },    // private    getScrollArea : function(){        return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;    },    // private    getScrollAnim : function(){        return {duration:this.scrollDuration, callback: this.updateScrollButtons, scope: this};    },    // private    getScrollIncrement : function(){        return this.scrollIncrement || (this.resizeTabs ? this.lastTabWidth+2 : 100);    },    /**     * Scrolls to a particular tab if tab scrolling is enabled     * @param {Panel} item The item to scroll to     * @param {Boolean} animate True to enable animations     */    scrollToTab : function(item, animate){        if(!item){ return; }        var el = this.getTabEl(item);        var pos = this.getScrollPos(), area = this.getScrollArea();        var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos;        var right = left + el.offsetWidth;        if(left < pos){            this.scrollTo(left, animate);        }else if(right > (pos + area)){            this.scrollTo(right - area, animate);        }    },    // private    scrollTo : function(pos, animate){        this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);        if(!animate){            this.updateScrollButtons();        }    },    onWheel : function(e){        var d = e.getWheelDelta()*this.wheelIncrement*-1;        e.stopEvent();        var pos = this.getScrollPos();        var newpos = pos + d;        var sw = this.getScrollWidth()-this.getScrollArea();        var s = Math.max(0, Math.min(sw, newpos));        if(s != pos){            this.scrollTo(s, false);        }    },    // private    onScrollRight : function(){        var sw = this.getScrollWidth()-this.getScrollArea();        var pos = this.getScrollPos();        var s = Math.min(sw, pos + this.getScrollIncrement());        if(s != pos){            this.scrollTo(s, this.animScroll);        }    },    // private    onScrollLeft : function(){        var pos = this.getScrollPos();        var s = Math.max(0, pos - this.getScrollIncrement());        if(s != pos){            this.scrollTo(s, this.animScroll);        }    },    // private    updateScrollButtons : function(){        var pos = this.getScrollPos();        this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('x-tab-scroller-left-disabled');        this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('x-tab-scroller-right-disabled');    }    /**     * @cfg {Boolean} collapsible     * @hide     */    /**     * @cfg {String} header     * @hide     */    /**     * @cfg {Boolean} headerAsText     * @hide     */    /**     * @property header     * @hide     */    /**     * @property title     * @hide     */    /**     * @cfg {Array} tools     * @hide     */    /**     * @cfg {Boolean} hideCollapseTool     * @hide     */    /**     * @cfg {Boolean} titleCollapse     * @hide     */    /**     * @cfg {Boolean} collapsed     * @hide     */});Ext.reg('tabpanel', Ext.TabPanel);/** * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which * can return false to cancel the tab change. * @param {String/Panel} tab The id or tab Panel to activate * @method activate */Ext.TabPanel.prototype.activate = Ext.TabPanel.prototype.setActiveTab;// private utility class used by TabPanelExt.TabPanel.AccessStack = function(){    var items = [];    return {        add : function(item){            items.push(item);            if(items.length > 10){                items.shift();            }        },        remove : function(item){            var s = [];            for(var i = 0, len = items.length; i < len; i++) {                if(items[i] != item){                    s.push(items[i]);                }            }            items = s;        },        next : function(){            return items.pop();        }    };};

⌨️ 快捷键说明

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