Elgg  Version 4.3
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
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
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of either verbatim or with modifications and or translated into another language(Hereinafter, translation is included without limitation in the term"modification".) Each licensee is addressed as"you".Activities other than copying