mirror of
https://github.com/Mibew/mibew.git
synced 2024-11-15 16:44:11 +03:00
Create JavaScript's PluginManager class
This commit is contained in:
parent
53e9400dde
commit
c61789c2d7
@ -16,5 +16,9 @@
|
||||
<script type="text/javascript" src="test_cases/mibewapi_tests.js"></script>
|
||||
<!-- End of the mibew_api.js tests -->
|
||||
|
||||
<!-- Start of the PluginManager class tests -->
|
||||
<script type="text/javascript" src="/webim/js/164/pluginmanager.js"></script>
|
||||
<script type="text/javascript" src="test_cases/pluginmanager_tests.js"></script>
|
||||
<!-- End of the mibew_api.js class tests -->
|
||||
</body>
|
||||
</html>
|
||||
|
@ -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'
|
||||
);
|
||||
});
|
8
src/messenger/webim/js/164/pluginmanager.js
Normal file
8
src/messenger/webim/js/164/pluginmanager.js
Normal file
@ -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}};
|
45
src/messenger/webim/js/source/pluginmanager.js
Normal file
45
src/messenger/webim/js/source/pluginmanager.js
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user