Elgg  Version 5.1
hooks.js
Go to the documentation of this file.
1 define(['jquery', 'elgg'], function ($, elgg) {
2  // counter for tracking registration order
3  var index = 0;
4 
5  // array that holds all hook registrations
6  var hooks = {};
7 
14  function prepareHook(name, type) {
15  hooks[name] = hooks[name] || [];
16  hooks[name][type] = hooks[name][type] || [];
17 
18  hooks['all'] = hooks['all'] || [];
19  hooks[name]['all'] = hooks[name]['all'] || [];
20  hooks['all'][type] = hooks['all'][type] || [];
21  hooks['all']['all'] = hooks['all']['all'] || [];
22  }
23 
24  return {
25 
29  reset: function() {
30  hooks = [];
31  },
32 
45  register: function(name, type, handler, priority) {
46  elgg.assertTypeOf('string', name);
47  elgg.assertTypeOf('string', type);
48  elgg.assertTypeOf('function', handler);
49 
50  if (!name || !type) {
51  return false;
52  }
53 
54  prepareHook(name, type);
55 
56  hooks[name][type].push({
57  priority: priority,
58  index: index++,
59  handler: handler
60  });
61 
62  return true;
63  },
64 
83  trigger: function(name, type, params, value) {
84  elgg.assertTypeOf('string', name);
85  elgg.assertTypeOf('string', type);
86 
87  // default to null if unpassed
88  value = (value != null) ? value : null;
89 
90  var registrations = [],
91  push = Array.prototype.push;
92 
93  prepareHook(name, type);
94 
95  if (hooks[name][type].length) {
96  if (name !== 'all' && type !== 'all') {
97  push.apply(registrations, hooks[name][type]);
98  }
99  }
100 
101  if (hooks['all'][type].length) {
102  if (type !== 'all') {
103  push.apply(registrations, hooks['all'][type]);
104  }
105  }
106 
107  if (hooks[name]['all'].length) {
108  if (name !== 'all') {
109  push.apply(registrations, hooks[name]['all']);
110  }
111  }
112 
113  if (hooks['all']['all'].length) {
114  push.apply(registrations, hooks['all']['all']);
115  }
116 
117  registrations.sort(function (a, b) {
118  // priority first
119  if (a.priority < b.priority) {
120  return -1;
121  }
122 
123  if (a.priority > b.priority) {
124  return 1;
125  }
126 
127  // then insertion order
128  return (a.index < b.index) ? -1 : 1;
129  });
130 
131  // only synchronous handlers
132  $.each(registrations, function (i, registration) {
133  var handler_return = registration.handler(name, type, params, value);
134  if (handler_return != null) {
135  value = handler_return;
136  }
137  });
138 
139  return value;
140  }
141  };
142 });
if(parse_url(elgg_get_site_url(), PHP_URL_PATH)!== '/') if(file_exists(elgg_get_root_path(). 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
define(['jquery', 'elgg'], function($, elgg){var index=0;var hooks={};function prepareHook(name, type){hooks[name]=hooks[name]||[];hooks[name][type]=hooks[name][type]||[];hooks['all']=hooks['all']||[];hooks[name]['all']=hooks[name]['all']||[];hooks['all'][type]=hooks['all'][type]||[];hooks['all']['all']=hooks['all']['all']||[];}return{reset:function(){hooks=[];}, register:function(name, type, handler, priority){elgg.assertTypeOf('string', name);elgg.assertTypeOf('string', type);elgg.assertTypeOf('function', handler);if(!name||!type){return false;}prepareHook(name, type);hooks[name][type].push({priority:priority, index:index++, handler:handler});return true;}, trigger:function(name, type, params, value){elgg.assertTypeOf('string', name);elgg.assertTypeOf('string', type);value=(value!=null)?value:null;var registrations=[], push=Array.prototype.push;prepareHook(name, type);if(hooks[name][type].length){if(name!== 'all'&&type!== 'all'){push.apply(registrations, hooks[name][type]);}}if(hooks['all'][type].length){if(type!== 'all'){push.apply(registrations, hooks['all'][type]);}}if(hooks[name]['all'].length){if(name!== 'all'){push.apply(registrations, hooks[name]['all']);}}if(hooks['all']['all'].length){push.apply(registrations, hooks['all']['all']);}registrations.sort(function(a, b){if(a.priority< b.priority){return-1;}if(a.priority > b.priority){return 1;}return(a.index< b.index)?-1:1;});$.each(registrations, function(i, registration){var handler_return=registration.handler(name, type, params, value);if(handler_return!=null){value=handler_return;}});return value;}};})
$data value
Definition: default.php:27
return['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/security_txt'=>['access'=> 'admin'],'admin/security/settings'=>['access'=> 'admin'],'admin/security/regenerate_site_secret'=>['access'=> 'admin'],'admin/site/cache/invalidate'=>['access'=> 'admin'],'admin/site/flush_cache'=>['access'=> 'admin'],'admin/site/icons'=>['access'=> 'admin'],'admin/site/set_maintenance_mode'=>['access'=> 'admin'],'admin/site/set_robots'=>['access'=> 'admin'],'admin/site/theme'=>['access'=> 'admin'],'admin/site/unlock_upgrade'=>['access'=> 'admin'],'admin/site/settings'=>['access'=> 'admin'],'admin/upgrade'=>['access'=> 'admin'],'admin/upgrade/reset'=>['access'=> 'admin'],'admin/user/ban'=>['access'=> 'admin'],'admin/user/bulk/ban'=>['access'=> 'admin'],'admin/user/bulk/delete'=>['access'=> 'admin'],'admin/user/bulk/unban'=>['access'=> 'admin'],'admin/user/bulk/validate'=>['access'=> 'admin'],'admin/user/change_email'=>['access'=> 'admin'],'admin/user/delete'=>['access'=> 'admin'],'admin/user/login_as'=>['access'=> 'admin'],'admin/user/logout_as'=>[],'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'],'annotation/delete'=>[],'avatar/upload'=>[],'comment/save'=>[],'diagnostics/download'=>['access'=> 'admin'],'entity/delete'=>[],'entity/mute'=>[],'entity/subscribe'=>[],'entity/unmute'=>[],'entity/unsubscribe'=>[],'login'=>['access'=> 'logged_out'],'logout'=>[],'notifications/mute'=>['access'=> 'public'],'plugins/settings/remove'=>['access'=> 'admin'],'plugins/settings/save'=>['access'=> 'admin'],'plugins/usersettings/save'=>[],'register'=>['access'=> 'logged_out','middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],],'river/delete'=>[],'settings/notifications'=>[],'settings/notifications/subscriptions'=>[],'user/changepassword'=>['access'=> 'public'],'user/requestnewpassword'=>['access'=> 'public'],'useradd'=>['access'=> 'admin'],'usersettings/save'=>[],'widgets/add'=>[],'widgets/delete'=>[],'widgets/move'=>[],'widgets/save'=>[],]
Definition: actions.php:70
$site name
Definition: settings.php:15
var elgg
Definition: elgglib.js:4