From e0af35f7911808a4aaf00d977327efbb929636b8 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Tue, 27 Nov 2012 10:28:08 +0100 Subject: [PATCH] ability to remove contacts --- chromesoul.css | 7 +++++++ lib/contacts.nsui.js | 36 +++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/chromesoul.css b/chromesoul.css index 19672d7..449b8dd 100644 --- a/chromesoul.css +++ b/chromesoul.css @@ -121,3 +121,10 @@ .spk-me { color: blue; } + +.remove { + float: right; + font-family: sans-serif; + font-size: 12px; + cursor: pointer; +} diff --git a/lib/contacts.nsui.js b/lib/contacts.nsui.js index 83c484e..ab2b2b7 100644 --- a/lib/contacts.nsui.js +++ b/lib/contacts.nsui.js @@ -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 ; + } } };