01.
function
hooks()
02.
{
03.
this
.queue =
new
Array();
04.
}
05.
06.
hooks.prototype.addAction =
function
(hook, func)
07.
{
08.
this
.queue[hook] =
new
Array();
09.
if
(
typeof
func ==
'function'
) {
10.
this
.queue[hook].push(func);
11.
}
else
if
(
typeof
func ==
'string'
) {
12.
this
.queue[hook].push(
this
.window[func]);
13.
}
14.
}
15.
16.
hooks.prototype.doAction =
function
(hook)
17.
{
18.
var
parameters = Array.prototype.slice.call(arguments, 1);
19.
var
functions =
this
.queue[hook];
20.
for
(
var
i=0; i < functions.length; i++)
21.
{
22.
this
.call_user_func_array(functions[i], parameters);
23.
}
24.
return
true
;
25.
}
26.
27.
hooks.prototype.call_user_func_array =
function
(cb, parameters)
28.
{
29.
if
(
typeof
cb ===
'string'
) {
30.
func = (
typeof
this
[cb] ===
'function'
) ?
this
[cb] : func = (
new
Function(
null
,
'return '
+ cb))();
31.
}
else
if
(cb
instanceof
Array) {
32.
func = (
typeof
cb[0] ==
'string'
) ? eval(cb[0]+
"['"
+cb[1]+
"']"
) : func = cb[0][cb[1]];
33.
}
else
if
(
typeof
cb ===
'function'
) {
34.
func = cb;
35.
}
36.
if
(
typeof
func !=
'function'
) {
37.
throw
new
Error(func +
' is not a valid function'
);
38.
}
39.
if
(
typeof
parameters ==
'undefined'
) {
40.
var
tmp_ary = [];
41.
var
parameters = Array.prototype.slice.call(tmp_ary, 1);
42.
}
43.
return
(
typeof
cb[0] ===
'string'
) ? func.apply(eval(cb[0]), parameters) :
44.
(
typeof
cb[0] !==
'object'
) ? func.apply(
null
, parameters) : func.apply(cb[0], parameters);
45.
}