plugins: make PluginManager dependent of userPlugins and register them at runtime

This commit is contained in:
David Cormier 2013-10-08 18:57:43 -04:00
parent e457e96cd6
commit 7b701079f4
1 changed files with 18 additions and 19 deletions

View File

@ -1,22 +1,23 @@
var plugins = angular.module('plugins', []); plugins = angular.module('plugins', []);
var Plugin = function(contentForMessage) {
plugins.service('plugins', function() {
return {
this.Plugin = function(contentForMessage) { contentForMessage: contentForMessage,
exclusive: false,
return {
contentForMessage: contentForMessage,
exclusive: false,
}
} }
}
plugins.service('plugins', ['userPlugins', function(userPlugins) {
var PluginManagerObject = function() { var PluginManagerObject = function() {
var plugins = []; var plugins = [];
var registerPlugins = function(userPlugins) {
var addPlugin = function(plugin) { for (var i = 0; i < userPlugins.length; i++) {
plugins.push(plugin); plugins.push(userPlugins[i]);
};
} }
var contentForMessage = function(message) { var contentForMessage = function(message) {
@ -25,7 +26,8 @@ plugins.service('plugins', function() {
for (var i = 0; i < plugins.length; i++) { for (var i = 0; i < plugins.length; i++) {
var pluginContent = plugins[i].contentForMessage(message); var pluginContent = plugins[i].contentForMessage(message);
if (pluginContent) { if (pluginContent) {
var pluginContent = {'visible': false, 'content': pluginContent } var pluginContent = {'visible': false,
'content': pluginContent }
content.push(pluginContent); content.push(pluginContent);
if (plugins[i].exclusive) { if (plugins[i].exclusive) {
@ -33,20 +35,17 @@ plugins.service('plugins', function() {
} }
} }
} }
return content; return content;
} }
return { return {
addPlugin: addPlugin, registerPlugins: registerPlugins,
contentForMessage: contentForMessage contentForMessage: contentForMessage
} }
} }
this.PluginManager = new PluginManagerObject(); this.PluginManager = new PluginManagerObject();
this.PluginManager.registerPlugins(userPlugins.plugins);
});
}]); }]);
plugins.factory('userPlugins', function() { plugins.factory('userPlugins', function() {