Elgg  Version 3.0
init.js.php
Go to the documentation of this file.
1 <?php
8 $modules = [];
9 foreach (elgg_get_plugins() as $plugin) {
10  $id = $plugin->getID();
11  if (elgg_view_exists("boot/$id.js")) {
12  $modules[] = "boot/$id";
13  }
14 }
15 
16 ?>
17 //<script>
18 define(function (require) {
19  var Plugin = require('elgg/Plugin');
20  var elgg = require('elgg');
21 
22  var modules = [];
23  var i;
24 
25  // We need literal require('boot/example'); statements. We can't use async require in here because we promise to
26  // not return this module until all boot plugins are loaded.
27 <?php foreach ($modules as $name) { ?>
28  modules.push({
29  plugin: require(<?= json_encode($name, JSON_UNESCAPED_SLASHES) ?>),
30  name: <?= json_encode($name, JSON_UNESCAPED_SLASHES) ?>
31  });
32 <?php } ?>
33 
34  for (i = 0; i < modules.length; i++) {
35  if (modules[i].plugin instanceof Plugin) {
36  modules[i].plugin._init();
37  } else {
38  console.error("Boot module boot/" + modules[i].name + " did not return an instance of Plugin (from elgg/Plugin)");
39  }
40  }
41 
42  elgg.trigger_hook('init', 'system');
43 });
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:205
$modules
Boot all the plugins and trigger the [init, system] hook.
Definition: init.js.php:8
$plugin
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$id
River item delete action.
Definition: delete.php:6
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
elgg_get_plugins($status= 'active')
Returns an ordered list of plugins.
Definition: plugins.php:76
$site name
define(function(require){var $=require('jquery');var elgg=require('elgg');var spinner=require('elgg/spinner');var Ajax=require('elgg/Ajax');var ajax=new Ajax();function init(){initPluginReordering();$(document).on('click', '.elgg-admin-plugins-categories a', filterPluginCategory);$(document).on('click', '.elgg-plugins-toggle', toggleAllPlugins);$(document).on('click', '.elgg-plugin-state-change', toggleSinglePlugin);$(document).on('mouseenter', '.elgg-plugin-details-screenshots.elgg-plugin-screenshot', showPluginScreenshot);};function freezePlugins(){$('#elgg-plugin-list-cover').css('display', 'block');};function unfreezePlugins(){$('#elgg-plugin-list-cover').css('display', 'none');};function initPluginReordering(){$('#elgg-plugin-list > ul').sortable({items: 'li:has(>.elgg-state-draggable)', handle: '.elgg-body', forcePlaceholderSize:true, placeholder: 'elgg-plugin-placeholder', opacity:0.8, revert:500, stop:movePlugin});};function toggleSinglePlugin(e){freezePlugins();e.preventDefault();ajax.action(this.href).done(function(output, statusText, jqXHR){if(jqXHR.AjaxData.status==-1){location.reload();return;}ajax.path('admin_plugins_refresh').done(function(output){$('#elgg-plugin-list').html(output.list);$('.elgg-sidebar').html(output.sidebar);$(".elgg-admin-plugins-categories > li.elgg-state-selected > a").trigger('click');initPluginReordering();unfreezePlugins();});});};function toggleAllPlugins(e){e.preventDefault();if(!confirm(elgg.echo('question:areyousure'))){return;}freezePlugins();var guids=[], state=$(this).data('desiredState'), find_state=state== 'active'? 'inactive': 'active';$('.elgg-plugin.elgg-state-'+find_state+ ':visible').each(function(){var guid=$(this).data('guid');if(guid){guids.push(guid);}});if(!guids.length){elgg.register_error(elgg.echo('admin:plugins:already:'+state));unfreezePlugins();return;}spinner.start();var $form=$('< form method="post"/>');$form.prop('action', elgg.security.addToken(this.href));$form.append('< input type="hidden"name="guids"value="' + guids.join(',') + '"/>');$form.appendTo("body").submit();};function movePlugin(e, ui){freezePlugins();var pluginGuid=ui.item.attr('id');pluginGuid=pluginGuid.replace('elgg-object-', '');elgg.action('admin/plugins/set_priority',{data:{plugin_guid:pluginGuid, priority:ui.item.index()+1}, success:function(){var priorityDep=new RegExp(elgg.echo('ElggPlugin:Dependencies:Priority'));ui.item.siblings().andSelf().each(function(){if(priorityDep.test($(this).find('.elgg-dependency-requires').text())){updatePluginView($(this));}});unfreezePlugins();}});};function updatePluginView(pluginView){var pluginGuid=pluginView.attr('id');pluginGuid=pluginGuid.replace('elgg-object-', '');elgg.get({url:elgg.config.wwwroot+"ajax/view/object/plugin/full", dataType:"html", cache:false, data:{guid:pluginGuid, display_reordering:true}, success:function(htmlData){if(htmlData.length > 0){pluginView.html(htmlData);}}});};function filterPluginCategory(e){e.preventDefault();$(".elgg-admin-plugins-categories > li").removeClass("elgg-state-selected");$(".elgg-plugin").hide();$(".elgg-plugin-category-"+$(this).attr("rel")).show();$(this).closest('li').addClass("elgg-state-selected");};function showPluginScreenshot(){$(this).parent().find(".elgg-plugin-screenshot").removeClass("elgg-state-selected");$(this).addClass("elgg-state-selected");$(".elgg-plugin-details-screenshots > div > img").hide();$(".elgg-plugin-details-screenshots > div > img[rel='"+$(this).attr("rel")+"']").show();};init();})
var elgg
Definition: elgglib.js:4