diff --git a/src/messenger/tests/client_side/qunit/index.html b/src/messenger/tests/client_side/qunit/index.html index fc099ef4..6b7ee313 100644 --- a/src/messenger/tests/client_side/qunit/index.html +++ b/src/messenger/tests/client_side/qunit/index.html @@ -16,5 +16,9 @@ + + + + diff --git a/src/messenger/tests/client_side/qunit/test_cases/pluginmanager_tests.js b/src/messenger/tests/client_side/qunit/test_cases/pluginmanager_tests.js new file mode 100644 index 00000000..a6e19028 --- /dev/null +++ b/src/messenger/tests/client_side/qunit/test_cases/pluginmanager_tests.js @@ -0,0 +1,21 @@ +// Testing PluginManager class +module('PluginManager'); + +test('getPlugin', function() { + var pluginManager = new PluginManager(); + // Try to load not stored plugin + equal( + pluginManager.getPlugin('WrongPlugin'), + false, + 'Test loading not stored plugin' + ) + + // Try save and load test plugin + var testPlugin = {'testField': 'testValue'} + pluginManager.addPlugin('TestPlugin', testPlugin); + deepEqual( + pluginManager.getPlugin('TestPlugin'), + testPlugin, + 'Test loading stored plugin' + ); +}); \ No newline at end of file diff --git a/src/messenger/webim/js/164/pluginmanager.js b/src/messenger/webim/js/164/pluginmanager.js new file mode 100644 index 00000000..adc4449f --- /dev/null +++ b/src/messenger/webim/js/164/pluginmanager.js @@ -0,0 +1,8 @@ +/* + This file is part of Mibew Messenger project. + http://mibew.org + + Copyright (c) 2005-2011 Mibew Messenger Community + License: http://mibew.org/license.php +*/ +var PluginManager=function(){var b={};this.addPlugin=function(a,c){b[a]=c};this.getPlugin=function(a){return b[a]?b[a]:!1}}; \ No newline at end of file diff --git a/src/messenger/webim/js/source/pluginmanager.js b/src/messenger/webim/js/source/pluginmanager.js new file mode 100644 index 00000000..9897694d --- /dev/null +++ b/src/messenger/webim/js/source/pluginmanager.js @@ -0,0 +1,45 @@ +/** + * @preserve This file is part of Mibew Messenger project. + * http://mibew.org + * + * Copyright (c) 2005-2011 Mibew Messenger Community + * License: http://mibew.org/license.php + */ + +/** + * Create an instance of plugin manager + * @constructor + */ +var PluginManager = function() { + + /** + * Contains all added plugins + * @type Array + * @private + */ + var pluginsList = {} + + /** + * Add plugin to internal plugins list + * + * @param {String} pluginName Name of the added plugin. Uses to get plugin + * by the PluginManager.getPlugin() method + * @param {Object} plugin A plugin object + */ + this.addPlugin = function(pluginName, plugin) { + pluginsList[pluginName] = plugin; + } + + /** + * Get plugin object from internal storage + * + * @returns {Object|Boolean} Plugin object if it was added by the + * PluginManager.addPlugin method and boolean false otherwise. + */ + this.getPlugin = function(pluginName) { + if (pluginsList[pluginName]) { + return pluginsList[pluginName]; + } + return false; + } +} \ No newline at end of file