aboutsummaryrefslogtreecommitdiff
path: root/js/classes
diff options
context:
space:
mode:
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-14 08:28:22 +0000
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-11-14 08:28:22 +0000
commit72a4b251503eeb2ae4cc8efdea1f522817652406 (patch)
treedd611bd8cce5fbcbf1c398da5619287a7487ee9a /js/classes
parentaa5bb3f0bc17d858831412da82eef805ecafac89 (diff)
downloadelgg-72a4b251503eeb2ae4cc8efdea1f522817652406.tar.gz
elgg-72a4b251503eeb2ae4cc8efdea1f522817652406.tar.bz2
Refs #2538: Refactored and cleaned up ElggPriorityList and events
git-svn-id: http://code.elgg.org/elgg/trunk@7312 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'js/classes')
-rw-r--r--js/classes/ElggPriorityList.js63
1 files changed, 38 insertions, 25 deletions
diff --git a/js/classes/ElggPriorityList.js b/js/classes/ElggPriorityList.js
index 521fbbb64..324b07cac 100644
--- a/js/classes/ElggPriorityList.js
+++ b/js/classes/ElggPriorityList.js
@@ -1,60 +1,73 @@
+/**
+ *
+ */
elgg.ElggPriorityList = function() {
this.length = 0;
this.priorities_ = [];
};
+/**
+ *
+ */
elgg.ElggPriorityList.prototype.insert = function(obj, opt_priority) {
- if (opt_priority == undefined) {
- opt_priority = 500;
- }
+ var priority = parseInt(opt_priority || 500, 10);
- opt_priority = parseInt(opt_priority);
- if (opt_priority < 0) {
- opt_priority = 0;
- }
-
- if (this.priorities_[opt_priority] == undefined) {
- this.priorities_[opt_priority] = [];
+ priority = Math.max(priority, 0);
+
+ if (elgg.isUndefined(this.priorities_[priority])) {
+ this.priorities_[priority] = [];
}
-
- this.priorities_[opt_priority].push(obj);
+
+ this.priorities_[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) {
+ var index = 0, p, i, elems;
+ for (p in this.priorities_) {
+ elems = this.priorities_[p];
+ for (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) {
+
+ var index = 0, p, elems, i;
+
+ for (p in this.priorities_) {
+ elems = this.priorities_[p];
+ for (i in elems) {
if (!callback(elems[i], index)) {
return false;
- };
+ }
+ index++;
}
}
-
+
return true;
};
+/**
+ *
+ */
elgg.ElggPriorityList.prototype.remove = function(obj) {
- this.priorities_.forEach(function(elems, priority) {
+ this.priorities_.forEach(function(elems) {
var index;
- while ((index = elems.indexOf(obj)) != -1) {
+ while ((index = elems.indexOf(obj)) !== -1) {
elems.splice(index, 1);
+ this.length--;
}
});
}; \ No newline at end of file