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

📄 tabpanel.js

📁 ajax框架extjs是一套完整的富客户端解决方案
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.TabPanel * <p>A basic tab container. TabPanels can be used exactly like a standard {@link Ext.Panel} for layout * purposes, but also have special support for containing child Components that are managed using a CardLayout * layout manager, and displayed as seperate tabs.</p> * <p>There is no actual tab class &mdash; each tab is simply an {@link Ext.BoxComponent Component} such * as a {@link Ext.Panel Panel}. However, when rendered in a TabPanel, each child Component can fire * additional events that only exist for tabs and are not available from other Component. These are:</p> * <ul> * <li><b>activate</b>: Fires when this Component becomes the active tab. * <div class="mdetail-params"> *      <strong style="font-weight: normal;">Listeners will be called with the following arguments:</strong> *      <ul><li><code>tab</code> : Panel<div class="sub-desc">The tab that was activated</div></li></ul> *  </div></li> * <li><b>deactivate</b>: Fires when the Component that was the active tab becomes deactivated. * <div class="mdetail-params"> *      <strong style="font-weight: normal;">Listeners will be called with the following arguments:</strong> *      <ul><li><code>tab</code> : Panel<div class="sub-desc">The tab that was deactivated</div></li></ul> *  </div></li> * </ul> * <p>To add Components to a TabPanel which are generated dynamically on the server, it is necessary to * create a server script to generate the Javascript to create the Component required.</p> * For example, to add a GridPanel to a TabPanel where the GridPanel is generated by the server * based on certain parameters, you would need to execute an Ajax request to invoke your the script, * and process the response object to add it to the TabPanel:</p><pre><code>Ext.Ajax.request({    url: 'gen-invoice-grid.php',    params: {        startDate = Ext.getCmp('start-date').getValue(),        endDate = Ext.getCmp('end-date').getValue()    },    success: function(xhr) {        var newComponent = eval(xhr.responseText);        myTabPanel.add(newComponent);        myTabPanel.setActiveTab(newComponent);    },    failure: function() {    	Ext.Msg.alert("Grid create failed", "Server communication failure");    }});</code></pre> * <p>The server script would need to return an executable Javascript statement which, when processed * using <tt>eval()</tt> will return either a config object with an {@link Ext.Component#xtype xtype}, * or an instantiated Component. For example:</p><pre><code>{function() {    function formatDate(value){        return value ? value.dateFormat('M d, Y') : '';    };    var store = new Ext.data.Store({        url: 'get-invoice-data.php',        baseParams: {            startDate: '01/01/2008',            endDate: '01/31/2008'        }        reader: new Ext.data.JsonReader({            record: 'transaction',            id: 'id',            totalRecords: 'total'        }, [           'customer',           'invNo',           {name: 'date', type: 'date', dateFormat: 'm/d/Y'},           {name: 'value', type: 'float'}        ])    });    var grid = new Ext.grid.GridPanel({        title: 'Invoice Report',        bbar: new Ext.PagingToolbar(store),        store: store,        columns: [            {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},            {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},            {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},            {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}        ],    });    store.load();    return grid;})();</code></pre> * <p>Since that code is <i>generated</i> by a server script, the <tt>baseParams</tt> for the Store * can be configured into the Store. The metadata to allow generation of the Record layout, and the * ColumnModel is also known on the server, so these can be generated into the code.</p> * <p>When that code fragment is passed through the <tt>eval</tt> function in the success handler * of the Ajax request, the code is executed by the Javascript processor, and the anonymous function * runs, and returns the grid.</p> * <p>There are several other methods available for creating TabPanels. The output of the following * examples should produce exactly the same appearance. The tabs can be created and rendered completely * in code, as in this example:</p> * <pre><code>var tabs = new Ext.TabPanel({    renderTo: Ext.getBody(),    activeTab: 0,    items: [{        title: 'Tab 1',        html: 'A simple tab'    },{        title: 'Tab 2',        html: 'Another one'    }]});</code></pre>  * <p>TabPanels can also be rendered from pre-existing markup in a couple of ways.  See the {@link #autoTabs} example for  * rendering entirely from markup that is already structured correctly as a TabPanel (a container div with  * one or more nested tab divs with class 'x-tab'). You can also render from markup that is not strictly  * structured by simply specifying by id which elements should be the container and the tabs. Using this method,  * tab content can be pulled from different elements within the page by id regardless of page structure.  Note  * that the tab divs in this example contain the class 'x-hide-display' so that they can be rendered deferred  * without displaying outside the tabs. You could alternately set {@link #deferredRender} to false to render all  * content tabs on page load. For example:  * <pre><code>var tabs = new Ext.TabPanel({    renderTo: 'my-tabs',    activeTab: 0,    items:[        {contentEl:'tab1', title:'Tab 1'},        {contentEl:'tab2', title:'Tab 2'}    ]});// Note that the tabs do not have to be nested within the container (although they can be)&lt;div id="my-tabs">&lt;/div>&lt;div id="tab1" class="x-hide-display">A simple tab&lt;/div>&lt;div id="tab2" class="x-hide-display">Another one&lt;/div></code></pre> * @extends Ext.Panel * @constructor * @param {Object} config The configuration options */Ext.TabPanel = Ext.extend(Ext.Panel,  {    /**     * @cfg {Boolean} layoutOnTabChange Set to true to do a layout of tab items as tabs are changed.     */    /**     * @cfg {Boolean} monitorResize True to automatically monitor window resize events and rerender the layout on     * browser resize (defaults to true).     */    monitorResize : true,    /**     * @cfg {Boolean} deferredRender Internally, the TabPanel uses a {@link Ext.layout.CardLayout} to manage its tabs.     * This property will be passed on to the layout as its {@link Ext.layout.CardLayout#deferredRender} config value,     * determining whether or not each tab is rendered only when first accessed (defaults to true).     */    deferredRender : true,    /**     * @cfg {Number} tabWidth The initial width in pixels of each new tab (defaults to 120).     */    tabWidth: 120,    /**     * @cfg {Number} minTabWidth The minimum width in pixels for each tab when {@link #resizeTabs} = true (defaults to 30).     */    minTabWidth: 30,    /**     * @cfg {Boolean} resizeTabs True to automatically resize each tab so that the tabs will completely fill the     * tab strip (defaults to false).  Setting this to true may cause specific widths that might be set per tab to     * be overridden in order to fit them all into view (although {@link #minTabWidth} will always be honored).     */    resizeTabs:false,    /**     * @cfg {Boolean} enableTabScroll True to enable scrolling to tabs that may be invisible due to overflowing the     * overall TabPanel width. Only available with tabPosition:'top' (defaults to false).     */    enableTabScroll: false,    /**     * @cfg {Number} scrollIncrement The number of pixels to scroll each time a tab scroll button is pressed (defaults     * to 100, or if {@link #resizeTabs} = true, the calculated tab width).  Only applies when {@link #enableTabScroll} = true.     */    scrollIncrement : 0,    /**     * @cfg {Number} scrollRepeatInterval Number of milliseconds between each scroll while a tab scroll button is     * continuously pressed (defaults to 400).     */    scrollRepeatInterval : 400,    /**     * @cfg {Float} scrollDuration The number of milliseconds that each scroll animation should last (defaults to .35).     * Only applies when {@link #animScroll} = true.     */    scrollDuration : .35,    /**     * @cfg {Boolean} animScroll True to animate tab scrolling so that hidden tabs slide smoothly into view (defaults     * to true).  Only applies when {@link #enableTabScroll} = true.     */    animScroll : true,    /**     * @cfg {String} tabPosition The position where the tab strip should be rendered (defaults to 'top').  The only     * other supported value is 'bottom'.  Note that tab scrolling is only supported for position 'top'.     */    tabPosition: 'top',    /**     * @cfg {String} baseCls The base CSS class applied to the panel (defaults to 'x-tab-panel').     */    baseCls: 'x-tab-panel',    /**     * @cfg {Boolean} autoTabs     * <p>True to query the DOM for any divs with a class of 'x-tab' to be automatically converted     * to tabs and added to this panel (defaults to false).  Note that the query will be executed within the scope of     * the container element only (so that multiple tab panels from markup can be supported via this method).</p>     * <p>This method is only possible when the markup is structured correctly as a container with nested     * divs containing the class 'x-tab'. To create TabPanels without these limitations, or to pull tab content from     * other elements on the page, see the example at the top of the class for generating tabs from markup.</p>     * <p>There are a couple of things to note when using this method:<ul>     * <li>When using the autoTabs config (as opposed to passing individual tab configs in the TabPanel's     * {@link #items} collection), you must use {@link #applyTo} to correctly use the specified id as the tab container.     * The autoTabs method <em>replaces</em> existing content with the TabPanel components.</li>     * <li>Make sure that you set {@link #deferredRender} to false so that the content elements for each tab will be     * rendered into the TabPanel immediately upon page load, otherwise they will not be transformed until each tab     * is activated and will be visible outside the TabPanel.</li>     * </ul>Example usage:</p>     * <pre><code>var tabs = new Ext.TabPanel({    applyTo: 'my-tabs',    activeTab: 0,    deferredRender: false,    autoTabs: true});// This markup will be converted to a TabPanel from the code above&lt;div id="my-tabs">    &lt;div class="x-tab" title="Tab 1">A simple tab&lt;/div>    &lt;div class="x-tab" title="Tab 2">Another one&lt;/div>&lt;/div></code></pre>     */    autoTabs : false,    /**     * @cfg {String} autoTabSelector The CSS selector used to search for tabs in existing markup when {@link #autoTabs}     * = true (defaults to 'div.x-tab').  This can be any valid selector supported by {@link Ext.DomQuery#select}.     * Note that the query will be executed within the scope of this tab panel only (so that multiple tab panels from     * markup can be supported on a page).     */    autoTabSelector:'div.x-tab',    /**     * @cfg {String/Number} activeTab A string id or the numeric index of the tab that should be initially     * activated on render (defaults to none).     */    activeTab : null,    /**     * @cfg {Number} tabMargin The number of pixels of space to calculate into the sizing and scrolling of tabs. If you     * change the margin in CSS, you will need to update this value so calculations are correct with either resizeTabs     * or scrolling tabs. (defaults to 2)     */    tabMargin : 2,    /**     * @cfg {Boolean} plain True to render the tab strip without a background container image (defaults to false).     */    plain: false,    /**     * @cfg {Number} wheelIncrement For scrolling tabs, the number of pixels to increment on mouse wheel scrolling (defaults to 20).     */    wheelIncrement : 20,    /*     * This is a protected property used when concatenating tab ids to the TabPanel id for internal uniqueness.     * It does not generally need to be changed, but can be if external code also uses an id scheme that can     * potentially clash with this one.     */    idDelimiter : '__',    // private    itemCls : 'x-tab-item',    // private config overrides    elements: 'body',    headerAsText: false,    frame: false,    hideBorders:true,    // private    initComponent : function(){        this.frame = false;        Ext.TabPanel.superclass.initComponent.call(this);        this.addEvents(            /**             * @event beforetabchange             * Fires before the active tab changes. Handlers can return false to cancel the tab change.             * @param {TabPanel} this             * @param {Panel} newTab The tab being activated             * @param {Panel} currentTab The current active tab             */            'beforetabchange',            /**             * @event tabchange             * Fires after the active tab has changed.             * @param {TabPanel} this             * @param {Panel} tab The new active tab             */            'tabchange',            /**             * @event contextmenu             * Fires when the original browser contextmenu event originated from a tab element.             * @param {TabPanel} this             * @param {Panel} tab The target tab             * @param {EventObject} e             */            'contextmenu'        );        this.setLayout(new Ext.layout.CardLayout({            deferredRender: this.deferredRender        }));        if(this.tabPosition == 'top'){            this.elements += ',header';            this.stripTarget = 'header';        }else {            this.elements += ',footer';            this.stripTarget = 'footer';        }        if(!this.stack){            this.stack = Ext.TabPanel.AccessStack();        }        this.initItems();    },    // private    render : function(){        Ext.TabPanel.superclass.render.apply(this, arguments);        if(this.activeTab !== undefined){            var item = this.activeTab;            delete this.activeTab;            this.setActiveTab(item);        }    },

⌨️ 快捷键说明

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