pad.pub0.org/static/js/plugins.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
var plugins = {
2011-07-07 17:59:34 +00:00
callHook: function(hookName, args)
{
var global = (function () {return this}());
var hook = ((global.clientVars || {}).hooks || {})[hookName];
2011-07-07 17:59:34 +00:00
if (hook === undefined) return [];
2011-03-26 13:10:41 +00:00
var res = [];
2011-07-07 17:59:34 +00:00
for (var i = 0, N = hook.length; i < N; i++)
{
2011-03-26 13:10:41 +00:00
var plugin = hook[i];
var pluginRes = eval(plugin.plugin)[plugin.original || hookName](args);
2011-07-07 17:59:34 +00:00
if (pluginRes != undefined && pluginRes != null) res = res.concat(pluginRes);
2011-03-26 13:10:41 +00:00
}
return res;
},
2011-07-07 17:59:34 +00:00
callHookStr: function(hookName, args, sep, pre, post)
{
2011-03-26 13:10:41 +00:00
if (sep == undefined) sep = '';
if (pre == undefined) pre = '';
if (post == undefined) post = '';
2012-02-01 05:20:33 +00:00
var newCallhooks = [];
var callhooks = plugins.callHook(hookName, args);
for (var i = 0, ii = callhooks.length; i < ii; i++) {
newCallhooks[i] = pre + callhooks[i] + post;
}
return newCallhooks.join(sep || "");
2011-03-26 13:10:41 +00:00
}
};
exports.plugins = plugins;