Elgg  Version 4.x
deprecated.js
Go to the documentation of this file.
1 
9 elgg.global = this;
10 
18 elgg.ACCESS_PRIVATE = 0;
19 
27 elgg.nullFunction = function() {};
28 
38 elgg.abstractMethod = function() {
39  throw new Error("Oops... you forgot to implement an abstract method!");
40 };
41 
47 elgg.extend = jQuery.extend;
48 
60 elgg.isArray = jQuery.isArray;
61 
73 elgg.isFunction = jQuery.isFunction;
74 
86 elgg.isPlainObject = jQuery.isPlainObject;
87 
97 elgg.isString = function(val) {
98  return typeof val === 'string';
99 };
100 
110 elgg.isNumber = function(val) {
111  return typeof val === 'number';
112 };
113 
126 elgg.isObject = function(val) {
127  return typeof val === 'object';
128 };
129 
139 elgg.isUndefined = function(val) {
140  return val === undefined;
141 };
142 
152 elgg.isNull = function(val) {
153  return val === null;
154 };
155 
165 elgg.isNullOrUndefined = function(val) {
166  return val == null;
167 };
168 
176 elgg.require = function(pkg) {
177  elgg.assertTypeOf('string', pkg);
178 
179  var parts = pkg.split('.'),
180  cur = elgg.global,
181  part, i;
182 
183  for (i = 0; i < parts.length; i += 1) {
184  part = parts[i];
185  cur = cur[part];
186  if (cur === undefined) {
187  throw new Error("Missing package: " + pkg);
188  }
189  }
190 };
191 
226 elgg.provide = function(pkg, opt_context) {
227  var parts,
228  context = opt_context || elgg.global,
229  part, i;
230 
231  if (Array.isArray(pkg)) {
232  parts = pkg;
233  } else {
234  elgg.assertTypeOf('string', pkg);
235  parts = pkg.split('.');
236  }
237 
238  for (i = 0; i < parts.length; i += 1) {
239  part = parts[i];
240  context[part] = context[part] || {};
241  context = context[part];
242  }
243 };
244 
245 // register provides for backwards compatibility
246 elgg.provide('elgg.config');
247 elgg.provide('elgg.session');
248 elgg.provide('elgg.ui');
249 elgg.provide('elgg.security.token');
250 elgg.provide('elgg.config.translations');
251 elgg.provide('elgg.config.hooks');
252 elgg.provide('elgg.config.instant_hooks');
253 elgg.provide('elgg.config.triggered_hooks');
254 
270 elgg.session.cookie = function(name, value, options) {
271  var cookies = [], cookie = [], i = 0, date, valid = true;
272 
273  //elgg.session.cookie()
274  if (name === undefined) {
275  return document.cookie;
276  }
277 
278  //elgg.session.cookie(name)
279  if (value === undefined) {
280  if (document.cookie && document.cookie !== '') {
281  cookies = document.cookie.split(';');
282  for (i = 0; i < cookies.length; i += 1) {
283  cookie = jQuery.trim(cookies[i]).split('=');
284  if (cookie[0] === name) {
285  return decodeURIComponent(cookie[1]);
286  }
287  }
288  }
289  return undefined;
290  }
291 
292  // elgg.session.cookie(name, value[, opts])
293  options = options || {};
294 
295  if (value === null) {
296  value = '';
297  options.expires = -1;
298  }
299 
300  cookies.push(name + '=' + value);
301 
302  if (options.expires) {
303  if (typeof options.expires === 'number') {
304  date = new Date();
305  date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
306  } else if (options.expires.toUTCString) {
307  date = options.expires;
308  }
309 
310  if (date) {
311  cookies.push('expires=' + date.toUTCString());
312  }
313  }
314 
315  // CAUTION: Needed to parenthesize options.path and options.domain
316  // in the following expressions, otherwise they evaluate to undefined
317  // in the packed version for some reason.
318  if (options.path) {
319  cookies.push('path=' + (options.path));
320  }
321 
322  if (options.domain) {
323  cookies.push('domain=' + (options.domain));
324  }
325 
326  if (options.secure) {
327  cookies.push('secure');
328  }
329 
330  document.cookie = cookies.join('; ');
331 };
332 
342 elgg.system_messages = function(msgs, delay, type) {
343  require(['elgg/system_messages'], function(messages) {
344  messages.showMessage(msgs, delay, type);
345  });
346 };
347 
352 elgg.clear_system_messages = function() {
353  require(['elgg/system_messages'], function(messages) {
354  messages.clear();
355  });
356 };
357 
364 elgg.system_message = function(msgs, delay) {
365  require(['elgg/system_messages'], function(messages) {
366  messages.success(msgs, delay);
367  });
368 };
369 
376 elgg.register_error = function(errors, delay) {
377  require(['elgg/system_messages'], function(messages) {
378  messages.error(errors, delay);
379  });
380 };
381 
389 elgg.security.addToken = function (data) {
390  var security = require('elgg/security');
391  return security.addToken(data);
392 };
393 
418 elgg.inherit = function(Child, Parent) {
419  Child.prototype = new Parent();
420  Child.prototype.constructor = Child;
421 };
422 
437 elgg.ElggEntity = function(o) {
438  $.extend(this, o);
439 };
440 
453 elgg.ElggUser = function(o) {
454  elgg.ElggEntity.call(this, o);
455 };
456 
457 elgg.inherit(elgg.ElggUser, elgg.ElggEntity);
458 
468 elgg.ElggUser.prototype.isAdmin = function() {
469  return this.admin;
470 };
471 
472 // This just has to happen after ElggUser is defined, however it's probably
473 // better to have this procedural code here than in ElggUser.js
474 if (elgg.session.user) {
475  elgg.session.user = new elgg.ElggUser(elgg.session.user);
476 }
477 
484 elgg.get_logged_in_user_entity = function() {
485  return elgg.session.user;
486 };
487 
492 elgg.get_page_owner_guid = function() {
493  return elgg.page_owner ? elgg.page_owner.guid : 0;
494 };
495 
501 elgg.add_translation = function(lang, translations) {
502  var i18n = require('elgg/i18n');
503  i18n.addTranslation(lang, translations);
504 };
505 
511 elgg.get_language = function() {
512  return elgg.config.current_language;
513 };
514 
530 elgg.echo = function(key, argv, language) {
531  var i18n = require('elgg/i18n');
532  return i18n.echo(key, argv, language);
533 };
534 
543 elgg.ui.registerTogglableMenuItems = function(menuItemNameA, menuItemNameB) {
544  require(['navigation/menu/elements/item_toggle'], function() {
545  menuItemNameA = menuItemNameA.replace('_', '-');
546  menuItemNameB = menuItemNameB.replace('_', '-');
547 
548  $('.elgg-menu-item-' + menuItemNameA + ' a').not('[data-toggle]').attr('data-toggle', menuItemNameB);
549  $('.elgg-menu-item-' + menuItemNameB + ' a').not('[data-toggle]').attr('data-toggle', menuItemNameA);
550  });
551 };
$site name
Definition: settings.php:21
$data value
Definition: default.php:27
$new_user language
Definition: useradd.php:58
elgg session cookie
Helper function for setting cookies.
Definition: deprecated.js:270
elgg require
Throw an error if the required package isn&#39;t present.
Definition: deprecated.js:176
var elgg
Definition: elgglib.js:4