From 890a9b913dfc55f6cc1d4ed29c4037b50a5b9eb2 Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 4 Nov 2012 20:02:43 +0000 Subject: [PATCH] Client: New plugin manager implementation --- client/assets/dev/build.js | 1 + client/assets/dev/index.html.tmpl | 1 + client/assets/dev/model_application.js | 3 + client/assets/dev/model_pluginmanager.js | 27 ++++++++ client/assets/dev/utils.js | 87 ------------------------ 5 files changed, 32 insertions(+), 87 deletions(-) create mode 100644 client/assets/dev/model_pluginmanager.js diff --git a/client/assets/dev/build.js b/client/assets/dev/build.js index 44db168..545fe72 100644 --- a/client/assets/dev/build.js +++ b/client/assets/dev/build.js @@ -40,6 +40,7 @@ var src = concat([ __dirname + '/model_channel.js', __dirname + '/model_server.js', __dirname + '/model_applet.js', + __dirname + '/model_pluginmanager.js', __dirname + '/applet_settings.js', __dirname + '/applet_nickserv.js', diff --git a/client/assets/dev/index.html.tmpl b/client/assets/dev/index.html.tmpl index 35921d1..327d0e1 100644 --- a/client/assets/dev/index.html.tmpl +++ b/client/assets/dev/index.html.tmpl @@ -203,6 +203,7 @@ ], [ + 'dev/model_pluginmanager.js', 'dev/utils.js', 'dev/view.js' ] diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index 9dcdb1c..f26e115 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -31,6 +31,9 @@ kiwi.model.Application = function () { // Best guess at where the kiwi server is this.detectKiwiServer(); + + // Load the plugin manager + this.plugins = new kiwi.model.PluginManager(); }; this.start = function () { diff --git a/client/assets/dev/model_pluginmanager.js b/client/assets/dev/model_pluginmanager.js new file mode 100644 index 0000000..00cf161 --- /dev/null +++ b/client/assets/dev/model_pluginmanager.js @@ -0,0 +1,27 @@ +kiwi.model.PluginManager = Backbone.Model.extend({ + initialize: function () { + this.$plugin_holder = $('').appendTo('#kiwi'); + this.loaded_plugins = {}; + }, + + // Load an applet within this panel + load: function (url) { + if (this.loaded_plugins[url]) { + this.unload(url); + } + + this.loaded_plugins[url] = $('
'); + this.loaded_plugins[url].appendTo(this.$plugin_holder) + .load(url); + }, + + + unload: function (url) { + if (!this.loaded_plugins[url]) { + return; + } + + this.loaded_plugins[url].remove(); + delete this.loaded_plugins[url]; + } +}); \ No newline at end of file diff --git a/client/assets/dev/utils.js b/client/assets/dev/utils.js index de64451..4648235 100644 --- a/client/assets/dev/utils.js +++ b/client/assets/dev/utils.js @@ -644,93 +644,6 @@ var plugins = [ -/** -* @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 -- 2.25.1