sorting contacts
This commit is contained in:
parent
e0af35f791
commit
37ab83bb3e
1 changed files with 13 additions and 1 deletions
|
@ -20,6 +20,18 @@ var ContactList = function() {
|
||||||
this.lst = document.getElementById("contact-lst");
|
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) {
|
ContactList.prototype.addContact = function(name) {
|
||||||
var li = null, login = null, close = null;
|
var li = null, login = null, close = null;
|
||||||
|
|
||||||
|
@ -45,7 +57,7 @@ ContactList.prototype.addContact = function(name) {
|
||||||
})(this));
|
})(this));
|
||||||
this.contacts[name] = li;
|
this.contacts[name] = li;
|
||||||
this.save();
|
this.save();
|
||||||
this.lst.appendChild(li);
|
this.insertContact(li);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue