📄 component.js
字号:
/*
* Ext JS Library 2.3.0
* Copyright(c) 2006-2009, 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 may participate in the automated * Ext component lifecycle of creation, rendering and destruction which is provided by the {@link Ext.Container Container} class. * Components may be added to a Container through the {@link Ext.Container#items items} config option at the time the Container is created, * or they may be added dynamically via the {@link Ext.Container#add add} method.</p> * <p>The Component base class has built-in support for basic hide/show and enable/disable behavior.</p> * <p>All Components are registered with the {@link Ext.ComponentMgr} on construction so that they can be referenced at any time via * {@link Ext#getCmp}, passing the {@link #id}.</p> * <p>All user-developed visual widgets that are required to participate in automated lifecycle and size management should subclass Component (or * {@link Ext.BoxComponent} if managed box model handling is required, ie height and width management).</p> * <p>See the <a href="http://extjs.com/learn/Tutorial:Creating_new_UI_controls">Creating new UI controls</a> tutorial for details on how * and to either extend or augment ExtJs base classes to create custom Components.</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.ProgressBarpropertygrid Ext.grid.PropertyGridslider Ext.Slidersplitbutton Ext.SplitButtonstatusbar Ext.StatusBartabpanel Ext.TabPaneltreepanel Ext.tree.TreePanelviewport Ext.Viewportwindow Ext.WindowToolbar components---------------------------------------toolbar Ext.Toolbartbbutton Ext.Toolbar.Buttontbfill Ext.Toolbar.Filltbitem Ext.Toolbar.Itemtbseparator Ext.Toolbar.Separatortbspacer Ext.Toolbar.Spacertbsplit Ext.Toolbar.SplitButtontbtext Ext.Toolbar.TextItemForm components---------------------------------------form Ext.FormPanelcheckbox Ext.form.Checkboxcombo Ext.form.ComboBoxdatefield Ext.form.DateFieldfield Ext.form.Fieldfieldset Ext.form.FieldSethidden Ext.form.Hiddenhtmleditor Ext.form.HtmlEditorlabel Ext.form.Labelnumberfield 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 Component's initial configuration specification. Read-only. * @type Object * @property initialConfig */ this.initialConfig = config; Ext.apply(this, config); this.addEvents( /** * @event disable * Fires after the component is disabled. * @param {Ext.Component} this */ 'disable', /** * @event enable * Fires after the component is enabled. * @param {Ext.Component} this */ 'enable', /** * @event beforeshow * Fires before the component is shown. Return false to stop the show. * @param {Ext.Component} this */ 'beforeshow', /** * @event show * Fires after the component is shown. * @param {Ext.Component} this */ 'show', /** * @event beforehide * Fires before the component is hidden. Return false to stop the hide. * @param {Ext.Component} this */ 'beforehide', /** * @event hide * Fires after the component is hidden. * @param {Ext.Component} this */ 'hide', /** * @event beforerender * Fires before the component is rendered. Return false to stop the render. * @param {Ext.Component} this */ 'beforerender', /** * @event render * Fires after the component is rendered. * @param {Ext.Component} this */ 'render', /** * @event beforedestroy * Fires before the component is destroyed. Return false to stop the destroy. * @param {Ext.Component} this */ 'beforedestroy', /** * @event destroy * Fires after the component is destroyed. * @param {Ext.Component} this */ 'destroy', /** * @event beforestaterestore * Fires before the state of the component is restored. Return false to stop the restore. * @param {Ext.Component} this * @param {Object} state The hash of state values */ 'beforestaterestore', /** * @event staterestore * Fires after the state of the component is restored. * @param {Ext.Component} this * @param {Object} state The hash of state values */ 'staterestore', /** * @event beforestatesave * Fires before the state of the component is saved to the configured state provider. Return false to stop the save. * @param {Ext.Component} this * @param {Object} state The hash of state values */ 'beforestatesave', /** * @event statesave * Fires after the state of the component is saved to the configured state provider. * @param {Ext.Component} this * @param {Object} state The hash of state values */ 'statesave' ); this.getId(); Ext.ComponentMgr.register(this); Ext.Component.superclass.constructor.call(this); if(this.baseAction){ this.baseAction.addComponent(this); } this.initComponent(); if(this.plugins){ if(Ext.isArray(this.plugins)){ for(var i = 0, len = this.plugins.length; i < len; i++){ this.plugins[i] = this.initPlugin(this.plugins[i]); } }else{ this.plugins = this.initPlugin(this.plugins); } } if(this.stateful !== false){ this.initState(config); } 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, { // Configs below are used for all Components when rendered by FormLayout. /** * @cfg {String} fieldLabel The label text to display next to this Component (defaults to '') * <p><b>This config is only used when this Component is rendered by a Container which has been * configured to use the {@link Ext.form.FormLayout FormLayout} layout manager.</b></p> * Example use:<pre><code>new Ext.FormPanel({ height: 100, renderTo: Ext.getBody(), items: [{ xtype: 'textfield', fieldLabel: 'Name' }]});</code></pre> */ /** * @cfg {String} labelStyle A CSS style specification to apply directly to this field's label (defaults to the * container's labelStyle value if set, or '').<code></code>. * <p><b>This config is only used when this Component is rendered by a Container which has been * configured to use the {@link Ext.form.FormLayout FormLayout} layout manager.</b></p> * Example use:<pre><code>new Ext.FormPanel({ height: 100, renderTo: Ext.getBody(), items: [{ xtype: 'textfield', fieldLabel: 'Name', labelStyle: 'font-weight:bold;' }]});</code></pre> */ /** * @cfg {String} labelSeparator The standard separator to display after the text of each form label (defaults * to the value of {@link Ext.layout.FormLayout#labelSeparator}, which is a colon ':' by default). To display * no separator for this field's label specify empty string ''. * <p><b>This config is only used when this Component is rendered by a Container which has been * configured to use the {@link Ext.form.FormLayout FormLayout} layout manager.</b></p> * Example use:<pre><code>new Ext.FormPanel({ height: 100, renderTo: Ext.getBody(), items: [{ xtype: 'textfield', fieldLabel: 'Name', labelSeparator: '...' }]});</code></pre> */ /** * @cfg {Boolean} hideLabel True to completely hide the label element (defaults to false). By default, even if * you do not specify a {@link fieldLabel} the space will still be reserved so that the field will line up with * other fields that do have labels. Setting this to true will cause the field to not reserve that space. * <p><b>This config is only used when this Component is rendered by a Container which has been * configured to use the {@link Ext.form.FormLayout FormLayout} layout manager.</b></p> * Example use:<pre><code>new Ext.FormPanel({ height: 100, renderTo: Ext.getBody(), items: [{ xtype: 'textfield' hideLabel: true }]});</code></pre> */ /** * @cfg {String} clearCls The CSS class used to provide field clearing (defaults to 'x-form-clear-left'). * <p><b>This config is only used when this Component is rendered by a Container which has been * configured to use the {@link Ext.form.FormLayout FormLayout} layout manager.</b></p> */ /** * @cfg {String} itemCls An additional CSS class to apply to the wrapper's form item element of this field (defaults * to the container's itemCls value if set, or ''). Since it is applied to the item wrapper, it allows you to write * standard CSS rules that can apply to the field, the label (if specified) or any other element within the markup for * the field. * <p><b>This config is only used when this Component is rendered by a Container which has been * configured to use the {@link Ext.form.FormLayout FormLayout} layout manager.</b></p> * Example use:<pre><code>// Apply a style to the field's label:<style> .required .x-form-item-label {font-weight:bold;color:red;}</style>new Ext.FormPanel({ height: 100, renderTo: Ext.getBody(), items: [{ xtype: 'textfield', fieldLabel: 'Name', itemCls: 'required' //this label will be styled },{ xtype: 'textfield', fieldLabel: 'Favorite Color' }]});</code></pre> */ /** * @cfg {String} id * The unique id of this component (defaults to an auto-assigned id). You should assign an id if you need to * be able to access the component later and you do not have an object reference available (e.g., using * {@link Ext.ComponentMgr#getCmp}). Note that this id will also be used as the element id for the containing * HTML element that is rendered to the page for this component. This allows you to write id-based CSS rules to * style the specific instance of this component uniquely, and also to select sub-elements using this * component's id as the parent. */ /** * @cfg {Mixed} autoEl * <p>A tag name or {@link Ext.DomHelper DomHelper} spec used to create the {@link #getEl Element} which will * encapsulate this Component.</p> * <p>You only need to specify this when creating or subclassing the base classes {@link Ext.Component}, {@link Ext.BoxComponent}, * and {@link Ext.Container}. The more complex Ext classes use a more complex DOM structure created by their own * onRender methods.</p> * <p>This is intended to allow the developer to create application-specific utility Components encapsulated by * different DOM elements. Example usage:</p><pre><code>{ xtype: 'box', autoEl: { tag: 'img', src: 'http://www.example.com/example.jpg' }}, { xtype: 'box', autoEl: { tag: 'blockquote', html: 'autoEl is cool!' }}, { xtype: 'container', autoEl: 'ul', cls: 'ux-unordered-list', items: { xtype: 'box', autoEl: 'li', html: 'First list item' }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -