📄 component.js
字号:
/*
* Ext JS Library 2.0 Beta 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/** * @class Ext.Component * @extends Ext.util.Observable * <p>Base class for all Ext components. All subclasses of Component can automatically participate in the standard * Ext component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Ext.Container} and * to be automatically registered with the {@link Ext.ComponentMgr} so that it can be referenced at any time via * {@link Ext#getCmp}. All visual widgets that require rendering into a layout should subclass Component (or * {@link Ext.BoxComponent} if managed box model handling is required).</p> * <p>Every component has a specific xtype, which is its Ext-specific type name, along with methods for checking the * xtype like {@link #getXType} and {@link #isXType}. This is the list of all valid xtypes:</p> * <pre>xtype Class------------- ------------------box Ext.BoxComponentbutton Ext.Buttoncolorpalette Ext.ColorPalettecomponent Ext.Componentcontainer Ext.Containercycle Ext.CycleButtondataview Ext.DataViewdatepicker Ext.DatePickereditor Ext.Editoreditorgrid Ext.grid.EditorGridPanelgrid Ext.grid.GridPanelpaging Ext.PagingToolbarpanel Ext.Panelprogress Ext.ProgressBarsplitbutton Ext.SplitButtontabpanel Ext.TabPaneltreepanel Ext.tree.TreePanelviewport Ext.ViewPortwindow Ext.WindowToolbar components---------------------------------------toolbar Ext.Toolbartbitem Ext.Toolbar.Itemtbseparator Ext.Toolbar.Separatortbspacer Ext.Toolbar.Spacertbfill Ext.Toolbar.Filltbtext Ext.Toolbar.TextItemtbbutton Ext.Toolbar.Buttontbsplit Ext.Toolbar.SplitButtonForm components---------------------------------------checkbox Ext.form.Checkboxcombo Ext.form.ComboBoxdatefield Ext.form.DateFieldfield Ext.form.Fieldfieldset Ext.form.FieldSetform Ext.FormPanelhidden Ext.form.Hiddenhtmleditor Ext.form.HtmlEditornumberfield Ext.form.NumberFieldradio Ext.form.Radiotextarea Ext.form.TextAreatextfield Ext.form.TextFieldtimefield Ext.form.TimeFieldtrigger Ext.form.TriggerField</pre> * @constructor * @param {Ext.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal * element and its id used as the component id. If a string is passed, it is assumed to be the id of an existing element * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component. */Ext.Component = function(config){ config = config || {}; if(config.initialConfig){ if(config.isAction){ // actions this.baseAction = config; } config = config.initialConfig; // component cloning / action set up }else if(config.tagName || config.dom || typeof config == "string"){ // element object config = {applyTo: config, id: config.id || config}; } this.initialConfig = config; Ext.apply(this, config); this.addEvents({ /** * @event disable * Fires after the component is disabled. * @param {Ext.Component} this */ disable : true, /** * @event enable * Fires after the component is enabled. * @param {Ext.Component} this */ enable : true, /** * @event beforeshow * Fires before the component is shown. Return false to stop the show. * @param {Ext.Component} this */ beforeshow : true, /** * @event show * Fires after the component is shown. * @param {Ext.Component} this */ show : true, /** * @event beforehide * Fires before the component is hidden. Return false to stop the hide. * @param {Ext.Component} this */ beforehide : true, /** * @event hide * Fires after the component is hidden. * @param {Ext.Component} this */ hide : true, /** * @event beforerender * Fires before the component is rendered. Return false to stop the render. * @param {Ext.Component} this */ beforerender : true, /** * @event render * Fires after the component is rendered. * @param {Ext.Component} this */ render : true, /** * @event beforedestroy * Fires before the component is destroyed. Return false to stop the destroy. * @param {Ext.Component} this */ beforedestroy : true, /** * @event destroy * Fires after the component is destroyed. * @param {Ext.Component} this */ destroy : true }); this.getId(); Ext.ComponentMgr.register(this); Ext.Component.superclass.constructor.call(this); if(this.baseAction){ this.baseAction.addComponent(this); } this.initComponent(); if(this.stateful !== false){ this.initState(config); } if(this.plugins){ if(this.plugins instanceof Array){ for(var i = 0, len = this.plugins.length; i < len; i++){ this.plugins[i].init(this); } }else{ this.plugins.init(this); } } if(this.applyTo){ this.applyToMarkup(this.applyTo); delete this.applyTo; }else if(this.renderTo){ this.render(this.renderTo); delete this.renderTo; }};// privateExt.Component.AUTO_ID = 1000;Ext.extend(Ext.Component, Ext.util.Observable, { /** * @cfg {String} id * The unique id of this component (defaults to an auto-assigned id). */ /** * @cfg {String} cls * An optional extra CSS class that will be added to this component's Element (defaults to ''). This can be * useful for adding customized styles to the component or any of its children using standard CSS rules. */ /** * @cfg {String} style * A custom style specification to be applied to this component's Element. Should be a valid argument to * {@link Ext.Element#applyStyles}. */ /** * @cfg {String} ctCls * An optional extra CSS class that will be added to this component's container (defaults to ''). This can be * useful for adding customized styles to the container or any of its children using standard CSS rules. */ /** * @cfg {Object/Array} plugins * An object or array of objects that will provide custom functionality for this component. The only * requirement for a valid plugin is that it contain an init method that accepts a reference of type Ext.Component. * When a component is created, if any plugins are available, the component will call the init method on each * plugin, passing a reference to itself. Each plugin can then call methods or respond to events on the * component as needed to provide its functionality. */ /** * @cfg {Mixed} applyTo * The id of the node, a DOM node or an existing Element corresponding to a DIV that is already present in * the document that specifies some structural markup for this component. When applyTo is used, constituent parts of * the component can also be specified by id or CSS class name within the main element, and the component being created * may attempt to create its subcomponents from that markup if applicable. Using this config, a call to render() is * not required. If applyTo is specified, any value passed for {@link #renderTo} will be ignored and the target * element's parent node will automatically be used as the component's container. */ /** * @cfg {Mixed} renderTo * The id of the node, a DOM node or an existing Element that will be the container to render this component into. * Using this config, a call to render() is not required. */ /* //internal - to be set by subclasses * @cfg {String} stateId * The unique id for this component to use for state management purposes (defaults to the component id). */ /* //internal - to be set by subclasses * @cfg {Array} stateEvents * An array of events that, when fired, should trigger this component to save its state (defaults to none). * These can be any types of events supported by this component, including browser or custom events (e.g., * ['click', 'customerchange']). */ /** * @cfg {String} disabledClass * CSS class added to the component when it is disabled (defaults to "x-item-disabled"). */ disabledClass : "x-item-disabled", /** * @cfg {Boolean} allowDomMove * Whether the component can move the Dom node when rendering (defaults to true). */ allowDomMove : true, /** * @cfg {Boolean} autoShow * True if the component should check for hidden classes (e.g. 'x-hidden' or 'x-hide-display') and remove * them on render (defaults to false). */ autoShow : false, /** * @cfg {String} hideMode * How this component should hidden. Supported values are "visibility" (css visibility), "offsets" (negative * offset position) and "display" (css display) - defaults to "display". */ hideMode: 'display', /** * @cfg {Boolean} hideParent * True to hide and show the component's container when hide/show is called on the component, false to hide * and show the component itself (defaults to false). For example, this can be used as a shortcut for a hide * button on a window by setting hide:true on the button when adding it to its parent container. */ hideParent: false, /** * The component's owner {@link Ext.Container} (defaults to undefined, and is set automatically when * the component is added to a container). Read-only. * @type Ext.Container * @property ownerCt */ /** * True if this component is hidden. Read-only. * @type Boolean * @property */ hidden : false, /** * True if this component is disabled. Read-only. * @type Boolean * @property */ disabled : false, /** * True if this component has been rendered. Read-only. * @type Boolean * @property */ rendered : false, // private ctype : "Ext.Component", // private actionMode : "el", // private getActionEl : function(){ return this[this.actionMode]; }, /* // protected * Function to be implemented by Component subclasses to be part of standard component initialization flow (it is empty by default). * <pre><code>// Traditional constructor:Ext.Foo = function(config){ // call superclass constructor: Ext.Foo.superclass.constructor.call(this, config); this.addEvents({ // add events });};Ext.extend(Ext.Foo, Ext.Bar, { // class body}// initComponent replaces the constructor:Ext.Foo = Ext.extend(Ext.Bar, { initComponent : function(){ // call superclass initComponent Ext.Container.superclass.initComponent.call(this); this.addEvents({ // add events }); }}</code></pre> */ initComponent : Ext.emptyFn, /** * If this is a lazy rendering component, render it to its container element. * @param {Mixed} container (optional) The element this component should be rendered into. If it is being * applied to existing markup, this should be left off. * @param {String/Number} position (optional) The element ID or DOM node index within the container <b>before</b> * which this component will be inserted (defaults to appending to the end of the container) */ render : function(container, position){ if(!this.rendered && this.fireEvent("beforerender", this) !== false){ if(!container && this.el){ this.el = Ext.get(this.el); container = this.el.dom.parentNode; this.allowDomMove = false; } this.container = Ext.get(container); if(this.ctCls){ this.container.addClass(this.ctCls); } this.rendered = true; if(position !== undefined){ if(typeof position == 'number'){ position = this.container.dom.childNodes[position]; }else{ position = Ext.getDom(position); } } this.onRender(this.container, position || null); if(this.autoShow){ this.el.removeClass(['x-hidden','x-hide-' + this.hideMode]); } if(this.cls){ this.el.addClass(this.cls); delete this.cls; } if(this.style){ this.el.applyStyles(this.style); delete this.style; } this.fireEvent("render", this); this.afterRender(this.container); if(this.hidden){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -