3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.ComponentMgr
9 * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
10 * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
11 * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
12 * <p>This object also provides a registry of available Component <i>classes</i>
13 * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
14 * The <code>{@link Ext.Component#xtype xtype}</code> provides a way to avoid instantiating child Components
15 * when creating a full, nested config object for a complete Ext page.</p>
16 * <p>A child Component may be specified simply as a <i>config object</i>
17 * as long as the correct <code>{@link Ext.Component#xtype xtype}</code> is specified so that if and when the Component
18 * needs rendering, the correct type can be looked up for lazy instantiation.</p>
19 * <p>For a list of all available <code>{@link Ext.Component#xtype xtypes}</code>, see {@link Ext.Component}.</p>
22 Ext.ComponentMgr = function(){
23 var all = new Ext.util.MixedCollection();
29 * Registers a component.
30 * @param {Ext.Component} c The component
32 register : function(c){
37 * Unregisters a component.
38 * @param {Ext.Component} c The component
40 unregister : function(c){
45 * Returns a component by {@link Ext.Component#id id}.
46 * For additional details see {@link Ext.util.MixedCollection#get}.
47 * @param {String} id The component {@link Ext.Component#id id}
48 * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
56 * Registers a function that will be called when a Component with the specified id is added to ComponentMgr. This will happen on instantiation.
57 * @param {String} id The component {@link Ext.Component#id id}
58 * @param {Function} fn The callback function
59 * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
61 onAvailable : function(id, fn, scope){
62 all.on("add", function(index, o){
64 fn.call(scope || o, o);
65 all.un("add", fn, scope);
71 * The MixedCollection used internally for the component cache. An example usage may be subscribing to
72 * events on the MixedCollection to monitor addition or removal. Read-only.
73 * @type {MixedCollection}
78 * Checks if a Component type is registered.
79 * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
80 * @return {Boolean} Whether the type is registered.
82 isRegistered : function(xtype){
83 return types[xtype] !== undefined;
87 * <p>Registers a new Component constructor, keyed by a new
88 * {@link Ext.Component#xtype}.</p>
89 * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
90 * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
92 * see {@link Ext.Container#items}</p>
93 * @param {String} xtype The mnemonic string by which the Component class may be looked up.
94 * @param {Constructor} cls The new Component class.
96 registerType : function(xtype, cls){
102 * Creates a new Component from the specified config object using the
103 * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
104 * @param {Object} config A configuration object for the Component you wish to create.
105 * @param {Constructor} defaultType The constructor to provide the default Component type if
106 * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
107 * @return {Ext.Component} The newly instantiated Component.
109 create : function(config, defaultType){
110 return config.render ? config : new types[config.xtype || defaultType](config);
114 * <p>Registers a new Plugin constructor, keyed by a new
115 * {@link Ext.Component#ptype}.</p>
116 * <p>Use this method (or its alias {@link Ext#preg Ext.preg}) to register new
117 * plugins for {@link Ext.Component}s so that lazy instantiation may be used when specifying
119 * @param {String} ptype The mnemonic string by which the Plugin class may be looked up.
120 * @param {Constructor} cls The new Plugin class.
122 registerPlugin : function(ptype, cls){
128 * Creates a new Plugin from the specified config object using the
129 * config object's {@link Ext.component#ptype ptype} to determine the class to instantiate.
130 * @param {Object} config A configuration object for the Plugin you wish to create.
131 * @param {Constructor} defaultType The constructor to provide the default Plugin type if
132 * the config object does not contain a <code>ptype</code>. (Optional if the config contains a <code>ptype</code>).
133 * @return {Ext.Component} The newly instantiated Plugin.
135 createPlugin : function(config, defaultType){
136 var PluginCls = ptypes[config.ptype || defaultType];
137 if (PluginCls.init) {
140 return new PluginCls(config);
147 * Shorthand for {@link Ext.ComponentMgr#registerType}
148 * @param {String} xtype The {@link Ext.component#xtype mnemonic string} by which the Component class
150 * @param {Constructor} cls The new Component class.
154 Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down
156 * Shorthand for {@link Ext.ComponentMgr#registerPlugin}
157 * @param {String} ptype The {@link Ext.component#ptype mnemonic string} by which the Plugin class
159 * @param {Constructor} cls The new Plugin class.
163 Ext.preg = Ext.ComponentMgr.registerPlugin;
165 * Shorthand for {@link Ext.ComponentMgr#create}
166 * Creates a new Component from the specified config object using the
167 * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
168 * @param {Object} config A configuration object for the Component you wish to create.
169 * @param {Constructor} defaultType The constructor to provide the default Component type if
170 * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
171 * @return {Ext.Component} The newly instantiated Component.
175 Ext.create = Ext.ComponentMgr.create;