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 { .spk-me {
color: blue; 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) { ContactList.prototype.addContact = function(name) {
var el = null; var li = null, login = null, close = null;
if (typeof this.contacts[name] === "undefined") { if (typeof this.contacts[name] === "undefined") {
el = document.createElement("li"); li = document.createElement("li");
el.innerHTML = name; login = document.createElement("span");
el.addEventListener("dblclick", function() { close = document.createElement("span");
var nel = $cs.ui.addNewTab(this.innerHTML); 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(); $cs.ui.hideAllTabs();
nel.show(); nel.show();
}); });
this.contacts[name] = el; close.addEventListener("click", (function(elem) {
return function() {
elem.rmContact(name);
};
})(this));
this.contacts[name] = li;
this.save(); 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 ;
}
} }
}; };