From cc2eda7057772d5a87413110dc92447095827bbb Mon Sep 17 00:00:00 2001 From: David Cormier Date: Tue, 8 Oct 2013 17:55:30 -0400 Subject: [PATCH] plugins: create PluginManager service --- js/plugins.js | 57 ++++++++++++++++++++++++------------------------ js/websockets.js | 4 ++-- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index 4c7d88b..d725c79 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -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(); + +}); }]); diff --git a/js/websockets.js b/js/websockets.js index c7b4ad2..89111a0 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -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) {