Elgg  Version 2.3
elgg.js.php
Go to the documentation of this file.
1 <?php
7 
8 // this warning is due to the change in JS boot order in Elgg 1.9
9 echo <<<JS
10 if (typeof elgg != 'object') {
11  throw new Error('elgg configuration object is not defined! You must include the js/initialize_elgg view in html head before JS library files!');
12 }
13 
14 JS;
15 
16 // For backwards compatibility...
17 echo elgg_view('sprintf.js');
18 
19 // We use a named AMD module and inline it here instead of using an async call.
20 // This allows us to bootstrap elgg.ui.widgets library at runtime, without having
21 // to wait for the module to load. This is necessary to ensure BC for plugins that
22 // rely on elgg.ui.widgets methods to be available at system init.
23 // @todo: remove in 3.x and use async calls
24 echo elgg_view('elgg/widgets.js');
25 
26 // In 3.0 this will be required by elgg/lightbox, but in 2.x we have to worry about
27 // legacy code that expects $.colorbox to be ready synchronously. To avoid inlining
28 // in both lightbox.js and elgg/lightbox, we do so here and define it as a module.
29 echo elgg_view('jquery.colorbox.js');
30 ?>
31 define('jquery.colorbox');
32 <?php
33 // We use named AMD modules and inline them here in order to save HTTP requests,
34 // as these modules will be required on each page
35 echo elgg_view('elgg/popup.js');
36 echo elgg_view('elgg/lightbox.js');
37 
38 $elggDir = \Elgg\Application::elggDir();
39 $files = array(
40  // these must come first
41  $elggDir->getPath("js/lib/elgglib.js"),
42 
43  // class definitions
44  $elggDir->getPath("js/classes/ElggEntity.js"),
45  $elggDir->getPath("js/classes/ElggUser.js"),
46  $elggDir->getPath("js/classes/ElggPriorityList.js"),
47 
48  //libraries
49  $elggDir->getPath("js/lib/prototypes.js"),
50  $elggDir->getPath("js/lib/hooks.js"),
51  $elggDir->getPath("js/lib/security.js"),
52  $elggDir->getPath("js/lib/languages.js"),
53  $elggDir->getPath("js/lib/ajax.js"),
54  $elggDir->getPath("js/lib/session.js"),
55  $elggDir->getPath("js/lib/pageowner.js"),
56  $elggDir->getPath("js/lib/configuration.js"),
57  $elggDir->getPath("js/lib/comments.js"),
58 
59  //ui
60  $elggDir->getPath("js/lib/ui.js"),
61  $elggDir->getPath("js/lib/ui.widgets.js"),
62 );
63 
64 
65 foreach ($files as $file) {
66  readfile($file);
67  // putting a new line between the files to address https://github.com/elgg/elgg/issues/3081
68  echo "\n";
69 }
70 
71 ?>
72 //<script>
73 <?php foreach (_elgg_get_js_site_data() as $expression => $value): ?>
74 <?= $expression ?> = <?= json_encode($value) ?>;
75 <?php endforeach; ?>
76 
77 // page data overrides site data
78 $.extend(elgg.data, elgg._data);
79 delete elgg._data;
80 
81 // jQuery and UI must be loaded sync in 2.x but modules should depend on these AMD modules
82 define('jquery', function () {
83  return jQuery;
84 });
85 define('jquery-ui');
86 
87 // The datepicker language modules depend on "../datepicker", so to avoid RequireJS from
88 // trying to load that, we define it manually here. The lang modules have names like
89 // "jquery-ui/i18n/datepicker-LANG.min" and these views are mapped in /views.php
90 define('jquery-ui/datepicker', jQuery.datepicker);
91 
92 define('elgg', ['jquery', 'languages/' + elgg.get_language()], function($, translations) {
93  elgg.add_translation(elgg.get_language(), translations);
94 
95  return elgg;
96 });
97 
98 require(['elgg']); // Forces the define() function to always run
99 
100 // Process queue. We have to wait until now because many modules depend on 'elgg' and we can't load
101 // it asynchronously.
102 if (!window._require_queue) {
103  if (window.console) {
104  console.log('Elgg\'s require() shim is not defined. Do not override the view "page/elements/head".');
105  }
106 } else {
107  while (_require_queue.length) {
108  require.apply(null, _require_queue.shift());
109  }
110  delete window._require_queue;
111 }
112 
113 elgg.trigger_hook('boot', 'system');
114 
115 require(['elgg/init', 'elgg/ready']);
116 
117 <?php
118 if (_elgg_view_may_be_altered('lightbox/settings.js', 'lightbox/settings.js.php')) {
119  elgg_deprecated_notice('lightbox/settings.js view has been deprecated. Use "getOptions", "ui.lightbox" ' .
120  'JS plugin hook or data-colorbox-opts attribute instead', '2.2');
121  ?>
122  require(['elgg'], function(elgg) {
123  elgg.provide('elgg.ui.lightbox');
124  <?= elgg_view('lightbox/settings.js') ?>
125  });
126  <?php
127 }
128 ?>
129 
130 // We need to ensure bindings take place
131 require(['elgg/lightbox']);
if(!array_key_exists($filename, $text_files)) $file
_elgg_view_may_be_altered($view, $path)
Is there a chance a plugin is altering this view?
Definition: views.php:1800
$_ELGG translations
String translations for the current language.
Definition: config.php:333
$value
Definition: longtext.php:42
_elgg_get_js_site_data()
Get the site data to be merged into "elgg" in elgg.js.
Definition: views.php:1990
elgg echo
Translates a string.
Definition: languages.js:48
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
global $CONFIG
Core Elgg JavaScript file.
Definition: elgg.js.php:6
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:336
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
elgg global
Pointer to the global context.
Definition: elgglib.js:12
const elgg
Definition: elgg.js.php:92
static elggDir()
Returns a directory that points to the root of Elgg, but not necessarily the install root...
define(function(require){var $=require('jquery');$(document).on('change', '#elgg-river-selector', function(){var url=window.location.href;if(window.location.search.length){url=url.substring(0, url.indexOf('?'));}url+= '?'+$(this).val();window.location.href=url;});})
Initiates page reload when river selector value changes core/river/filter.
foreach($resources as $id=> $href) if(!empty($resources_html)) $files
Definition: details.php:141
_require_queue
Definition: head.php:38