ability to remove contacts

This commit is contained in:
Rodolphe Breard 2012-11-27 10:28:08 +01:00
parent 1f60d56ee2
commit e0af35f791
2 changed files with 36 additions and 7 deletions

View file

@ -121,3 +121,10 @@
.spk-me {
color: blue;
}
.remove {
float: right;
font-family: sans-serif;
font-size: 12px;
cursor: pointer;
}

View file

@ -21,20 +21,42 @@ var ContactList = function() {
};
ContactList.prototype.addContact = function(name) {
var el = null;
var li = null, login = null, close = null;
if (typeof this.contacts[name] === "undefined") {
el = document.createElement("li");
el.innerHTML = name;
el.addEventListener("dblclick", function() {
var nel = $cs.ui.addNewTab(this.innerHTML);
li = document.createElement("li");
login = document.createElement("span");
close = document.createElement("span");
close.classList.add("remove");
login.innerHTML = name;
close.innerHTML = "x";
li.appendChild(login);
li.appendChild(close);
li.addEventListener("dblclick", function() {
var nel = $cs.ui.addNewTab(name);
$cs.ui.hideAllTabs();
nel.show();
});
this.contacts[name] = el;
close.addEventListener("click", (function(elem) {
return function() {
elem.rmContact(name);
};
})(this));
this.contacts[name] = li;
this.save();
this.lst.appendChild(el);
this.lst.appendChild(li);
}
};
ContactList.prototype.rmContact = function(name) {
console.log('removing ' + name + 'from contacts');
for (var i = this.lst.children.length - 1; i >= 0; --i) {
if (this.lst.children[i].children[0].innerHTML === name) {
console.log('deleted');
this.lst.removeChild(this.lst.children[i]);
break ;
}
}
};