aboutsummaryrefslogtreecommitdiff
path: root/engine/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/js/lib')
-rw-r--r--engine/js/lib/elgglib.js19
-rw-r--r--engine/js/lib/events.js65
-rw-r--r--engine/js/lib/languages.js17
-rw-r--r--engine/js/lib/security.js14
-rw-r--r--engine/js/lib/ui.js9
-rw-r--r--engine/js/lib/ui.widgets.js4
6 files changed, 88 insertions, 40 deletions
diff --git a/engine/js/lib/elgglib.js b/engine/js/lib/elgglib.js
index 5c32deaaf..f7c30bdc2 100644
--- a/engine/js/lib/elgglib.js
+++ b/engine/js/lib/elgglib.js
@@ -9,11 +9,10 @@
*/
var elgg = elgg || {};
-elgg.init = function() {
- //if the user clicks a system message, make it disappear
- $('.elgg_system_message').live('click', function() {
- $(this).stop().fadeOut('fast');
- });
+elgg.assertTypeOf = function(type, param) {
+ if (typeof param !== type) {
+ throw new TypeError("Expecting param to be a " + type + ". Was a " + typeof param + ".");
+ }
};
/**
@@ -176,12 +175,4 @@ elgg.register_error = function(errors, delay) {
*/
elgg.forward = function(url) {
location.href = elgg.extendUrl(url);
-};
-
-/**
- * Initialise Elgg
- * @todo How should plugins, etc. initialize themselves?
- */
-$(function() {
- elgg.init();
-});
+}; \ No newline at end of file
diff --git a/engine/js/lib/events.js b/engine/js/lib/events.js
new file mode 100644
index 000000000..358dd6280
--- /dev/null
+++ b/engine/js/lib/events.js
@@ -0,0 +1,65 @@
+elgg.provide('elgg.config.events');
+elgg.provide('elgg.config.events.all');
+elgg.provide('elgg.config.events.all.all');
+
+elgg.register_event_handler = function(event, type, callback, priority) {
+ elgg.assertTypeOf('string', event);
+ elgg.assertTypeOf('string', event);
+ elgg.assertTypeOf('function', callback);
+
+ if (!event || !type) {
+ return false;
+ }
+
+ elgg.provide('elgg.config.events.' + event + '.' + type);
+
+ var events = elgg.config.events;
+
+ if (!(events[event][type] instanceof elgg.ElggPriorityList)) {
+ events[event][type] = new elgg.ElggPriorityList();
+ }
+
+ return events[event][type].insert(callback, priority);
+};
+
+elgg.trigger_event = function(event, type, object) {
+ elgg.assertTypeOf('string', event);
+ elgg.assertTypeOf('string', event);
+
+ elgg.provide('elgg.config.events.' + event + '.' + type);
+ elgg.provide('elgg.config.events.all.' + type);
+ elgg.provide('elgg.config.events.' + event + '.all');
+ elgg.provide('elgg.config.events.all.all');
+
+ var events = elgg.config.events;
+
+ var callEventHandler = function(handler) {
+ return handler(event, type, object) !== false;
+ };
+
+ if (events[event][type] instanceof elgg.ElggPriorityList) {
+ if (!events[event][type].every(callEventHandler)) {
+ return false;
+ }
+ }
+
+ if (events['all'][type] instanceof elgg.ElggPriorityList) {
+ if (!events['all'][type].every(callEventHandler)) {
+ return false;
+ }
+ }
+
+ if (events[event]['all'] instanceof elgg.ElggPriorityList) {
+ if (!events[event]['all'].every(callEventHandler)) {
+ return false;
+ }
+ }
+
+ if (events['all']['all'] instanceof elgg.ElggPriorityList) {
+ if (!events['all']['all'].every(callEventHandler)) {
+ return false;
+ }
+ }
+
+ return true;
+}; \ No newline at end of file
diff --git a/engine/js/lib/languages.js b/engine/js/lib/languages.js
index 6ac83f350..3231cf77d 100644
--- a/engine/js/lib/languages.js
+++ b/engine/js/lib/languages.js
@@ -5,10 +5,6 @@ elgg.provide('elgg.config.translations');
elgg.config.language = 'en';
-elgg.config.translations.init = function() {
- elgg.reload_all_translations();
-};
-
elgg.add_translation = function(lang, translations) {
elgg.provide('elgg.config.translations.' + lang);
@@ -37,11 +33,6 @@ elgg.reload_all_translations = function(language) {
};
/**
- * @deprecated Use elgg.reload_all_translations
- */
-elgg.config.translations.load = elgg.reload_all_translations;
-
-/**
* Get the current language
* @return {String}
*/
@@ -85,6 +76,8 @@ elgg.echo = function(key, language) {
return undefined;
};
-$(function() {
- elgg.config.translations.init();
-}); \ No newline at end of file
+elgg.config.translations.init = function() {
+ elgg.reload_all_translations();
+};
+
+elgg.register_event_handler('boot', 'system', elgg.config.translations.init); \ No newline at end of file
diff --git a/engine/js/lib/security.js b/engine/js/lib/security.js
index f4494111b..bdd762560 100644
--- a/engine/js/lib/security.js
+++ b/engine/js/lib/security.js
@@ -5,11 +5,6 @@ elgg.provide('elgg.security');
elgg.security.token = {};
-elgg.security.init = function() {
- //refresh security token every 5 minutes
- setInterval(elgg.security.refreshToken, elgg.security.interval);
-};
-
elgg.security.setToken = function(json) {
//update the convenience object
elgg.security.token = json;
@@ -67,6 +62,9 @@ elgg.security.addToken = function(data) {
throw new TypeError("elgg.security.addToken not implemented for " + (typeof data) + "s");
};
-$(function() {
- elgg.security.init();
-}); \ No newline at end of file
+elgg.security.init = function() {
+ //refresh security token every 5 minutes
+ setInterval(elgg.security.refreshToken, elgg.security.interval);
+};
+
+elgg.register_event_handler('boot', 'system', elgg.security.init); \ No newline at end of file
diff --git a/engine/js/lib/ui.js b/engine/js/lib/ui.js
index b584d66d1..4a9c64e70 100644
--- a/engine/js/lib/ui.js
+++ b/engine/js/lib/ui.js
@@ -1,6 +1,11 @@
elgg.provide('elgg.ui');
elgg.ui.init = function () {
+ //if the user clicks a system message, make it disappear
+ $('.elgg_system_message').live('click', function() {
+ $(this).stop().fadeOut('fast');
+ });
+
$('a.collapsibleboxlink').click(elgg.ui.toggleCollapsibleBox);
// set-up hover class for dragged widgets
@@ -113,6 +118,4 @@ elgg.ui.toggleCollapsibleBox = function () {
};
})(jQuery);
-$(function() {
- elgg.ui.init();
-}); \ No newline at end of file
+elgg.register_event_handler('init', 'system', elgg.ui.init); \ No newline at end of file
diff --git a/engine/js/lib/ui.widgets.js b/engine/js/lib/ui.widgets.js
index 02a6d0e16..1e3163709 100644
--- a/engine/js/lib/ui.widgets.js
+++ b/engine/js/lib/ui.widgets.js
@@ -128,6 +128,4 @@ var toggleContent = elgg.ui.widgets.toggleContent,
widget_state = elgg.ui.widgets.state,
outputWidgetList = elgg.ui.widgets.outputList;
-$(function() {
- elgg.ui.widgets.init();
-});
+elgg.register_event_handler('init', 'system', elgg.ui.widgets.init); \ No newline at end of file