From 52fe9265add0b01699f63dd9b2aeeb4b248b02c1 Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Sat, 15 Oct 2011 01:02:01 -0700 Subject: 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. --- js/lib/elgglib.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'js/lib/elgglib.js') 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 @@ -520,6 +520,42 @@ elgg.getSelectorFromUrlFragment = function(url) { return ''; }; +/** + * 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 * -- cgit v1.2.3