From 4528138d6eacdb2eaede3b4e63a3ad77b982378a Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 4 Sep 2011 01:55:05 +0100 Subject: [PATCH] Plugin loader/unloader --- js/front.js | 39 ++++++++-------------- js/util.js | 94 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 71 insertions(+), 62 deletions(-) diff --git a/js/front.js b/js/front.js index c51e5c6..1a49d7e 100644 --- a/js/front.js +++ b/js/front.js @@ -774,26 +774,20 @@ var front = { front.boxes.plugins.box.css('top', -(front.boxes.plugins.height + 40)); // Populate the plugin list.. - lst = $('#plugin_list'); - lst.find('option').remove(); - for (j in plugins.privmsg) { - txt = plugins.privmsg[j].name; - lst.append(''); + function enumPlugins () { + lst = $('#plugin_list'); + lst.find('option').remove(); + for (j in plugs.loaded) { + txt = plugs.loaded[j].name; + lst.append(''); + } } + enumPlugins(); // Event bindings $('#kiwi .plugin_file').submit(function () { - $.getJSON($('.txtpluginfile').val(), function (data) { - var plg = {}; - plg.name = data.name; - eval("plg.onprivmsg = " + data.onprivmsg); - eval("plg.onload = " + data.onload); - eval("plg.onunload = " + data.onunload); - plugins.privmsg.push(plg); - - if (plg.onload instanceof Function) { - plg.onload(); - } + $('
').load($('.txtpluginfile').val(), function(e){ + enumPlugins(); }); return false; }); @@ -802,17 +796,10 @@ var front = { }); $('#kiwi #plugins_list_unload').click(function () { - var selected_plugin, i; + var selected_plugin; selected_plugin = $('#plugin_list').val(); - console.log("removing plugin: " + selected_plugin); - for (i in plugins.privmsg) { - if (plugins.privmsg[i].name === selected_plugin) { - if (plugins.privmsg[i].onunload instanceof Function) { - plugins.privmsg[i].onunload(); - } - delete plugins.privmsg[i]; - } - } + plugs.unloadPlugin(selected_plugin); + enumPlugins(); }); $('#kiwi .txtpluginfile').focus(); diff --git a/js/util.js b/js/util.js index f186ed9..37ac40a 100644 --- a/js/util.js +++ b/js/util.js @@ -150,42 +150,57 @@ var plugins = [ { name: "inBrowser", oninit: function(event, opts){ - $('#windows a.link_ext').live('mouseover', function () { - var a = $(this); - var tt = $('.tt', a); - - if (tt.text() === '') { - var tooltip = $('Open in Kiwi..'); - tt.append(tooltip); - } - - tt.css('top', -tt.outerHeight()+'px'); - tt.css('left', (a.outerWidth() / 2) - (tt.outerWidth() / 2)); - }); - $('#windows a.link_ext').live('mouseout', function () { - var a = $(this); - var tt = $('.tt', a); - }); - $('#windows a.link_ext').live('click', function (e) { - var a = $(this); - - switch (e.target.className) { - case 'link_ext': - case 'link_img_a': - return true; - break; - case 'link_ext_browser': - var t = new Utilityview('Browser'); - t.topic = a.attr('href'); - - t.iframe = $(''); - t.iframe.attr('src', a.attr('href')); - t.div.append(t.iframe); - t.show(); - break; - } - return false; - }); + $('#windows a.link_ext').live('mouseover', this.mouseover); + $('#windows a.link_ext').live('mouseout', this.mouseout); + $('#windows a.link_ext').live('click', this.mouseclick); + }, + + onunload: function(event, opts){ + // TODO: make this work + $('#windows a.link_ext').die('mouseover', this.mouseover); + $('#windows a.link_ext').die('mouseout', this.mouseout); + $('#windows a.link_ext').die('click', this.mouseclick); + }, + + + + mouseover: function(e){ + var a = $(this); + var tt = $('.tt', a); + + if (tt.text() === '') { + var tooltip = $('Open in Kiwi..'); + tt.append(tooltip); + } + + tt.css('top', -tt.outerHeight()+'px'); + tt.css('left', (a.outerWidth() / 2) - (tt.outerWidth() / 2)); + }, + + mouseout: function(e){ + var a = $(this); + var tt = $('.tt', a); + }, + + mouseclick: function(e){ + var a = $(this); + + switch (e.target.className) { + case 'link_ext': + case 'link_img_a': + return true; + break; + case 'link_ext_browser': + var t = new Utilityview('Browser'); + t.topic = a.attr('href'); + + t.iframe = $(''); + t.iframe.attr('src', a.attr('href')); + t.div.append(t.iframe); + t.show(); + break; + } + return false; } } ]; @@ -210,6 +225,13 @@ plugs.loadPlugin = function (plugin) { return true; }; +plugs.unloadPlugin = function (plugin_name) { + if (typeof plugs.loaded[plugin_name] !== 'object') return; + + plugs.run('unload', {}, {run_only: plugin_name}); + delete plugs.loaded[plugin_name]; +} + /* -- 2.25.1