2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.ComponentMgr
\r
11 * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
\r
12 * thereof) on a page so that they can be easily accessed by component id (see {@link #get}, or
\r
13 * the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
\r
14 * <p>This object also provides a registry of available Component <i>classes</i>
\r
15 * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
\r
16 * The <tt>xtype</tt> provides a way to avoid instantiating child Components
\r
17 * when creating a full, nested config object for a complete Ext page.</p>
\r
18 * <p>A child Component may be specified simply as a <i>config object</i>
\r
19 * as long as the correct xtype is specified so that if and when the Component
\r
20 * needs rendering, the correct type can be looked up for lazy instantiation.</p>
\r
21 * <p>For a list of all available xtypes, see {@link Ext.Component}.</p>
\r
24 Ext.ComponentMgr = function(){
\r
25 var all = new Ext.util.MixedCollection();
\r
30 * Registers a component.
\r
31 * @param {Ext.Component} c The component
\r
33 register : function(c){
\r
38 * Unregisters a component.
\r
39 * @param {Ext.Component} c The component
\r
41 unregister : function(c){
\r
46 * Returns a component by id
\r
47 * @param {String} id The component id
\r
48 * @return Ext.Component
\r
55 * Registers a function that will be called when a specified component is added to ComponentMgr
\r
56 * @param {String} id The component id
\r
57 * @param {Function} fn The callback function
\r
58 * @param {Object} scope The scope of the callback
\r
60 onAvailable : function(id, fn, scope){
\r
61 all.on("add", function(index, o){
\r
63 fn.call(scope || o, o);
\r
64 all.un("add", fn, scope);
\r
70 * The MixedCollection used internally for the component cache. An example usage may be subscribing to
\r
71 * events on the MixedCollection to monitor addition or removal. Read-only.
\r
72 * @type {MixedCollection}
\r
77 * <p>Registers a new Component constructor, keyed by a new
\r
78 * {@link Ext.Component#xtype}.</p>
\r
79 * <p>Use this method to register new subclasses of {@link Ext.Component} so
\r
80 * that lazy instantiation may be used when specifying child Components.
\r
81 * see {@link Ext.Container#items}</p>
\r
82 * @param {String} xtype The mnemonic string by which the Component class
\r
84 * @param {Constructor} cls The new Component class.
\r
86 registerType : function(xtype, cls){
\r
92 * Creates a new Component from the specified config object using the
\r
93 * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
\r
94 * @param config {Object} A configuration object for the Component you wish to create.
\r
95 * @param defaultType {Constructor} The constructor to provide the default Component type if
\r
96 * the config object does not contain an xtype. (Optional if the config contains an xtype).
\r
97 * @return {Ext.Component} The newly instantiated Component.
\r
99 create : function(config, defaultType){
\r
100 return new types[config.xtype || defaultType](config);
\r
106 * Shorthand for {@link Ext.ComponentMgr#registerType}
\r
107 * @param {String} xtype The mnemonic string by which the Component class
\r
108 * may be looked up.
\r
109 * @param {Constructor} cls The new Component class.
\r
113 Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down