26 elgg.nullFunction =
function() {};
35 elgg.abstractMethod =
function() {
36 throw new Error(
"Oops... you forgot to implement an abstract method!");
42 elgg.extend = jQuery.extend;
53 elgg.isArray = jQuery.isArray;
64 elgg.isFunction = jQuery.isFunction;
75 elgg.isPlainObject = jQuery.isPlainObject;
84 elgg.isString =
function(val) {
85 return typeof val ===
'string';
95 elgg.isNumber =
function(val) {
96 return typeof val ===
'number';
109 elgg.isObject =
function(val) {
110 return typeof val ===
'object';
120 elgg.isUndefined =
function(val) {
121 return val === undefined;
142 elgg.isNullOrUndefined =
function(val) {
152 if (typeof val !==
type) {
153 throw new TypeError(
"Expecting param of " +
154 arguments.caller +
"to be a(n) " +
type +
"." +
155 " Was actually a(n) " + typeof val +
".");
165 elgg.assertTypeOf(
'string', pkg);
167 var parts = pkg.split(
'.'),
171 for (i = 0; i < parts.length; i += 1) {
174 if (
elgg.isUndefined(cur)) {
175 throw new Error(
"Missing package: " + pkg);
199 elgg.provide =
function(pkg, opt_context) {
200 elgg.assertTypeOf(
'string', pkg);
202 var parts = pkg.split(
'.'),
203 context = opt_context ||
elgg.global,
207 for (i = 0; i < parts.length; i += 1) {
209 context[part] = context[part] || {};
210 context = context[part];
237 elgg.inherit =
function(Child, Parent) {
238 Child.prototype =
new Parent();
239 Child.prototype.constructor = Child;
256 elgg.normalize_url =
function(
url) {
258 elgg.assertTypeOf(
'string',
url);
260 function validate(
url) {
263 url.scheme =
url.scheme.toLowerCase();
265 if (
url.scheme ==
'http' ||
url.scheme ==
'https') {
270 if (!(
new RegExp(
"^([a-zA-Z0-9][a-zA-Z0-9\\-\\.]*)$",
"i")).test(
url.host) ||
url.host.charAt(-1) ==
'.') {
275 if (!
url.scheme || !
url.host &&
url.scheme !=
'mailto' &&
url.scheme !=
'news' &&
url.scheme !=
'file') {
282 if (
url.indexOf(
'http:') === 0 ||
283 url.indexOf(
'https:') === 0 ||
284 url.indexOf(
'javascript:') === 0 ||
285 url.indexOf(
'mailto:') === 0 ) {
290 else if (validate(
url)) {
296 else if ((
new RegExp(
"^(\\#|\\?|//)",
"i")).test(
url)) {
304 else if ((
new RegExp(
"^[^\/]*\\.php(\\?.*)?$",
"i")).test(
url)) {
305 return elgg.config.wwwroot +
url.ltrim(
'/');
309 else if ((
new RegExp(
"^[^/]*\\.",
"i")).test(
url)) {
310 return 'http://' +
url;
317 return elgg.config.wwwroot +
url.ltrim(
'/');
329 elgg.system_messages =
function(msgs, delay,
type) {
330 if (
elgg.isUndefined(msgs)) {
334 var classes = [
'elgg-message'],
336 appendMessage =
function(msg) {
337 messages_html.push(
'<li class="' + classes.join(
' ') +
'"><p>' + msg +
'</p></li>');
339 systemMessages = $(
'ul.elgg-system-messages'),
343 delay = parseInt(delay || 6000, 10);
344 if (isNaN(delay) || delay <= 0) {
349 if (!
elgg.isArray(msgs)) {
353 if (
type ===
'error') {
354 classes.push(
'elgg-state-error');
356 classes.push(
'elgg-state-success');
359 msgs.forEach(appendMessage);
361 if (
type !=
'error') {
362 $(messages_html.join(
'')).appendTo(systemMessages)
363 .animate({opacity:
'1.0'}, delay).fadeOut(
'slow');
365 $(messages_html.join(
'')).appendTo(systemMessages);
374 elgg.system_message =
function(msgs, delay) {
375 elgg.system_messages(msgs, delay,
"message");
383 elgg.register_error =
function(errors, delay) {
384 elgg.system_messages(errors, delay,
"error");
393 elgg.deprecated_notice =
function(msg, dep_version) {
394 if (
elgg.is_admin_logged_in()) {
395 var parts =
elgg.release.split(
'.');
396 var elgg_major_version = parseInt(parts[0], 10);
397 var elgg_minor_version = parseInt(parts[1], 10);
398 var dep_major_version = Math.floor(dep_version);
399 var dep_minor_version = 10 * (dep_version - dep_major_version);
401 msg =
"Deprecated in Elgg " + dep_version +
": " + msg;
403 if ((dep_major_version < elgg_major_version) || (dep_minor_version < elgg_minor_version)) {
404 elgg.register_error(msg);
406 if (typeof console !==
"undefined") {
420 location.href =
elgg.normalize_url(
url);
432 elgg.parse_url =
function(
url, component, expand) {
436 expand = expand ||
false;
437 component = component ||
false;
441 '^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?://)?' 443 +
'((?:(([^:@]*)(?::([^:@]*))?)?@)?' 445 +
'([^:/?#]*)(?::(\\d*))?)' 447 +
'(((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[?#]|$)))*/?)?([^?#/]*))' 464 if (
url.indexOf(
'mailto:') === 0) {
465 results[
'scheme'] =
'mailto';
466 results[
'path'] =
url.replace(
'mailto:',
'');
470 if (
url.indexOf(
'javascript:') === 0) {
471 results[
'scheme'] =
'javascript';
472 results[
'path'] =
url.replace(
'javascript:',
'');
476 var re =
new RegExp(re_str);
477 var matches = re.exec(
url);
479 for (var
i in keys) {
481 results[keys[
i]] = matches[
i];
485 if (expand && typeof(results[
'query']) !=
'undefined') {
486 results[
'query'] =
elgg.parse_str(results[
'query']);
490 if (typeof(results[component]) !=
'undefined') {
491 return results[component];
505 elgg.parse_str =
function(string) {
510 re = /([^&=]+)=?([^&]*)/g,
513 while (result = re.exec(
string)) {
514 key = decodeURIComponent(result[1].replace(/\+/g,
' '));
515 value = decodeURIComponent(result[2].replace(/\+/g,
' '));
518 key = key.replace(re2,
'');
522 params[key].push(value);
543 elgg.getSelectorFromUrlFragment =
function(
url) {
544 var fragment =
url.split(
'#')[1];
548 if (fragment.indexOf(
'.') > -1) {
554 return '#' + fragment;
567 elgg.push_to_object_array =
function(object, parent, value) {
568 elgg.assertTypeOf(
'object',
object);
569 elgg.assertTypeOf(
'string', parent);
571 if (!(
object[parent] instanceof Array)) {
575 if ($.inArray(value,
object[parent]) < 0) {
576 return object[parent].push(value);
589 elgg.is_in_object_array =
function(object, parent, value) {
590 elgg.assertTypeOf(
'object',
object);
591 elgg.assertTypeOf(
'string', parent);
593 return typeof(
object[parent]) !=
'undefined' && $.inArray(value,
object[parent]) >= 0;
$CONFIG url
The full URL where Elgg is installed.