PluginManager.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-PluginManager'>/**
  19. </span> * Provides a registry of available Plugin classes indexed by a mnemonic code known as the Plugin's ptype.
  20. *
  21. * A plugin may be specified simply as a *config object* as long as the correct `ptype` is specified:
  22. *
  23. * {
  24. * ptype: 'gridviewdragdrop',
  25. * dragText: 'Drag and drop to reorganize'
  26. * }
  27. *
  28. * Or just use the ptype on its own:
  29. *
  30. * 'gridviewdragdrop'
  31. *
  32. * Alternatively you can instantiate the plugin with Ext.create:
  33. *
  34. * Ext.create('Ext.grid.plugin.DragDrop', {
  35. * dragText: 'Drag and drop to reorganize'
  36. * })
  37. */
  38. Ext.define('Ext.PluginManager', {
  39. extend: 'Ext.AbstractManager',
  40. alternateClassName: 'Ext.PluginMgr',
  41. singleton: true,
  42. typeName: 'ptype',
  43. <span id='Ext-PluginManager-method-create'> /**
  44. </span> * Creates a new Plugin from the specified config object using the config object's ptype to determine the class to
  45. * instantiate.
  46. * @param {Object} config A configuration object for the Plugin you wish to create.
  47. * @param {Function} defaultType (optional) The constructor to provide the default Plugin type if the config object does not
  48. * contain a `ptype`. (Optional if the config contains a `ptype`).
  49. * @return {Ext.Component} The newly instantiated Plugin.
  50. */
  51. create : function(config, defaultType){
  52. if (config.init) {
  53. return config;
  54. } else {
  55. return Ext.createByAlias('plugin.' + (config.ptype || defaultType), config);
  56. }
  57. // Prior system supported Singleton plugins.
  58. //var PluginCls = this.types[config.ptype || defaultType];
  59. //if (PluginCls.init) {
  60. // return PluginCls;
  61. //} else {
  62. // return new PluginCls(config);
  63. //}
  64. },
  65. //create: function(plugin, defaultType) {
  66. // if (plugin instanceof this) {
  67. // return plugin;
  68. // } else {
  69. // var type, config = {};
  70. //
  71. // if (Ext.isString(plugin)) {
  72. // type = plugin;
  73. // }
  74. // else {
  75. // type = plugin[this.typeName] || defaultType;
  76. // config = plugin;
  77. // }
  78. //
  79. // return Ext.createByAlias('plugin.' + type, config);
  80. // }
  81. //},
  82. <span id='Ext-PluginManager-method-findByType'> /**
  83. </span> * Returns all plugins registered with the given type. Here, 'type' refers to the type of plugin, not its ptype.
  84. * @param {String} type The type to search for
  85. * @param {Boolean} defaultsOnly True to only return plugins of this type where the plugin's isDefault property is
  86. * truthy
  87. * @return {Ext.AbstractPlugin[]} All matching plugins
  88. */
  89. findByType: function(type, defaultsOnly) {
  90. var matches = [],
  91. types = this.types,
  92. name,
  93. item;
  94. for (name in types) {
  95. if (!types.hasOwnProperty(name)) {
  96. continue;
  97. }
  98. item = types[name];
  99. if (item.type == type &amp;&amp; (!defaultsOnly || (defaultsOnly === true &amp;&amp; item.isDefault))) {
  100. matches.push(item);
  101. }
  102. }
  103. return matches;
  104. }
  105. }, function() {
  106. <span id='Ext-method-preg'> /**
  107. </span> * Shorthand for {@link Ext.PluginManager#registerType}
  108. * @param {String} ptype The ptype mnemonic string by which the Plugin class
  109. * may be looked up.
  110. * @param {Function} cls The new Plugin class.
  111. * @member Ext
  112. * @method preg
  113. */
  114. Ext.preg = function() {
  115. return Ext.PluginManager.registerType.apply(Ext.PluginManager, arguments);
  116. };
  117. });
  118. </pre>
  119. </body>
  120. </html>