Plugin manager.
Example:
const PluginManager = require('core/plugin-manager');
PluginManager.register('fast-click-highlight', ['view', 'field'], {
color : "red",
events: {
'click .fast-click-highlighted': 'onClickItem'
},
onClickItem: function(e) {
alert(1)
},
// The onAttach function will be called every time the plugin is
// attached to a new component. It will be executed from the scope of
// the component being attached to.
//Applied after the plugin has been mixed into the component.
onAttach: function(component, plugin) {
this.on('render', function(){
//same as plugin.color and component.$el.css
this.$el.css('color', this.color);
});
}
});
If you want to use the current plugin for a view, you have to declare the plugin in it:
const ViewManager = require('view/view-manager');
var MyView = ViewManager.View.extend({
initialize: function(options) {},
plugins: ['fast-click-highlight'],
...,
});
// or
$plugins: [{
'fast-click-highlight': {
events: {
'click article' : 'onClickItem'
}
}
}],
onClickItem: function() {
alert(2);
}
If you want to disable a plugin, you have to use the disabledPlugins
property as in the following example:
var MyView = ViewManager.View.extend({
initialize: function(options) {},
disabledPlugins: ['fast-click-highlight'],
...,
});
Members
-
<static> plugins
-
A hash map containing all registered plugins.
Methods
-
<static> attach(component, type)
-
Attaches a plugin to a view.
Parameters:
Name Type Description component
View/Component | Data/Bean | Data/BeanCollection The component.
type
string The component type. Can be one of the following: 'view', 'layout', 'field', 'model' or 'collection'.
-
<static> detach(component, type)
-
Detaches plugins and calls the
onDetach
method on each one.Parameters:
Name Type Description component
View/Component | Data/Bean | Data/BeanCollection The component.
type
string The component type. Can be one of the following: 'view', 'layout', 'field', 'model' or 'collection'.
-
<static> register(name, validTypes, plugin)
-
Registers a plugin.
Parameters:
Name Type Description name
string The plugin name.
validTypes
string | Array.<string> The list of component types this plugin can be applied to ('view', 'field', 'layout', 'model' and/or 'collection').
plugin
Object The plugin object.