sorting contacts

This commit is contained in:
Rodolphe Breard 2012-11-27 18:26:24 +01:00
parent e0af35f791
commit 37ab83bb3e

View file

@ -20,6 +20,18 @@ var ContactList = function() {
this.lst = document.getElementById("contact-lst");
};
ContactList.prototype.insertContact = function(elem) {
var i, nb_el = this.lst.children.length;
for (i = 0; i < nb_el; i++) {
if (this.lst.children[i].children[0].innerHTML > elem.children[0].innerHTML) {
this.lst.insertBefore(elem, this.lst.children[i]);
return ;
}
}
this.lst.appendChild(elem);
};
ContactList.prototype.addContact = function(name) {
var li = null, login = null, close = null;
@ -45,7 +57,7 @@ ContactList.prototype.addContact = function(name) {
})(this));
this.contacts[name] = li;
this.save();
this.lst.appendChild(li);
this.insertContact(li);
}
};