From e19fc9f24ab128d4337d67d0e3f312a1ab0be38b Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Mon, 22 Mar 2010 19:59:04 +0100 Subject: Made the client side plugin API more similar to the server side one --- etherpad/src/plugins/testplugin/static/js/test.js | 2 +- etherpad/src/static/js/plugins.js | 38 ++++++++++++----------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/etherpad/src/plugins/testplugin/static/js/test.js b/etherpad/src/plugins/testplugin/static/js/test.js index 0f30cd9..83fb40c 100644 --- a/etherpad/src/plugins/testplugin/static/js/test.js +++ b/etherpad/src/plugins/testplugin/static/js/test.js @@ -1 +1 @@ -callHook("kafoo"); +plugins.callHook("kafoo"); diff --git a/etherpad/src/static/js/plugins.js b/etherpad/src/static/js/plugins.js index 6d8804e..d1d6b14 100644 --- a/etherpad/src/static/js/plugins.js +++ b/etherpad/src/static/js/plugins.js @@ -1,19 +1,21 @@ -function callHook(hookName, args) { - if (clientVars.hooks[hookName] === undefined) - return []; - var res = []; - for (i = 0; i < clientVars.hooks[hookName].length; i++) { - var plugin = clientVars.hooks[hookName][i]; - var pluginRes = eval(plugin.plugin)[plugin.original || hookName](args); - if (pluginRes != undefined && pluginRes != null) - res = res.concat(pluginRes); - } - return res; -} +plugins = { + callHook: function (hookName, args) { + if (clientVars.hooks[hookName] === undefined) + return []; + var res = []; + for (i = 0; i < clientVars.hooks[hookName].length; i++) { + var plugin = clientVars.hooks[hookName][i]; + var pluginRes = eval(plugin.plugin)[plugin.original || hookName](args); + if (pluginRes != undefined && pluginRes != null) + res = res.concat(pluginRes); + } + return res; + }, -function callHookStr(hookName, args, sep, pre, post) { - if (sep == undefined) sep = ''; - if (pre == undefined) pre = ''; - if (post == undefined) post = ''; - return callHook(hookName, args).map(function (x) { return pre + x + post}).join(sep || ""); -} + callHookStr: function (hookName, args, sep, pre, post) { + if (sep == undefined) sep = ''; + if (pre == undefined) pre = ''; + if (post == undefined) post = ''; + return callHook(hookName, args).map(function (x) { return pre + x + post}).join(sep || ""); + } +}; -- cgit v1.2.3