Elgg  Version 2.3
Namespaces | Variables
elgglib.js File Reference

Go to the source code of this file.

Namespaces

 Singleton
 object for holding the Elgg javascript library
 

Variables

var elgg = elgg || {}
 
elgg global = this
 Pointer to the global context. More...
 
elgg ACCESS_PRIVATE = 0
 Duplicate of the server side ACCESS_PRIVATE access level. More...
 
elgg nullFunction = function() {}
 Convenience reference to an empty function. More...
 
elgg abstractMethod
 
elgg extend = jQuery.extend
 Merges two or more objects together and returns the result. More...
 
elgg isArray = jQuery.isArray
 Check if the value is an array. More...
 
elgg isFunction = jQuery.isFunction
 Check if the value is a function. More...
 
elgg isPlainObject = jQuery.isPlainObject
 Check if the value is a "plain" object (i.e., created by {} or new Object()) More...
 
elgg isString
 Check if the value is a string. More...
 
elgg isNumber
 Check if the value is a number. More...
 
elgg isObject
 Check if the value is an object. More...
 
elgg isUndefined
 Check if the value is undefined. More...
 
elgg isNull
 Check if the value is null. More...
 
elgg isNullOrUndefined
 Check if the value is either null or undefined. More...
 
elgg assertTypeOf
 Throw an exception of the type doesn't match. More...
 
elgg require
 Throw an error if the required package isn't present. More...
 
elgg provide
 
elgg inherit
 
elgg normalize_url
 Converts shorthand urls to absolute urls. More...
 
elgg system_message
 Wrapper function for system_messages. More...
 
elgg register_error
 Wrapper function for system_messages. More...
 
elgg deprecated_notice
 Informs admin users via a console message about use of a deprecated function or capability. More...
 
elgg forward
 Meant to mimic the php forward() function by simply redirecting the user to another page. More...
 
elgg parse_url
 Parse a URL into its parts. More...
 
elgg parse_str
 Returns an object with key/values of the parsed query string. More...
 
elgg getSelectorFromUrlFragment
 Returns a jQuery selector from a URL's fragement. More...
 
elgg push_to_object_array
 Adds child to object[parent] array. More...
 
elgg is_in_object_array
 Tests if object[parent] contains child. More...
 

Variable Documentation

elgg abstractMethod
Initial value:
= function() {
throw new Error("Oops... you forgot to implement an abstract method!");
}

Definition at line 35 of file elgglib.js.

elgg ACCESS_PRIVATE = 0

Duplicate of the server side ACCESS_PRIVATE access level.

This is a temporary hack to prevent having to mix up js and PHP in js views.

Definition at line 19 of file elgglib.js.

elgg assertTypeOf
Initial value:
= 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 + ".");
}
}
list style type
Definition: admin.css.php:808

Throw an exception of the type doesn't match.

Definition at line 151 of file elgglib.js.

elgg deprecated_notice
Initial value:
= function(msg, dep_version) {
if (elgg.is_admin_logged_in()) {
msg = "Deprecated in Elgg " + dep_version + ": " + msg;
if (typeof console !== "undefined") {
console.info(msg);
}
}
}
var elgg
Definition: elgglib.js:4

Informs admin users via a console message about use of a deprecated function or capability.

Parameters
{String}msg The deprecation message to display
{String}dep_version The version the function was deprecated for
Since
1.9

Definition at line 410 of file elgglib.js.

var elgg = elgg || {}

Definition at line 4 of file elgglib.js.

elgg extend = jQuery.extend

Merges two or more objects together and returns the result.

Definition at line 42 of file elgglib.js.

elgg forward
Initial value:
= function(url) {
var dest = elgg.normalize_url(url);
if (dest == location.href) {
location.reload();
}
$(window).on('hashchange', function () {
location.reload();
});
location.href = dest;
}
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 on
Definition: GPL-LICENSE.txt:43
if(!$site) if(!($site instanceof ElggSite)) $site url
var elgg
Definition: elgglib.js:4

Meant to mimic the php forward() function by simply redirecting the user to another page.

Parameters
{String}url The url to forward to
Examples:
/root/Elgg/engine/lib/views.php.

Definition at line 425 of file elgglib.js.

elgg getSelectorFromUrlFragment
Initial value:
= function(url) {
var fragment = url.split('#')[1];
if (fragment) {
if (fragment.indexOf('.') > -1) {
return fragment;
}
else {
return '#' + fragment;
}
}
return '';
}
if(!$site) if(!($site instanceof ElggSite)) $site url

Returns a jQuery selector from a URL's fragement.

Defaults to expecting an ID.

Examples: http://elgg.org/download.php returns '' http://elgg.org/download.php#id returns #id http://elgg.org/download.php#.class-name return .class-name http://elgg.org/download.php#a.class-name return a.class-name

Parameters
{String}url The URL
Returns
{String} The selector

Definition at line 562 of file elgglib.js.

elgg global = this

Pointer to the global context.

See also
elgg.require
elgg.provide
Examples:
/root/Elgg/engine/lib/views.php.

Definition at line 12 of file elgglib.js.

elgg inherit
Initial value:
= function(Child, Parent) {
Child.prototype = new Parent();
Child.prototype.constructor = Child;
}

Definition at line 254 of file elgglib.js.

