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.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.require =
function(pkg) {
elgg.assertTypeOf(
'string', pkg);
var parts = pkg.split('.'),
part, i;
for (i = 0; i < parts.length; i += 1) {
part = parts[i];
cur = cur[part];
if (cur === undefined) {
throw new Error("Missing package: " + pkg);
}
}
};
elgg.provide =
function(pkg, opt_context) {
var parts,
context = opt_context ||
elgg.global,
part, i;
if (Array.isArray(pkg)) {
parts = pkg;
} else {
elgg.assertTypeOf(
'string', pkg);
parts = pkg.split('.');
}
for (i = 0; i < parts.length; i += 1) {
part = parts[i];
context[part] = context[part] || {};
context = context[part];
}
};
elgg.provide(
'elgg.config');
elgg.provide(
'elgg.session');
elgg.provide(
'elgg.security.token');
elgg.provide(
'elgg.config.translations');
elgg.provide(
'elgg.config.hooks');
elgg.provide(
'elgg.config.instant_hooks');
elgg.provide(
'elgg.config.triggered_hooks');
var cookies = [],
cookie = [], i = 0, date, valid =
true;
if (
name === undefined) {
return document.cookie;
}
if (
value === undefined) {
if (document.cookie && document.cookie !== '') {
cookies = document.cookie.split(';');
for (i = 0; i < cookies.length; i += 1) {
return decodeURIComponent(
cookie[1]);
}
}
}
return undefined;
}
options = options || {};
options.expires = -1;
}
if (options.expires) {
if (typeof options.expires === 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else if (options.expires.toUTCString) {
date = options.expires;
}
if (date) {
cookies.push('expires=' + date.toUTCString());
}
}
if (options.path) {
cookies.push('path=' + (options.path));
}
if (options.domain) {
cookies.push('domain=' + (options.domain));
}
if (options.secure) {
cookies.push('secure');
}
document.cookie = cookies.join('; ');
};
elgg.system_messages =
function(msgs, delay, type) {
require([
'elgg/system_messages'],
function(messages) {
messages.showMessage(msgs, delay, type);
});
};
elgg.clear_system_messages =
function() {
require([
'elgg/system_messages'],
function(messages) {
messages.clear();
});
};
elgg.system_message =
function(msgs, delay) {
require([
'elgg/system_messages'],
function(messages) {
messages.success(msgs, delay);
});
};
elgg.register_error =
function(errors, delay) {
require([
'elgg/system_messages'],
function(messages) {
messages.error(errors, delay);
});
};
elgg.security.addToken =
function (data) {
var security =
require(
'elgg/security');
return security.addToken(data);
};
elgg.inherit =
function(Child, Parent) {
Child.prototype = new Parent();
Child.prototype.constructor = Child;
};
elgg.ElggEntity =
function(o) {
$.extend(this, o);
};
elgg.ElggUser =
function(o) {
elgg.ElggEntity.call(
this, o);
};
elgg.ElggUser.prototype.isAdmin =
function() {
return this.admin;
};
}
elgg.get_logged_in_user_entity =
function() {
return elgg.session.user;
};
elgg.get_page_owner_guid =
function() {
return elgg.page_owner ?
elgg.page_owner.guid : 0;
};
elgg.add_translation =
function(lang, translations) {
i18n.addTranslation(lang, translations);
};
elgg.get_language =
function() {
return elgg.config.current_language;
};
};
elgg.ui.registerTogglableMenuItems =
function(menuItemNameA, menuItemNameB) {
require([
'navigation/menu/elements/item_toggle'],
function() {
menuItemNameA = menuItemNameA.replace('_', '-');
menuItemNameB = menuItemNameB.replace('_', '-');
$('.elgg-menu-item-' + menuItemNameA + ' a').not('[data-toggle]').attr('data-toggle', menuItemNameB);
$('.elgg-menu-item-' + menuItemNameB + ' a').not('[data-toggle]').attr('data-toggle', menuItemNameA);
});
};