|
1 | 1 | (function($){ |
2 | | - |
3 | | -$.wpsdb={ |
4 | | -/** |
5 | | - * Implement a WordPress-link Hook System for Javascript |
6 | | - * TODO: Change 'tag' to 'args', allow number (priority), string (tag), object (priority+tag) |
7 | | - */ |
8 | | -hooks:{action:{},filter:{}}, |
9 | | -add_action:function(action,callable,tag){ |
10 | | -jQuery.wpsdb.add_hook('action',action,callable,tag); |
11 | | -}, |
12 | | -add_filter:function(action,callable,tag){ |
13 | | -jQuery.wpsdb.add_hook('filter',action,callable,tag); |
14 | | -}, |
15 | | -do_action:function(action,args){ |
16 | | -jQuery.wpsdb.do_hook('action',action,null,args); |
17 | | -}, |
18 | | -apply_filters:function(action,value,args){ |
19 | | -returnjQuery.wpsdb.do_hook('filter',action,value,args); |
20 | | -}, |
21 | | -remove_action:function(action,tag){ |
22 | | -jQuery.wpsdb.remove_hook('action',action,tag); |
23 | | -}, |
24 | | -remove_filter:function(action,tag){ |
25 | | -jQuery.wpsdb.remove_hook('filter',action,tag); |
26 | | -}, |
27 | | -add_hook:function(hook_type,action,callable,tag){ |
28 | | -if(undefined==jQuery.wpsdb.hooks[hook_type][action]){ |
29 | | -jQuery.wpsdb.hooks[hook_type][action]=[]; |
30 | | -} |
31 | | -varhooks=jQuery.wpsdb.hooks[hook_type][action]; |
32 | | -if(undefined==tag){ |
33 | | -tag=action+'_'+hooks.length; |
34 | | -} |
35 | | -jQuery.wpsdb.hooks[hook_type][action].push({tag:tag,callable:callable}); |
36 | | -}, |
37 | | -do_hook:function(hook_type,action,value,args){ |
38 | | -if(undefined!=jQuery.wpsdb.hooks[hook_type][action]){ |
39 | | -varhooks=jQuery.wpsdb.hooks[hook_type][action]; |
40 | | -for(vari=0;i<hooks.length;i++){ |
41 | | -if('action'==hook_type){ |
42 | | -hooks[i].callable(args); |
43 | | -}else{ |
44 | | -value=hooks[i].callable(value,args); |
45 | | -} |
46 | | -} |
47 | | -} |
48 | | -if('filter'==hook_type){ |
49 | | -returnvalue; |
50 | | -} |
51 | | -}, |
52 | | -remove_hook:function(hook_type,action,tag){ |
53 | | -if(undefined!=jQuery.wpsdb.hooks[hook_type][action]){ |
54 | | -varhooks=jQuery.wpsdb.hooks[hook_type][action]; |
55 | | -for(vari=hooks.length-1;i>=0;i--){ |
56 | | -if(undefined==tag||tag==hooks[i].tag) |
57 | | -hooks.splice(i,1); |
58 | | -} |
59 | | -} |
60 | | -} |
61 | | -} |
62 | | - |
| 2 | +$.wpsdb={ |
| 3 | +/** |
| 4 | + * Implement a WordPress-link Hook System for Javascript |
| 5 | + * TODO: Change 'tag' to 'args', allow number (priority), string (tag), |
| 6 | + object (priority+tag) |
| 7 | + */ |
| 8 | +hooks:{ |
| 9 | +action:{}, |
| 10 | +filter:{} |
| 11 | +}, |
| 12 | +add_action:function(action,callable,tag){ |
| 13 | +jQuery.wpsdb.add_hook('action',action,callable,tag); |
| 14 | +}, |
| 15 | +add_filter:function(action,callable,tag){ |
| 16 | +jQuery.wpsdb.add_hook('filter',action,callable,tag); |
| 17 | +}, |
| 18 | +do_action:function(action,args){ |
| 19 | +jQuery.wpsdb.do_hook('action',action,null,args); |
| 20 | +}, |
| 21 | +apply_filters:function(action,value,args){ |
| 22 | +returnjQuery.wpsdb.do_hook('filter',action,value,args); |
| 23 | +}, |
| 24 | +remove_action:function(action,tag){ |
| 25 | +jQuery.wpsdb.remove_hook('action',action,tag); |
| 26 | +}, |
| 27 | +remove_filter:function(action,tag){ |
| 28 | +jQuery.wpsdb.remove_hook('filter',action,tag); |
| 29 | +}, |
| 30 | +add_hook:function(hook_type,action,callable,tag){ |
| 31 | +if(undefined==jQuery.wpsdb.hooks[hook_type][action]){ |
| 32 | +jQuery.wpsdb.hooks[hook_type][action]=[]; |
| 33 | +} |
| 34 | +varhooks=jQuery.wpsdb.hooks[hook_type][action]; |
| 35 | +if(undefined==tag){ |
| 36 | +tag=action+'_'+hooks.length; |
| 37 | +} |
| 38 | +jQuery.wpsdb.hooks[hook_type][action].push({ |
| 39 | +tag:tag, |
| 40 | +callable:callable |
| 41 | +}); |
| 42 | +}, |
| 43 | +do_hook:function(hook_type,action,value,args){ |
| 44 | +if(undefined!=jQuery.wpsdb.hooks[hook_type][action]){ |
| 45 | +varhooks=jQuery.wpsdb.hooks[hook_type][action]; |
| 46 | +for(vari=0;i<hooks.length;i++){ |
| 47 | +if('action'==hook_type){ |
| 48 | +hooks[i].callable(args); |
| 49 | +}else{ |
| 50 | +value=hooks[i].callable(value,args); |
| 51 | +} |
| 52 | +} |
| 53 | +} |
| 54 | +if('filter'==hook_type){ |
| 55 | +returnvalue; |
| 56 | +} |
| 57 | +}, |
| 58 | +remove_hook:function(hook_type,action,tag){ |
| 59 | +if(undefined!=jQuery.wpsdb.hooks[hook_type][action]){ |
| 60 | +varhooks=jQuery.wpsdb.hooks[hook_type][action]; |
| 61 | +for(vari=hooks.length-1;i>=0;i--){ |
| 62 | +if(undefined==tag||tag==hooks[i].tag) |
| 63 | +hooks.splice(i,1); |
| 64 | +} |
| 65 | +} |
| 66 | +} |
| 67 | +}; |
63 | 68 | })(jQuery); |