elgg is_in_object_array
Initial value:
= function(object, parent, value) {
elgg.assertTypeOf('object', object);
elgg.assertTypeOf('string', parent);
return typeof(object[parent]) != 'undefined' && $.inArray(value, object[parent]) >= 0;
}
var elgg
Definition: elgglib.js:4

Tests if object[parent] contains child.

Parameters
{Object}object The object to add to
{String}parent The parent array to add to.
{*}value The value

Definition at line 608 of file elgglib.js.

elgg isArray = jQuery.isArray

Check if the value is an array.

No sense in reinventing the wheel!

Parameters
{*}val
Returns
boolean

Definition at line 53 of file elgglib.js.

elgg isFunction = jQuery.isFunction

Check if the value is a function.

No sense in reinventing the wheel!

Parameters
{*}val
Returns
boolean

Definition at line 64 of file elgglib.js.

elgg isNull
Initial value:
= function(val) {
return val === null;
}

Check if the value is null.

Parameters
{*}val
Returns
boolean

Definition at line 131 of file elgglib.js.

elgg isNullOrUndefined
Initial value:
= function(val) {
return val == null;
}

Check if the value is either null or undefined.

Parameters
{*}val
Returns
boolean

Definition at line 142 of file elgglib.js.

elgg isNumber
Initial value:
= function(val) {
return typeof val === 'number';
}

Check if the value is a number.

Parameters
{*}val
Returns
boolean

Definition at line 95 of file elgglib.js.

elgg isObject
Initial value:
= function(val) {
return typeof val === 'object';
}

Check if the value is an object.

Note
This returns true for functions and arrays! If you want to return true only for "plain" objects (created using {} or new Object()) use elgg.isPlainObject.
Parameters
{*}val
Returns
boolean

Definition at line 109 of file elgglib.js.

elgg isPlainObject = jQuery.isPlainObject

Check if the value is a "plain" object (i.e., created by {} or new Object())

No sense in reinventing the wheel!

Parameters
{*}val
Returns
boolean

Definition at line 75 of file elgglib.js.

elgg isString
Initial value:
= function(val) {
return typeof val === 'string';
}

Check if the value is a string.

Parameters
{*}val
Returns
boolean

Definition at line 84 of file elgglib.js.

elgg isUndefined
Initial value:
= function(val) {
return val === undefined;
}

Check if the value is undefined.

Parameters
{*}val
Returns
boolean

Definition at line 120 of file elgglib.js.

elgg normalize_url

Converts shorthand urls to absolute urls.

If the url is already absolute or protocol-relative, no change is made.

elgg.normalize_url(''); // 'http://my.site.com/' elgg.normalize_url('dashboard'); // 'http://my.site.com/dashboard' elgg.normalize_url('http://google.com/'); // no change elgg.normalize_url('//google.com/'); // no change

Parameters
{String}url The url to normalize
Returns
{String} The extended url

Definition at line 272 of file elgglib.js.

elgg nullFunction = function() {}

Convenience reference to an empty function.

Save memory by not generating multiple empty functions.

Definition at line 26 of file elgglib.js.

elgg parse_str
Initial value:
= 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;
}

Returns an object with key/values of the parsed query string.

Parameters
{String}string The string to parse
Returns
{Object} The parsed object string

Definition at line 523 of file elgglib.js.

elgg parse_url

Parse a URL into its parts.

Mimicks http://php.net/parse_url

Parameters
{String}url The URL to parse
{Number}component A component to return
{Boolean}expand Expand the query into an object? Else it's a string.
Returns
{Object} The parsed URL

Definition at line 450 of file elgglib.js.

elgg provide
Initial value:
= function(pkg, opt_context) {
var parts,
context = opt_context || elgg.global,
part, i;
if (elgg.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];
}
}
var elgg
Definition: elgglib.js:4
i
Definition: admin.css.php:47

Definition at line 212 of file elgglib.js.

elgg push_to_object_array
Initial value:
= 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;
}
var elgg
Definition: elgglib.js:4

Adds child to object[parent] array.

Parameters
{Object}object The object to add to
{String}parent The parent array to add to.
{*}value The value

Definition at line 586 of file elgglib.js.

elgg register_error
Initial value:
= function(errors, delay) {
elgg.system_messages(errors, delay, "error");
}
var elgg
Definition: elgglib.js:4

Wrapper function for system_messages.

Specifies "errors" as the type of message

Parameters
{String}errors The error message to display
{Number}delay How long to dispaly the error message (milliseconds)
Examples:
/root/Elgg/engine/lib/views.php.

Definition at line 399 of file elgglib.js.

elgg require
Initial value:
= function(pkg) {
elgg.assertTypeOf('string', pkg);
var parts = pkg.split('.'),
cur = elgg.global,
part, i;
for (i = 0; i < parts.length; i += 1) {
part = parts[i];
cur = cur[part];
if (elgg.isUndefined(cur)) {
throw new Error("Missing package: " + pkg);
}
}
}
var elgg
Definition: elgglib.js:4
i
Definition: admin.css.php:47

Throw an error if the required package isn't present.

Parameters
{String}pkg The required package (e.g., 'elgg.package')

Definition at line 164 of file elgglib.js.

elgg system_message
Initial value:
= function(msgs, delay) {
elgg.system_messages(msgs, delay, "message");
}
var elgg
Definition: elgglib.js:4

Wrapper function for system_messages.

Specifies "messages" as the type of message

Parameters
{String}msgs The message to display
{Number}delay How long to display the message (milliseconds)

Definition at line 390 of file elgglib.js.