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 ; + } } };