diff --git a/lib/contacts.nsui.js b/lib/contacts.nsui.js index ab2b2b7..b10ff38 100644 --- a/lib/contacts.nsui.js +++ b/lib/contacts.nsui.js @@ -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); } };