plugins: create PluginManager service
This commit is contained in:
parent
1fd6e1b0b6
commit
cc2eda7057
|
@ -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();
|
||||
|
||||
});
|
||||
|
||||
}]);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue