ComponentManager.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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-ComponentManager'>/**
  19. </span> * @class Ext.ComponentManager
  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;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.define('Ext.ComponentManager', {
  34. extend: 'Ext.AbstractManager',
  35. alternateClassName: 'Ext.ComponentMgr',
  36. singleton: true,
  37. typeName: 'xtype',
  38. <span id='Ext-ComponentManager-method-create'> /**
  39. </span> * Creates a new Component from the specified config object using the
  40. * config object's xtype to determine the class to instantiate.
  41. * @param {Object} config A configuration object for the Component you wish to create.
  42. * @param {String} defaultType (optional) The xtype to use if the config object does not
  43. * contain a &lt;code&gt;xtype&lt;/code&gt;. (Optional if the config contains a &lt;code&gt;xtype&lt;/code&gt;).
  44. * @return {Ext.Component} The newly instantiated Component.
  45. */
  46. create: function(component, defaultType){
  47. if (typeof component == 'string') {
  48. return Ext.widget(component);
  49. }
  50. if (component.isComponent) {
  51. return component;
  52. }
  53. return Ext.widget(component.xtype || defaultType, component);
  54. },
  55. registerType: function(type, cls) {
  56. this.types[type] = cls;
  57. cls[this.typeName] = type;
  58. cls.prototype[this.typeName] = type;
  59. }
  60. });</pre>
  61. </body>
  62. </html>