You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
9.9 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ComponentMgr'>/**
  19. </span> * @class Ext.ComponentMgr
  20. * &lt;p&gt;Provides a registry of all Components (instances of {@link Ext.Component} or any subclass
  21. * thereof) on a page so that they can be easily accessed by {@link Ext.Component component}
  22. * {@link Ext.Component#id id} (see {@link #get}, or the convenience method {@link Ext#getCmp Ext.getCmp}).&lt;/p&gt;
  23. * &lt;p&gt;This object also provides a registry of available Component &lt;i&gt;classes&lt;/i&gt;
  24. * indexed by a mnemonic code known as the Component's {@link Ext.Component#xtype xtype}.
  25. * The &lt;code&gt;{@link Ext.Component#xtype xtype}&lt;/code&gt; provides a way to avoid instantiating child Components
  26. * when creating a full, nested config object for a complete Ext page.&lt;/p&gt;
  27. * &lt;p&gt;A child Component may be specified simply as a &lt;i&gt;config object&lt;/i&gt;
  28. * as long as the correct &lt;code&gt;{@link Ext.Component#xtype xtype}&lt;/code&gt; is specified so that if and when the Component
  29. * needs rendering, the correct type can be looked up for lazy instantiation.&lt;/p&gt;
  30. * &lt;p&gt;For a list of all available &lt;code&gt;{@link Ext.Component#xtype xtypes}&lt;/code&gt;, see {@link Ext.Component}.&lt;/p&gt;
  31. * @singleton
  32. */
  33. Ext.ComponentMgr = function(){
  34. var all = new Ext.util.MixedCollection();
  35. var types = {};
  36. var ptypes = {};
  37. return {
  38. <span id='Ext-ComponentMgr-method-register'> /**
  39. </span> * Registers a component.
  40. * @param {Ext.Component} c The component
  41. */
  42. register : function(c){
  43. all.add(c);
  44. },
  45. <span id='Ext-ComponentMgr-method-unregister'> /**
  46. </span> * Unregisters a component.
  47. * @param {Ext.Component} c The component
  48. */
  49. unregister : function(c){
  50. all.remove(c);
  51. },
  52. <span id='Ext-ComponentMgr-method-get'> /**
  53. </span> * Returns a component by {@link Ext.Component#id id}.
  54. * For additional details see {@link Ext.util.MixedCollection#get}.
  55. * @param {String} id The component {@link Ext.Component#id id}
  56. * @return Ext.Component The Component, &lt;code&gt;undefined&lt;/code&gt; if not found, or &lt;code&gt;null&lt;/code&gt; if a
  57. * Class was found.
  58. */
  59. get : function(id){
  60. return all.get(id);
  61. },
  62. <span id='Ext-ComponentMgr-method-onAvailable'> /**
  63. </span> * Registers a function that will be called when a Component with the specified id is added to ComponentMgr. This will happen on instantiation.
  64. * @param {String} id The component {@link Ext.Component#id id}
  65. * @param {Function} fn The callback function
  66. * @param {Object} scope The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the callback is executed. Defaults to the Component.
  67. */
  68. onAvailable : function(id, fn, scope){
  69. all.on(&quot;add&quot;, function(index, o){
  70. if(o.id == id){
  71. fn.call(scope || o, o);
  72. all.un(&quot;add&quot;, fn, scope);
  73. }
  74. });
  75. },
  76. <span id='Ext-ComponentMgr-property-all'> /**
  77. </span> * The MixedCollection used internally for the component cache. An example usage may be subscribing to
  78. * events on the MixedCollection to monitor addition or removal. Read-only.
  79. * @type {MixedCollection}
  80. */
  81. all : all,
  82. <span id='Ext-ComponentMgr-property-types'> /**
  83. </span> * The xtypes that have been registered with the component manager.
  84. * @type {Object}
  85. */
  86. types : types,
  87. <span id='Ext-ComponentMgr-property-ptypes'> /**
  88. </span> * The ptypes that have been registered with the component manager.
  89. * @type {Object}
  90. */
  91. ptypes: ptypes,
  92. <span id='Ext-ComponentMgr-method-isRegistered'> /**
  93. </span> * Checks if a Component type is registered.
  94. * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
  95. * @return {Boolean} Whether the type is registered.
  96. */
  97. isRegistered : function(xtype){
  98. return types[xtype] !== undefined;
  99. },
  100. <span id='Ext-ComponentMgr-method-isPluginRegistered'> /**
  101. </span> * Checks if a Plugin type is registered.
  102. * @param {Ext.Component} ptype The mnemonic string by which the Plugin class may be looked up
  103. * @return {Boolean} Whether the type is registered.
  104. */
  105. isPluginRegistered : function(ptype){
  106. return ptypes[ptype] !== undefined;
  107. },
  108. <span id='Ext-ComponentMgr-method-registerType'> /**
  109. </span> * &lt;p&gt;Registers a new Component constructor, keyed by a new
  110. * {@link Ext.Component#xtype}.&lt;/p&gt;
  111. * &lt;p&gt;Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
  112. * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
  113. * child Components.
  114. * see {@link Ext.Container#items}&lt;/p&gt;
  115. * @param {String} xtype The mnemonic string by which the Component class may be looked up.
  116. * @param {Constructor} cls The new Component class.
  117. */
  118. registerType : function(xtype, cls){
  119. types[xtype] = cls;
  120. cls.xtype = xtype;
  121. },
  122. <span id='Ext-ComponentMgr-method-create'> /**
  123. </span> * Creates a new Component from the specified config object using the
  124. * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
  125. * @param {Object} config A configuration object for the Component you wish to create.
  126. * @param {Constructor} defaultType The constructor to provide the default Component type if
  127. * the config object does not contain a &lt;code&gt;xtype&lt;/code&gt;. (Optional if the config contains a &lt;code&gt;xtype&lt;/code&gt;).
  128. * @return {Ext.Component} The newly instantiated Component.
  129. */
  130. create : function(config, defaultType){
  131. return config.render ? config : new types[config.xtype || defaultType](config);
  132. },
  133. <span id='Ext-ComponentMgr-method-registerPlugin'> /**
  134. </span> * &lt;p&gt;Registers a new Plugin constructor, keyed by a new
  135. * {@link Ext.Component#ptype}.&lt;/p&gt;
  136. * &lt;p&gt;Use this method (or its alias {@link Ext#preg Ext.preg}) to register new
  137. * plugins for {@link Ext.Component}s so that lazy instantiation may be used when specifying
  138. * Plugins.&lt;/p&gt;
  139. * @param {String} ptype The mnemonic string by which the Plugin class may be looked up.
  140. * @param {Constructor} cls The new Plugin class.
  141. */
  142. registerPlugin : function(ptype, cls){
  143. ptypes[ptype] = cls;
  144. cls.ptype = ptype;
  145. },
  146. <span id='Ext-ComponentMgr-method-createPlugin'> /**
  147. </span> * Creates a new Plugin from the specified config object using the
  148. * config object's {@link Ext.component#ptype ptype} to determine the class to instantiate.
  149. * @param {Object} config A configuration object for the Plugin you wish to create.
  150. * @param {Constructor} defaultType The constructor to provide the default Plugin type if
  151. * the config object does not contain a &lt;code&gt;ptype&lt;/code&gt;. (Optional if the config contains a &lt;code&gt;ptype&lt;/code&gt;).
  152. * @return {Ext.Component} The newly instantiated Plugin.
  153. */
  154. createPlugin : function(config, defaultType){
  155. var PluginCls = ptypes[config.ptype || defaultType];
  156. if (PluginCls.init) {
  157. return PluginCls;
  158. } else {
  159. return new PluginCls(config);
  160. }
  161. }
  162. };
  163. }();
  164. <span id='Ext-method-reg'>/**
  165. </span> * Shorthand for {@link Ext.ComponentMgr#registerType}
  166. * @param {String} xtype The {@link Ext.component#xtype mnemonic string} by which the Component class
  167. * may be looked up.
  168. * @param {Constructor} cls The new Component class.
  169. * @member Ext
  170. * @method reg
  171. */
  172. Ext.reg = Ext.ComponentMgr.registerType; // this will be called a lot internally, shorthand to keep the bytes down
  173. <span id='Ext-method-preg'>/**
  174. </span> * Shorthand for {@link Ext.ComponentMgr#registerPlugin}
  175. * @param {String} ptype The {@link Ext.component#ptype mnemonic string} by which the Plugin class
  176. * may be looked up.
  177. * @param {Constructor} cls The new Plugin class.
  178. * @member Ext
  179. * @method preg
  180. */
  181. Ext.preg = Ext.ComponentMgr.registerPlugin;
  182. <span id='Ext-method-create'>/**
  183. </span> * Shorthand for {@link Ext.ComponentMgr#create}
  184. * Creates a new Component from the specified config object using the
  185. * config object's {@link Ext.component#xtype xtype} to determine the class to instantiate.
  186. * @param {Object} config A configuration object for the Component you wish to create.
  187. * @param {Constructor} defaultType The constructor to provide the default Component type if
  188. * the config object does not contain a &lt;code&gt;xtype&lt;/code&gt;. (Optional if the config contains a &lt;code&gt;xtype&lt;/code&gt;).
  189. * @return {Ext.Component} The newly instantiated Component.
  190. * @member Ext
  191. * @method create
  192. */
  193. Ext.create = Ext.ComponentMgr.create;</pre>
  194. </body>
  195. </html>