]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * Creates plugin instances.\r | |
3 | *\r | |
4 | * A plugin may be specified simply as a *config object* as long as the correct `ptype` is specified:\r | |
5 | *\r | |
6 | * {\r | |
7 | * ptype: 'gridviewdragdrop',\r | |
8 | * dragText: 'Drag and drop to reorganize'\r | |
9 | * }\r | |
10 | *\r | |
11 | * Or just use the ptype on its own:\r | |
12 | *\r | |
13 | * 'gridviewdragdrop'\r | |
14 | *\r | |
15 | * Alternatively you can instantiate the plugin with Ext.create:\r | |
16 | *\r | |
17 | * Ext.create('Ext.grid.plugin.DragDrop', {\r | |
18 | * dragText: 'Drag and drop to reorganize'\r | |
19 | * })\r | |
20 | * @private\r | |
21 | */\r | |
22 | Ext.define('Ext.plugin.Manager', {\r | |
23 | alternateClassName: [\r | |
24 | 'Ext.PluginManager',\r | |
25 | 'Ext.PluginMgr'\r | |
26 | ],\r | |
27 | \r | |
28 | singleton: true,\r | |
29 | typeName: 'ptype',\r | |
30 | \r | |
31 | /**\r | |
32 | * Creates a new Plugin from the specified config object using the config object's ptype to determine the class to\r | |
33 | * instantiate.\r | |
34 | * @param {Object} config A configuration object for the Plugin you wish to create.\r | |
35 | * @param {Function} defaultType (optional) The constructor to provide the default Plugin type if the config object does not\r | |
36 | * contain a `ptype`. (Optional if the config contains a `ptype`).\r | |
37 | * @return {Ext.Component} The newly instantiated Plugin.\r | |
38 | */\r | |
39 | create : function(config, defaultType, host) {\r | |
40 | var result, type;\r | |
41 | \r | |
42 | if (config.init) {\r | |
43 | result = config;\r | |
44 | } else {\r | |
45 | // Inject the host into the config is we know the host\r | |
46 | if (host) {\r | |
47 | config = Ext.apply({}, config); // copy since we are going to modify\r | |
48 | config.cmp = host;\r | |
49 | }\r | |
50 | // Grab the host ref if it was configured in\r | |
51 | else {\r | |
52 | host = config.cmp;\r | |
53 | }\r | |
54 | \r | |
55 | if (config.xclass) {\r | |
56 | result = Ext.create(config);\r | |
57 | } else {\r | |
58 | // Lookup the class from the ptype and instantiate unless its a singleton\r | |
59 | type = 'plugin.' + (config.ptype || defaultType);\r | |
60 | result = Ext.ClassManager.instantiateByAlias(type, config);\r | |
61 | }\r | |
62 | }\r | |
63 | \r | |
64 | // If we come out with a non-null plugin, ensure that any setCmp is called once.\r | |
65 | if (result && host && result.setCmp && !result.setCmpCalled) {\r | |
66 | result.setCmp(host);\r | |
67 | result.setCmpCalled = true;\r | |
68 | }\r | |
69 | return result;\r | |
70 | }\r | |
71 | });\r |