CommandManager.addHook Member

Registers a hook for a particular command.

Syntax

object.addHook(commandName, func, id, before);

Arguments

ArgumentSummary
commandName A String command name to hook. The command named must already exist in the CommandManager; if it does not, no hook is added.
func A Function to handle the hook.
id A String identifier for the hook.
before A Boolean indicating whether the hook wishes to be called before or after the command executes.

Returns

Remarks

A command hook is uniquely identified by the pair id, before; only a single hook may exist for a given pair of id and before values. It is wise to use a unique id; plugins should construct an id using plugin.id, e.g. |plugin.id + "-my-hook-1"|.

See Also

Source Code

function cmgr_hook (commandName, func, id, before)
{
if (!ASSERT(objectContains(this.commands, commandName),
"Unknown command '" + commandName + "'"))
{
return;
}
var command = this.commands[commandName];
if (before)
{
if (!("beforeHooks" in command))
command.beforeHooks = new Object();
command.beforeHooks[id] = func;
}
else
{
if (!("afterHooks" in command))
command.afterHooks = new Object();
command.afterHooks[id] = func;
}
}