Elgg  Version 1.11
ElggPriorityList.js
Go to the documentation of this file.
1 
5 elgg.ElggPriorityList = function() {
6  this.length = 0;
7  this.priorities_ = [];
8 };
9 
18 elgg.ElggPriorityList.prototype.insert = function(obj, opt_priority) {
19  var priority = 500;
20  if (arguments.length == 2 && opt_priority !== undefined) {
21  priority = parseInt(opt_priority, 10);
22  }
23 
24  priority = Math.max(priority, 0);
25 
26  if (elgg.isUndefined(this.priorities_[priority])) {
27  this.priorities_[priority] = [];
28  }
29 
30  this.priorities_[priority].push(obj);
31  this.length++;
32 };
33 
43 elgg.ElggPriorityList.prototype.forEach = function(callback) {
44  elgg.assertTypeOf('function', callback);
45 
46  var index = 0;
47 
48  this.priorities_.forEach(function(elems) {
49  elems.forEach(function(elem) {
50  callback(elem, index++);
51  });
52  });
53 
54  return this;
55 };
56 
66 elgg.ElggPriorityList.prototype.every = function(callback) {
67  elgg.assertTypeOf('function', callback);
68 
69  var index = 0;
70 
71  return this.priorities_.every(function(elems) {
72  return elems.every(function(elem) {
73  return callback(elem, index++);
74  });
75  });
76 };
77 
84 elgg.ElggPriorityList.prototype.remove = function(obj) {
85  this.priorities_.forEach(function(elems) {
86  var index;
87  while ((index = elems.indexOf(obj)) !== -1) {
88  elems.splice(index, 1);
89  this.length--;
90  }
91  });
92 };
elgg
Definition: install.js:23
z index
Definition: admin.php:354