aboutsummaryrefslogtreecommitdiff
path: root/js/lib/elgglib.js
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2011-10-15 01:02:01 -0700
committerBrett Profitt <brett.profitt@gmail.com>2011-10-15 01:02:01 -0700
commit52fe9265add0b01699f63dd9b2aeeb4b248b02c1 (patch)
treedebc2d309150fedafab6f67f5c22264ee363c89c /js/lib/elgglib.js
parentbe5e5eaaac3844c19a804347676cdc58f959827a (diff)
downloadelgg-52fe9265add0b01699f63dd9b2aeeb4b248b02c1.tar.gz
elgg-52fe9265add0b01699f63dd9b2aeeb4b248b02c1.tar.bz2
Fixes #3540. Added "instant hooks" to JS hooks engine. elgg.register_instant_hook(name, type) will cause any handler registering to that hook to be immediately executed if the hook has been previously triggered. Open for better suggestions about the name.
Diffstat (limited to 'js/lib/elgglib.js')
-rw-r--r--js/lib/elgglib.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/js/lib/elgglib.js b/js/lib/elgglib.js
index 96bd04d7c..0f17eeced 100644
--- a/js/lib/elgglib.js
+++ b/js/lib/elgglib.js
@@ -521,6 +521,42 @@ elgg.getSelectorFromUrlFragment = function(url) {
};
/**
+ * Adds child to object[parent] array.
+ *
+ * @param {Object} object The object to add to
+ * @param {String} parent The parent array to add to.
+ * @param {Mixed} value The value
+ */
+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 (object[parent].indexOf(value) < 0) {
+ return object[parent].push(value);
+ }
+
+ return false;
+}
+
+/**
+ * Tests if object[parent] contains child
+ *
+ * @param {Object} object The object to add to
+ * @param {String} parent The parent array to add to.
+ * @param {Mixed} value The value
+ */
+elgg.is_in_object_array = function(object, parent, value) {
+ elgg.assertTypeOf('object', object);
+ elgg.assertTypeOf('string', parent);
+
+ return typeof(object[parent]) != 'undefined' && object[parent].indexOf(value) >= 0;
+}
+
+/**
* Triggers the init hook when the library is ready
*
* Current requirements: