diff options
author | ewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-11-02 04:23:04 +0000 |
---|---|---|
committer | ewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-11-02 04:23:04 +0000 |
commit | f7ae28ea45656d2821262998e9a71c351dcced8c (patch) | |
tree | c0bed93d6a879ca0ee3c2c35a58c8290c10afbe0 /engine/js/lib/events.js | |
parent | af335c48fc3f4a741e7b5650db46aac48183c244 (diff) | |
download | elgg-f7ae28ea45656d2821262998e9a71c351dcced8c.tar.gz elgg-f7ae28ea45656d2821262998e9a71c351dcced8c.tar.bz2 |
Refs #2538: Added Elggy event system. Javascript boot sequence mimics PHP.
git-svn-id: http://code.elgg.org/elgg/trunk@7186 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/js/lib/events.js')
-rw-r--r-- | engine/js/lib/events.js | 65 |
1 files changed, 65 insertions, 0 deletions
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 |