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