From 37ab83bb3e07baab4a2eeb2d7f3c51de86da97a2 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Tue, 27 Nov 2012 18:26:24 +0100 Subject: [PATCH] sorting contacts --- lib/contacts.nsui.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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); } };