plugins: create PluginManager service

This commit is contained in:
David Cormier 2013-10-08 17:55:30 -04:00
parent 1fd6e1b0b6
commit cc2eda7057
2 changed files with 31 additions and 30 deletions

View file

@ -10,41 +10,42 @@ plugins.service('plugins', function() {
exclusive: false,
}
}
});
var PluginManagerObject = function() {
plugins.factory('pluginManager', ['youtubePlugin', 'urlPlugin', 'imagePlugin', function(youtubePlugin, urlPlugin, imagePlugin) {
var plugins = [];
var plugins = [youtubePlugin, urlPlugin, imagePlugin]
var hookPlugin = function(plugin) {
plugins.push(plugin);
}
var contentForMessage = function(message) {
var content = [];
for (var i = 0; i < plugins.length; i++) {
var pluginContent = plugins[i].contentForMessage(message);
if (pluginContent) {
var pluginContent = {'visible': false, 'content': pluginContent }
content.push(pluginContent);
if (plugins[i].exclusive) {
break;
}
}
var addPlugin = function(plugin) {
plugins.push(plugin);
}
return content;
var contentForMessage = function(message) {
var content = [];
for (var i = 0; i < plugins.length; i++) {
var pluginContent = plugins[i].contentForMessage(message);
if (pluginContent) {
var pluginContent = {'visible': false, 'content': pluginContent }
content.push(pluginContent);
if (plugins[i].exclusive) {
break;
}
}
}
return content;
}
return {
addPlugin: addPlugin,
contentForMessage: contentForMessage
}
}
return {
hookPlugin: hookPlugin,
contentForMessage: contentForMessage
}
this.PluginManager = new PluginManagerObject();
});
}]);

View file

@ -110,7 +110,7 @@ weechat.factory('colors', [function($scope) {
}]);
weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', function($rootScope, colors, models, pluginManager) {
weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', function($rootScope, colors, models, plugins) {
var handleBufferClosing = function(message) {
var bufferMessage = message['objects'][0]['content'][0];
@ -124,7 +124,7 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager',
var message = new models.BufferLine(message);
var buffer = models.getBuffer(message.buffer);
message.metadata = pluginManager.contentForMessage(message.text);
message.metadata = plugins.PluginManager.contentForMessage(message.text);
buffer.addLine(message);
if (!buffer.active) {