__dirname + '/model_channel.js',\r
__dirname + '/model_server.js',\r
__dirname + '/model_applet.js',\r
+ __dirname + '/model_pluginmanager.js',\r
\r
__dirname + '/applet_settings.js',\r
__dirname + '/applet_nickserv.js',\r
--- /dev/null
+kiwi.model.PluginManager = Backbone.Model.extend({\r
+ initialize: function () {\r
+ this.$plugin_holder = $('<div id="kiwi_plugins" style="display:none;"></div>').appendTo('#kiwi');\r
+ this.loaded_plugins = {};\r
+ },\r
+\r
+ // Load an applet within this panel\r
+ load: function (url) {\r
+ if (this.loaded_plugins[url]) {\r
+ this.unload(url);\r
+ }\r
+\r
+ this.loaded_plugins[url] = $('<div></div>');\r
+ this.loaded_plugins[url].appendTo(this.$plugin_holder)\r
+ .load(url);\r
+ },\r
+\r
+\r
+ unload: function (url) {\r
+ if (!this.loaded_plugins[url]) {\r
+ return;\r
+ }\r
+\r
+ this.loaded_plugins[url].remove();\r
+ delete this.loaded_plugins[url];\r
+ }\r
+});
\ No newline at end of file
-/**
-* @namespace
-*/
-kiwi.plugs = {};
-/**
-* Loaded plugins
-*/
-kiwi.plugs.loaded = {};
-/**
-* Load a plugin
-* @param {Object} plugin The plugin to be loaded
-* @returns {Boolean} True on success, false on failure
-*/
-kiwi.plugs.loadPlugin = function (plugin) {
- var plugin_ret;
- if (typeof plugin.name !== 'string') {
- return false;
- }
-
- plugin_ret = kiwi.plugs.run('plugin_load', {plugin: plugin});
- if (typeof plugin_ret === 'object') {
- kiwi.plugs.loaded[plugin_ret.plugin.name] = plugin_ret.plugin;
- kiwi.plugs.loaded[plugin_ret.plugin.name].local_data = new kiwi.dataStore('kiwi_plugin_' + plugin_ret.plugin.name);
- }
- kiwi.plugs.run('init', {}, {run_only: plugin_ret.plugin.name});
-
- return true;
-};
-
-/**
-* Unload a plugin
-* @param {String} plugin_name The name of the plugin to unload
-*/
-kiwi.plugs.unloadPlugin = function (plugin_name) {
- if (typeof kiwi.plugs.loaded[plugin_name] !== 'object') {
- return;
- }
-
- kiwi.plugs.run('unload', {}, {run_only: plugin_name});
- delete kiwi.plugs.loaded[plugin_name];
-};
-
-
-
-/**
-* Run an event against all loaded plugins
-* @param {String} event_name The name of the event
-* @param {Object} event_data The data to pass to the plugin
-* @param {Object} opts Options
-* @returns {Object} Event data, possibly modified by the plugins
-*/
-kiwi.plugs.run = function (event_name, event_data, opts) {
- var ret = event_data,
- ret_tmp,
- plugin_name;
-
- // Set some defaults if not provided
- event_data = (typeof event_data === 'undefined') ? {} : event_data;
- opts = (typeof opts === 'undefined') ? {} : opts;
-
- for (plugin_name in kiwi.plugs.loaded) {
- // If we're only calling 1 plugin, make sure it's that one
- if (typeof opts.run_only === 'string' && opts.run_only !== plugin_name) {
- continue;
- }
-
- if (typeof kiwi.plugs.loaded[plugin_name]['on' + event_name] === 'function') {
- try {
- ret_tmp = kiwi.plugs.loaded[plugin_name]['on' + event_name](ret, opts);
- if (ret_tmp === null) {
- return null;
- }
- ret = ret_tmp;
-
- if (typeof ret.event_bubbles === 'boolean' && ret.event_bubbles === false) {
- delete ret.event_bubbles;
- return ret;
- }
- } catch (e) {
- }
- }
- }
-
- return ret;
-};
-
-
/**
* @constructor