improved contact list and communications
This commit is contained in:
parent
b9058292fb
commit
85f6c4a862
5 changed files with 90 additions and 2 deletions
|
@ -38,6 +38,7 @@
|
||||||
<script type="text/javascript" src="lib/ns_client.js"></script>
|
<script type="text/javascript" src="lib/ns_client.js"></script>
|
||||||
<script type="text/javascript" src="lib/options.js"></script>
|
<script type="text/javascript" src="lib/options.js"></script>
|
||||||
<script type="text/javascript" src="lib/tab.nsui.js"></script>
|
<script type="text/javascript" src="lib/tab.nsui.js"></script>
|
||||||
|
<script type="text/javascript" src="lib/contacts.nsui.js"></script>
|
||||||
<script type="text/javascript" src="lib/nsui.js"></script>
|
<script type="text/javascript" src="lib/nsui.js"></script>
|
||||||
<script type="text/javascript" src="start.js"></script>
|
<script type="text/javascript" src="start.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
78
lib/contacts.nsui.js
Normal file
78
lib/contacts.nsui.js
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Rodolphe Breard
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice appear in all copies.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
var ContactList = function() {
|
||||||
|
this.storage = chrome.storage.sync;
|
||||||
|
this.contacts = {};
|
||||||
|
this.lst = document.getElementById("contact-lst");
|
||||||
|
};
|
||||||
|
|
||||||
|
ContactList.prototype.addContact = function(name) {
|
||||||
|
var el = 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);
|
||||||
|
|
||||||
|
$cs.ui.hideAllTabs();
|
||||||
|
nel.show();
|
||||||
|
});
|
||||||
|
this.contacts[name] = el;
|
||||||
|
this.save();
|
||||||
|
this.lst.appendChild(el);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ContactList.prototype.save = function() {
|
||||||
|
var i, data = {"contact_list": []};
|
||||||
|
|
||||||
|
for (i in this.contacts) {
|
||||||
|
if (this.contacts.hasOwnProperty(i)) {
|
||||||
|
data.contact_list.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.contact_list.sort();
|
||||||
|
this.storage.set(data, function() {});
|
||||||
|
};
|
||||||
|
|
||||||
|
ContactList.prototype.restore = function() {
|
||||||
|
this.storage.get("contact_list", (function(elem) {
|
||||||
|
return function(items) {
|
||||||
|
elem.contacts = {};
|
||||||
|
elem.lst.innerHTML = "";
|
||||||
|
if (typeof items.contact_list !== "undefined") {
|
||||||
|
for (i = items.contact_list.length - 1; i >= 0; --i) {
|
||||||
|
elem.addContact(items.contact_list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
ContactList.prototype.init = function() {
|
||||||
|
var add_btn = document.getElementById("add-contact");
|
||||||
|
|
||||||
|
this.restore();
|
||||||
|
this.save();
|
||||||
|
add_btn.addEventListener("keyup", function(event) {
|
||||||
|
if (event.keyCode == 13 && this.value != "") {
|
||||||
|
$cs.contacts.addContact(this.value);
|
||||||
|
this.value = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
10
lib/nsui.js
10
lib/nsui.js
|
@ -80,7 +80,7 @@ Nsui.prototype.getNextTab = function(current_name) {
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nsui.prototype.addContentToTab = function(tab_name, content) {
|
Nsui.prototype.addNewTab = function(tab_name) {
|
||||||
var tab = this.getTabByName(tab_name);
|
var tab = this.getTabByName(tab_name);
|
||||||
|
|
||||||
if (tab === null) {
|
if (tab === null) {
|
||||||
|
@ -89,13 +89,19 @@ Nsui.prototype.addContentToTab = function(tab_name, content) {
|
||||||
if (!tab.isCurrent()) {
|
if (!tab.isCurrent()) {
|
||||||
tab.setActive();
|
tab.setActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return tab;
|
||||||
|
};
|
||||||
|
|
||||||
|
Nsui.prototype.addContentToTab = function(tab_name, content) {
|
||||||
|
var tab = this.addNewTab(tab_name);
|
||||||
tab.appendText(this.formatMessage(content));
|
tab.appendText(this.formatMessage(content));
|
||||||
};
|
};
|
||||||
|
|
||||||
Nsui.prototype.formatMessage = function(msg) {
|
Nsui.prototype.formatMessage = function(msg) {
|
||||||
var fmt = "";
|
var fmt = "";
|
||||||
|
|
||||||
if (msg.login !== null) {
|
if (typeof msg.login !== "undefined" && msg.login !== null) {
|
||||||
fmt += '<span class="spk-oth">' + msg.login + ': </span>';
|
fmt += '<span class="spk-oth">' + msg.login + ': </span>';
|
||||||
} else {
|
} else {
|
||||||
fmt += '<span class="spk-me">' + document.getElementById('login').value + ': </span>';
|
fmt += '<span class="spk-me">' + document.getElementById('login').value + ': </span>';
|
||||||
|
|
|
@ -78,6 +78,7 @@ Tab.prototype.initBodyElement = function() {
|
||||||
|
|
||||||
if (typeof $cs.client !== "undefined") {
|
if (typeof $cs.client !== "undefined") {
|
||||||
$cs.client.sendMessage(elem.name, msg);
|
$cs.client.sendMessage(elem.name, msg);
|
||||||
|
$cs.ui.addContentToTab(elem.name, {"message": msg});
|
||||||
} else {
|
} else {
|
||||||
console.error("chromesoul client not found");
|
console.error("chromesoul client not found");
|
||||||
}
|
}
|
||||||
|
|
2
start.js
2
start.js
|
@ -2,6 +2,7 @@ var chromesoul = (function() {
|
||||||
var chromesoul = {
|
var chromesoul = {
|
||||||
"opts": new OptionsManager(),
|
"opts": new OptionsManager(),
|
||||||
"ui": new Nsui(),
|
"ui": new Nsui(),
|
||||||
|
"contacts": new ContactList(),
|
||||||
"client": new NsClient()
|
"client": new NsClient()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ var chromesoul = (function() {
|
||||||
$cs.opts.init();
|
$cs.opts.init();
|
||||||
$cs.ui.init();
|
$cs.ui.init();
|
||||||
$cs.client.init();
|
$cs.client.init();
|
||||||
|
$cs.contacts.init();
|
||||||
|
|
||||||
$cs.ui.setReconnect(function() {
|
$cs.ui.setReconnect(function() {
|
||||||
$cs.client.disconnect();
|
$cs.client.disconnect();
|
||||||
|
|
Reference in a new issue