3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.ComponentMgr"></div>/**
15 * @class Ext.ComponentMgr
16 * <p>Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
17 * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
18 * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).</p>
19 * <p>This object also provides a registry of available Component <i>classes</i>
20 * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
21 * The <code>{@link Ext.Component#xtype xtype}</code> provides a way to avoid instantiating child Components
22 * when creating a full, nested config object for a complete Ext page.</p>
23 * <p>A child Component may be specified simply as a <i>config object</i>
24 * as long as the correct <code>{@link Ext.Component#xtype xtype}</code> is specified so that if and when the Component
25 * needs rendering, the correct type can be looked up for lazy instantiation.</p>
26 * <p>For a list of all available <code>{@link Ext.Component#xtype xtypes}</code>, see {@link Ext.Component}.</p>
29 Ext.ComponentMgr = function(){
30 var all = new Ext.util.MixedCollection();
35 <div id="method-Ext.ComponentMgr-register"></div>/**
36 * Registers a component.
37 * @param {Ext.Component} c The component
39 register : function(c){
43 <div id="method-Ext.ComponentMgr-unregister"></div>/**
44 * Unregisters a component.
45 * @param {Ext.Component} c The component
47 unregister : function(c){
51 <div id="method-Ext.ComponentMgr-get"></div>/**
52 * Returns a component by {@link Ext.Component#id id}.
53 * For additional details see {@link Ext.util.MixedCollection#get}.
54 * @param {String} id The component {@link Ext.Component#id id}
55 * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
62 <div id="method-Ext.ComponentMgr-onAvailable"></div>/**
63 * Registers a function that will be called when a specified component is added to ComponentMgr
64 * @param {String} id The component {@link Ext.Component#id id}
65 * @param {Function} fn The callback function
66 * @param {Object} scope The scope of the callback
68 onAvailable : function(id, fn, scope){
69 all.on("add", function(index, o){
71 fn.call(scope || o, o);
72 all.un("add", fn, scope);
77 <div id="prop-Ext.ComponentMgr-all"></div>/**
78 * The MixedCollection used internally for the component cache. An example usage may be subscribing to
79 * events on the MixedCollection to monitor addition or removal. Read-only.
80 * @type {MixedCollection}
84 <div id="method-Ext.ComponentMgr-isRegistered"></div>/**
85 * Checks if a Component type is registered.
86 * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
87 * @return {Boolean} Whether the type is registered.
89 isRegistered : function(xtype){
90 return types[xtype] !== undefined;
93 <div id="method-Ext.ComponentMgr-registerType"></div>/**
94 * <p>Registers a new Component constructor, keyed by a new
95 * {@link Ext.Component#xtype}.</p>
96 * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
97 * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
99 * see {@link Ext.Container#items}</p>
100 * @param {String} xtype The mnemonic string by which the Component class may be looked up.
101 * @param {Constructor} cls The new Component class.
103 registerType : function(xtype, cls){
108 <div id="method-Ext.ComponentMgr-create"></div>/**
109 * Creates a new Component from the specified config object using the
110 * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
111 * @param {Object} config A configuration object for the Component you wish to create.
112 * @param {Constructor} defaultType The constructor to provide the default Component type if
113 * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
114 * @return {Ext.Component} The newly instantiated Component.
116 create : function(config, defaultType){
117 return config.render ? config : new types[config.xtype || defaultType](config);
120 <div id="method-Ext.ComponentMgr-registerPlugin"></div>/**
121 * <p>Registers a new Plugin constructor, keyed by a new
122 * {@link Ext.Component#ptype}.</p>
123 * <p>Use this method (or its alias {@link Ext#preg Ext.preg}) to register new
124 * plugins for {@link Ext.Component}s so that lazy instantiation may be used when specifying
126 * @param {String} ptype The mnemonic string by which the Plugin class may be looked up.
127 * @param {Constructor} cls The new Plugin class.
129 registerPlugin : function(ptype, cls){
134 <div id="method-Ext.ComponentMgr-createPlugin"></div>/**
135 * Creates a new Plugin from the specified config object using the
136 * config object's {@link Ext.component#ptype ptype} to determine the class to instantiate.
137 * @param {Object} config A configuration object for the Plugin you wish to create.
138 * @param {Constructor} defaultType The constructor to provide the default Plugin type if
139 * the config object does not contain a <code>ptype</code>. (Optional if the config contains a <code>ptype</code>).
140 * @return {Ext.Component} The newly instantiated Plugin.
142 createPlugin : function(config, defaultType){
143 return new ptypes[config.ptype || defaultType](config);
148 <div id="method-Ext-reg"></div>/**
149 * Shorthand for {@link Ext.ComponentMgr#registerType}
150 * @param {String} xtype The {@link Ext.component#xtype mnemonic string} by which the Component class
152 * @param {Constructor} cls The new Component class.
156 Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down
157 <div id="method-Ext-preg"></div>/**
158 * Shorthand for {@link Ext.ComponentMgr#registerPlugin}
159 * @param {String} ptype The {@link Ext.component#ptype mnemonic string} by which the Plugin class
161 * @param {Constructor} cls The new Plugin class.
165 Ext.preg = Ext.ComponentMgr.registerPlugin;
166 <div id="method-Ext-create"></div>/**
167 * Shorthand for {@link Ext.ComponentMgr#create}
168 * Creates a new Component from the specified config object using the
169 * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
170 * @param {Object} config A configuration object for the Component you wish to create.
171 * @param {Constructor} defaultType The constructor to provide the default Component type if
172 * the config object does not contain a <code>xtype</code>. (Optional if the config contains a <code>xtype</code>).
173 * @return {Ext.Component} The newly instantiated Component.
177 Ext.create = Ext.ComponentMgr.create;</pre>