This forces an inheriting class to implement the method or it will throw an error.AbstractClass.prototype.toBeImplemented = elgg.abstractMethod;
elgg.nullFunction =
function() {};
elgg.abstractMethod =
function() {
throw new Error("Oops... you forgot to implement an abstract method!");
};
elgg.extend = jQuery.extend;
elgg.isArray = jQuery.isArray;
elgg.isFunction = jQuery.isFunction;
elgg.isPlainObject = jQuery.isPlainObject;
elgg.isString =
function(val) {
return typeof val === 'string';
};
elgg.isNumber =
function(val) {
return typeof val === 'number';
};
elgg.isObject =
function(val) {
return typeof val === 'object';
};
elgg.isUndefined =
function(val) {
return val === undefined;
};
elgg.isNull =
function(val) {
return val === null;
};
elgg.isNullOrUndefined =
function(val) {
return val == null;
};
elgg.assertTypeOf =
function(
type, val) {
if (typeof val !==
type) {
throw new TypeError("Expecting param of " +
arguments.caller +
"to be a(n) " +
type +
"." +
" Was actually a(n) " + typeof val + ".");
}
};
elgg.require =
function(pkg) {
elgg.assertTypeOf(
'string', pkg);
var parts = pkg.split('.'),
for (i = 0; i < parts.length; i += 1) {
cur = cur[part];
if (
elgg.isUndefined(cur)) {
throw new Error("Missing package: " + pkg);
}
}
};
elgg.provide =
function(pkg, opt_context) {
elgg.assertTypeOf(
'string', pkg);
var parts = pkg.split('.'),
context = opt_context ||
elgg.global,
for (i = 0; i < parts.length; i += 1) {
context[part] = context[part] || {};
context = context[part];
}
};
elgg.inherit =
function(Child, Parent) {
Child.prototype = new Parent();
Child.prototype.constructor = Child;
};
elgg.normalize_url =
function(
url) {
url.scheme =
url.scheme.toLowerCase();
}
if (
url.scheme ==
'http' ||
url.scheme ==
'https') {
return false;
}
if (!(
new RegExp(
"^([a-zA-Z0-9][a-zA-Z0-9\\-\\.]*)$",
"i")).test(
url.host) ||
url.host.charAt(-1) ==
'.') {
return false;
}
}
if (!
url.scheme || !
url.host &&
url.scheme !=
'mailto' &&
url.scheme !=
'news' &&
url.scheme !=
'file') {
return false;
}
return true;
};
if (
url.indexOf(
'http:') === 0 ||
url.indexOf(
'https:') === 0 ||
url.indexOf(
'javascript:') === 0 ||
url.indexOf(
'mailto:') === 0 ) {
}
else if (validate(
url)) {
}
else if ((
new RegExp(
"^(\\#|\\?|//)",
"i")).test(
url)) {
}
else if ((
new RegExp(
"^[^\/]*\\.php(\\?.*)?$",
"i")).test(
url)) {
return elgg.config.wwwroot +
url.ltrim(
'/');
}
else if ((
new RegExp(
"^[^/]*\\.",
"i")).test(
url)) {
}
else {
return elgg.config.wwwroot +
url.ltrim(
'/');
}
};
elgg.system_messages =
function(msgs, delay,
type) {
if (
elgg.isUndefined(msgs)) {
return;
}
var classes = ['elgg-message'],
messages_html = [],
appendMessage = function(msg) {
messages_html.push('<li class="' + classes.join(' ') + '"><p>' + msg + '</p></li>');
},
systemMessages = $('ul.elgg-system-messages'),
delay = parseInt(delay || 6000, 10);
if (isNaN(delay) || delay <= 0) {
delay = 6000;
}
if (!
elgg.isArray(msgs)) {
msgs = [msgs];
}
classes.push('elgg-state-error');
} else {
classes.push('elgg-state-success');
}
msgs.forEach(appendMessage);
$(messages_html.join('')).appendTo(systemMessages)
.animate({opacity: '1.0'}, delay).fadeOut('slow');
} else {
$(messages_html.join('')).appendTo(systemMessages);
}
};
elgg.system_message =
function(msgs, delay) {
elgg.system_messages(msgs, delay,
"message");
};
elgg.register_error =
function(errors, delay) {
elgg.system_messages(errors, delay,
"error");
};
elgg.deprecated_notice =
function(msg, dep_version) {
if (
elgg.is_admin_logged_in()) {
var parts =
elgg.release.split(
'.');
var elgg_major_version = parseInt(parts[0], 10);
var elgg_minor_version = parseInt(parts[1], 10);
var dep_major_version = Math.floor(dep_version);
var dep_minor_version = 10 * (dep_version - dep_major_version);
msg = "Deprecated in Elgg " + dep_version + ": " + msg;
if ((dep_major_version < elgg_major_version) || (dep_minor_version < elgg_minor_version)) {
elgg.register_error(msg);
} else {
if (typeof console !== "undefined") {
console.warn(msg);
}
}
}
};
location.href =
elgg.normalize_url(
url);
};
elgg.parse_url =
function(
url, component, expand) {
expand = expand || false;
component = component || false;
var re_str =
'^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?://)?'
+ '((?:(([^:@]*)(?::([^:@]*))?)?@)?'
+ '([^:/?#]*)(?::(\\d*))?)'
+ '(((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[?#]|$)))*/?)?([^?#/]*))'
+ '(?:\\?([^#]*))?'
+ '(?:#(.*))?)',
keys = {
1: "scheme",
4: "user",
5: "pass",
6: "host",
7: "port",
9: "path",
12: "query",
13: "fragment"
},
results = {};
if (
url.indexOf(
'mailto:') === 0) {
results['scheme'] = 'mailto';
results[
'path'] =
url.replace(
'mailto:',
'');
return results;
}
if (
url.indexOf(
'javascript:') === 0) {
results['scheme'] = 'javascript';
results[
'path'] =
url.replace(
'javascript:',
'');
return results;
}
var re = new RegExp(re_str);
var matches = re.exec(
url);
results[keys[
i]] = matches[
i];
}
}
if (expand && typeof(results['query']) != 'undefined') {
results[
'query'] =
elgg.parse_str(results[
'query']);
}
if (component) {
if (typeof(results[component]) != 'undefined') {
return results[component];
} else {
return false;
}
}
return results;
};
elgg.parse_str =
function(string) {
var params = {},
result,
key,
value,
re = /([^&=]+)=?([^&]*)/g,
re2 = /\[\]$/;
while (result = re.exec(string)) {
key = decodeURIComponent(result[1].replace(/\+/g, ' '));
value = decodeURIComponent(result[2].replace(/\+/g, ' '));
if (re2.test(key)) {
key = key.replace(re2, '');
if (!params[key]) {
params[key] = [];
}
params[key].push(value);
} else {
params[key] = value;
}
}
return params;
};
elgg.getSelectorFromUrlFragment =
function(
url) {
var fragment =
url.split(
'#')[1];
if (fragment) {
if (fragment.indexOf('.') > -1) {
return fragment;
}
else {
return '#' + fragment;
}
}
return '';
};
elgg.push_to_object_array =
function(object, parent, value) {
elgg.assertTypeOf(
'object',
object);
elgg.assertTypeOf(
'string', parent);
if (!(object[parent] instanceof Array)) {
object[parent] = [];
}
if ($.inArray(value, object[parent]) < 0) {
return object[parent].push(value);
}
return false;
};
elgg.is_in_object_array =
function(object, parent, value) {
elgg.assertTypeOf(
'object',
object);
elgg.assertTypeOf(
'string', parent);
return typeof(object[parent]) != 'undefined' && $.inArray(value, object[parent]) >= 0;
};