PageRenderTime 29ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/ext-4.1.0_b3/src/PluginManager.js

https://bitbucket.org/srogerf/javascript
JavaScript | 108 lines | 31 code | 7 blank | 70 comment | 10 complexity | 7622923229caf1fa8d47de8c2207efe9 MD5 | raw file
  1. /**
  2. * @singleton
  3. *
  4. * Provides a registry of available Plugin classes indexed by a mnemonic code known as the Plugin's ptype.
  5. *
  6. * A plugin may be specified simply as a *config object* as long as the correct `ptype` is specified:
  7. *
  8. * {
  9. * ptype: 'gridviewdragdrop',
  10. * dragText: 'Drag and drop to reorganize'
  11. * }
  12. *
  13. * Or just use the ptype on its own:
  14. *
  15. * 'gridviewdragdrop'
  16. *
  17. * Alternatively you can instantiate the plugin with Ext.create:
  18. *
  19. * Ext.create('Ext.view.plugin.AutoComplete', {
  20. * ptype: 'gridviewdragdrop',
  21. * dragText: 'Drag and drop to reorganize'
  22. * })
  23. */
  24. Ext.define('Ext.PluginManager', {
  25. extend: 'Ext.AbstractManager',
  26. alternateClassName: 'Ext.PluginMgr',
  27. singleton: true,
  28. typeName: 'ptype',
  29. /**
  30. * Creates a new Plugin from the specified config object using the config object's ptype to determine the class to
  31. * instantiate.
  32. * @param {Object} config A configuration object for the Plugin you wish to create.
  33. * @param {Function} defaultType (optional) The constructor to provide the default Plugin type if the config object does not
  34. * contain a `ptype`. (Optional if the config contains a `ptype`).
  35. * @return {Ext.Component} The newly instantiated Plugin.
  36. */
  37. //create: function(plugin, defaultType) {
  38. // if (plugin instanceof this) {
  39. // return plugin;
  40. // } else {
  41. // var type, config = {};
  42. //
  43. // if (Ext.isString(plugin)) {
  44. // type = plugin;
  45. // }
  46. // else {
  47. // type = plugin[this.typeName] || defaultType;
  48. // config = plugin;
  49. // }
  50. //
  51. // return Ext.createByAlias('plugin.' + type, config);
  52. // }
  53. //},
  54. create : function(config, defaultType){
  55. if (config.init) {
  56. return config;
  57. } else {
  58. return Ext.createByAlias('plugin.' + (config.ptype || defaultType), config);
  59. }
  60. // Prior system supported Singleton plugins.
  61. //var PluginCls = this.types[config.ptype || defaultType];
  62. //if (PluginCls.init) {
  63. // return PluginCls;
  64. //} else {
  65. // return new PluginCls(config);
  66. //}
  67. },
  68. /**
  69. * Returns all plugins registered with the given type. Here, 'type' refers to the type of plugin, not its ptype.
  70. * @param {String} type The type to search for
  71. * @param {Boolean} defaultsOnly True to only return plugins of this type where the plugin's isDefault property is
  72. * truthy
  73. * @return {Ext.AbstractPlugin[]} All matching plugins
  74. */
  75. findByType: function(type, defaultsOnly) {
  76. var matches = [],
  77. types = this.types;
  78. for (var name in types) {
  79. if (!types.hasOwnProperty(name)) {
  80. continue;
  81. }
  82. var item = types[name];
  83. if (item.type == type && (!defaultsOnly || (defaultsOnly === true && item.isDefault))) {
  84. matches.push(item);
  85. }
  86. }
  87. return matches;
  88. }
  89. }, function() {
  90. /**
  91. * Shorthand for {@link Ext.PluginManager#registerType}
  92. * @param {String} ptype The ptype mnemonic string by which the Plugin class
  93. * may be looked up.
  94. * @param {Function} cls The new Plugin class.
  95. * @member Ext
  96. * @method preg
  97. */
  98. Ext.preg = function() {
  99. return Ext.PluginManager.registerType.apply(Ext.PluginManager, arguments);
  100. };
  101. });