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/classes | |
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/classes')
-rw-r--r-- | engine/js/classes/ElggPriorityList.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/engine/js/classes/ElggPriorityList.js b/engine/js/classes/ElggPriorityList.js new file mode 100644 index 000000000..521fbbb64 --- /dev/null +++ b/engine/js/classes/ElggPriorityList.js @@ -0,0 +1,60 @@ +elgg.ElggPriorityList = function() { + this.length = 0; + this.priorities_ = []; +}; + +elgg.ElggPriorityList.prototype.insert = function(obj, opt_priority) { + if (opt_priority == undefined) { + opt_priority = 500; + } + + opt_priority = parseInt(opt_priority); + if (opt_priority < 0) { + opt_priority = 0; + } + + if (this.priorities_[opt_priority] == undefined) { + this.priorities_[opt_priority] = []; + } + + this.priorities_[opt_priority].push(obj); + this.length++; +}; + +elgg.ElggPriorityList.prototype.forEach = function(callback) { + elgg.assertTypeOf('function', callback); + + var index = 0; + for (var p in this.priorities_) { + var elems = this.priorities_[p]; + for (var i in elems) { + callback(elems[i], index); + index++; + } + } +}; + +elgg.ElggPriorityList.prototype.every = function(callback) { + elgg.assertTypeOf('function', callback); + + var index = 0; + for (var p in this.priorities_) { + var elems = this.priorities_[p]; + for (var i in elems) { + if (!callback(elems[i], index)) { + return false; + }; + } + } + + return true; +}; + +elgg.ElggPriorityList.prototype.remove = function(obj) { + this.priorities_.forEach(function(elems, priority) { + var index; + while ((index = elems.indexOf(obj)) != -1) { + elems.splice(index, 1); + } + }); +};
\ No newline at end of file |