Elgg  Version 3.0
hooks.js
Go to the documentation of this file.
1 /*
2  * Javascript hook interface
3  */
4 
5 elgg.provide('elgg.config.hooks');
6 elgg.provide('elgg.config.instant_hooks');
7 elgg.provide('elgg.config.triggered_hooks');
8 
9 !function() {
10  // counter for tracking registration order
11  var index = 0;
12 
30  elgg.register_hook_handler = function(name, type, handler, priority) {
31  elgg.assertTypeOf('string', name);
32  elgg.assertTypeOf('string', type);
33  elgg.assertTypeOf('function', handler);
34 
35  if (!name || !type) {
36  return false;
37  }
38 
39  var hooks = elgg.config.hooks;
40 
41  elgg.provide([name, type], hooks);
42 
43  if (!hooks[name][type].length) {
44  hooks[name][type] = [];
45  }
46 
47  // call if instant and already triggered.
48  if (elgg.is_instant_hook(name, type) && elgg.is_triggered_hook(name, type)) {
49  handler(name, type, null, null);
50  }
51 
52  hooks[name][type].push({
53  priority: priority,
54  index: index++,
55  handler: handler
56  });
57  return true;
58  }
59 }();
60 
81 elgg.trigger_hook = function(name, type, params, value) {
82  elgg.assertTypeOf('string', name);
83  elgg.assertTypeOf('string', type);
84 
85  // mark as triggered
86  elgg.set_triggered_hook(name, type);
87 
88  // default to null if unpassed
89  value = !elgg.isNullOrUndefined(value) ? value : null;
90 
91  var hooks = elgg.config.hooks,
92  registrations = [],
93  push = Array.prototype.push;
94 
95  elgg.provide([name, type], hooks);
96  elgg.provide(['all', type], hooks);
97  elgg.provide([name, 'all'], hooks);
98  elgg.provide(['all', 'all'], hooks);
99 
100  if (hooks[name][type].length) {
101  if (name !== 'all' && type !== 'all') {
102  push.apply(registrations, hooks[name][type]);
103  }
104  }
105  if (hooks['all'][type].length) {
106  if (type !== 'all') {
107  push.apply(registrations, hooks['all'][type]);
108  }
109  }
110  if (hooks[name]['all'].length) {
111  if (name !== 'all') {
112  push.apply(registrations, hooks[name]['all']);
113  }
114  }
115  if (hooks['all']['all'].length) {
116  push.apply(registrations, hooks['all']['all']);
117  }
118 
119  registrations.sort(function (a, b) {
120  // priority first
121  if (a.priority < b.priority) {
122  return -1;
123  }
124  if (a.priority > b.priority) {
125  return 1;
126  }
127 
128  // then insertion order
129  return (a.index < b.index) ? -1 : 1;
130  });
131 
132  // only synchronous handlers
133  $.each(registrations, function (i, registration) {
134  var handler_return = registration.handler(name, type, params, value);
135  if (!elgg.isNullOrUndefined(handler_return)) {
136  value = handler_return;
137  }
138  });
139 
140  return value;
141 };
142 
156 elgg.register_instant_hook = function(name, type) {
157  elgg.assertTypeOf('string', name);
158  elgg.assertTypeOf('string', type);
159 
160  return elgg.push_to_object_array(elgg.config.instant_hooks, name, type);
161 };
162 
169 elgg.is_instant_hook = function(name, type) {
170  return elgg.is_in_object_array(elgg.config.instant_hooks, name, type);
171 };
172 
179 elgg.set_triggered_hook = function(name, type) {
180  return elgg.push_to_object_array(elgg.config.triggered_hooks, name, type);
181 };
182 
189 elgg.is_triggered_hook = function(name, type) {
190  return elgg.is_in_object_array(elgg.config.triggered_hooks, name, type);
191 };
192 
193 elgg.register_instant_hook('init', 'system');
194 elgg.register_instant_hook('ready', 'system');
195 elgg.register_instant_hook('boot', 'system');
return['admin/delete_admin_notice'=>['access'=> 'admin'],'admin/delete_admin_notices'=>['access'=> 'admin'],'admin/menu/save'=>['access'=> 'admin'],'admin/plugins/activate'=>['access'=> 'admin'],'admin/plugins/activate_all'=>['access'=> 'admin'],'admin/plugins/deactivate'=>['access'=> 'admin'],'admin/plugins/deactivate_all'=>['access'=> 'admin'],'admin/plugins/set_priority'=>['access'=> 'admin'],'admin/security/settings'=>['access'=> 'admin'],'admin/security/regenerate_site_secret'=>['access'=> 'admin'],'admin/site/flush_cache'=>['access'=> 'admin'],'admin/site/set_maintenance_mode'=>['access'=> 'admin'],'admin/site/set_robots'=>['access'=> 'admin'],'admin/site/unlock_upgrade'=>['access'=> 'admin'],'admin/site/update_basic'=>['access'=> 'admin'],'admin/site/update_advanced'=>['access'=> 'admin'],'admin/upgrade'=>['access'=> 'admin'],'admin/upgrade/reset'=>['access'=> 'admin'],'admin/user/ban'=>['access'=> 'admin'],'admin/user/bulk/delete'=>['access'=> 'admin'],'admin/user/bulk/validate'=>['access'=> 'admin'],'admin/user/delete'=>['access'=> 'admin'],'admin/user/makeadmin'=>['access'=> 'admin'],'admin/user/resetpassword'=>['access'=> 'admin'],'admin/user/removeadmin'=>['access'=> 'admin'],'admin/user/unban'=>['access'=> 'admin'],'admin/user/validate'=>['access'=> 'admin'],'avatar/upload'=>[],'avatar/crop'=>[],'avatar/remove'=>[],'comment/save'=>[],'entity/delete'=>[],'login'=>['access'=> 'public'],'logout'=>[],'plugins/settings/save'=>['access'=> 'admin'],'plugins/usersettings/save'=>[],'register'=>['access'=> 'public'],'river/delete'=>[],'user/changepassword'=>['access'=> 'public'],'user/requestnewpassword'=>['access'=> 'public'],'useradd'=>['access'=> 'admin'],'usersettings/save'=>[],'widgets/add'=>[],'widgets/delete'=>[],'widgets/move'=>[],'widgets/save'=>[],]
Definition: actions.php:50
if(!$enabled) if(PHP_SAPI!== 'cli')
Interates through each element of an array and calls callback a function.
$data value
Definition: default.php:27
$site name
var elgg
Definition: elgglib.js:4