Skip to content

Commit

Permalink
Issue breard-r#4: font-size option now available in options
Browse files Browse the repository at this point in the history
added: double-clicking on a contact when on the options tab now switches to chat-panel
  • Loading branch information
SirBelga committed Oct 30, 2014
1 parent 11d8cbd commit 6a4af66
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
9 changes: 5 additions & 4 deletions chromesoul.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

<div id="main-ctn">
<div id="config-pannel">
<input type="text" placeholder="Login" id="login" class="opt" value=""><br>
<input type="password" placeholder="Password (SOCKS)" id="pwd_socks" class="opt" value=""><br>
<input type="checkbox" id="enable_notif" class="opt" checked="checked"><label for="enable_notif">Enable notifications</label><br>
<input type="checkbox" id="enable_msg" class="opt" checked="checked"><label for="enable_msg">Enable messages</label><br>
<input type="text" placeholder="Login" id="login" class="opt" value="" /><br>
<input type="password" placeholder="Password (SOCKS)" id="pwd_socks" class="opt" value="" /><br>
<input type="checkbox" id="enable_notif" class="opt" checked="checked" /><label for="enable_notif">Enable notifications</label><br>
<input type="checkbox" id="enable_msg" class="opt" checked="checked" /><label for="enable_msg">Enable messages</label><br>
<input type="number" placeholder="12" id="chat-size" class="opt" value="" /><label for="chat-size">Chat font-size</label><br>
<button id="save">Save</button> <span id="status"></span>
</div>
<div id="chat-pannel">
Expand Down
1 change: 1 addition & 0 deletions lib/contacts.nsui.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ContactList.prototype.addContact = function(name) {
var nel = $cs.ui.addNewTab(name);

$cs.ui.hideAllTabs();
$cs.ui.showContent("chat-pannel");
nel.show();
});
close.addEventListener("click", (function(elem) {
Expand Down
32 changes: 25 additions & 7 deletions lib/nsui.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Nsui.prototype.getTabByName = function(name) {
}

return ret;
}
};

Nsui.prototype.getNextTab = function(current_name) {
var i, prev = null;
Expand Down Expand Up @@ -204,15 +204,33 @@ Nsui.prototype.sanitizeText = function(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};

Nsui.prototype.currentTabStyle = function() {
$cs.opts.restore();
if (this.tab_lst.length > 1) {
for (var tab in this.tab_lst) {
if (tab.el_lst.classList.contains("tab-current")) {
tab.chat_log.style.fontSize = $cs.opts.values["chat-size"] + "px";
break;
}
}
}
else if (this.tab_lst.length > 0) {
this.tab_lst[0].chat_log.style.fontSize = $cs.opts.values["chat-size"] + "px";
}
};

Nsui.prototype.showContent = function(part_id) {
var i, ctn_lst = ["config-pannel", "chat-pannel"];

for (i = ctn_lst.length - 1; i>= 0; --i) {
if (ctn_lst[i] === part_id) {
document.getElementById(ctn_lst[i]).style.display = "block";
} else {
document.getElementById(ctn_lst[i]).style.display = "none";
if (part_id === "chat-pannel") {
this.currentTabStyle();
}
for (i = ctn_lst.length - 1; i>= 0; --i) {
if (ctn_lst[i] === part_id) {
document.getElementById(ctn_lst[i]).style.display = "block";
} else {
document.getElementById(ctn_lst[i]).style.display = "none";
}
}
};

Expand All @@ -222,7 +240,7 @@ Nsui.prototype.switchContent = function(part_id, part_id_to) {
} else {
this.showContent(part_id_to);
}
}
};

Nsui.prototype.init = function() {
window.onfocus = (function(elem) {
Expand Down
14 changes: 11 additions & 3 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ OptionsManager.prototype.types = {
},
"checkbox": function(elem) {
return elem.checked;
},
"number": function(elem) {
return elem.value;
}
},
"set": {
Expand All @@ -48,6 +51,9 @@ OptionsManager.prototype.types = {
} else {
elem.setAttribute('checked');
}
},
"number": function(elem, val) {
elem.value = val;
}
}
};
Expand Down Expand Up @@ -81,15 +87,15 @@ OptionsManager.prototype.init = function() {
OptionsManager.prototype.savePart = function(pass) {
var i = 0, data = {}, storage;

if (pass) {
if (pass) {
storage = this.pass_storage;
} else {
storage = this.storage;
}

if (this.opts !== null) {
for (i = this.opts.length - 1; i >= 0; --i) {
if ((pass && (this.getElemType(this.opts[i]) === "password" || this.getElemType(this.opts[i]) === "text"))
if ((pass && (this.getElemType(this.opts[i]) === "password" || this.getElemType(this.opts[i]) === "text"))
|| (!pass && this.getElemType(this.opts[i]) !== "password" && this.getElemType(this.opts[i]) !== "text")) {
data[this.opts[i].id] = this.getElemValue(this.opts[i]);
this.values[this.opts[i].id] = data[this.opts[i].id];
Expand All @@ -110,7 +116,7 @@ OptionsManager.prototype.savePart = function(pass) {

OptionsManager.prototype.save = function() {
this.savePart(true);
this.savePart(false);
this.savePart(false);
};

OptionsManager.prototype.restore = function() {
Expand Down Expand Up @@ -151,3 +157,5 @@ OptionsManager.prototype.setElemValue = function(elem, val) {
this.types.set[type](elem, val);
}
};


15 changes: 11 additions & 4 deletions lib/tab.nsui.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Tab = function(name) {
this.buff_len = 1000;
this.history_index = 0;
this.history = [];
$cs.opts.restore();
this.initListElement();
this.initBodyElement();
};
Expand Down Expand Up @@ -62,16 +63,21 @@ Tab.prototype.initListElement = function() {

Tab.prototype.initBodyElement = function() {
var chat_input_w = document.createElement("div");

this.chat_input = document.createElement("input");
this.chat_input.placeholder = "Some text here...";

this.chat_log = document.createElement("p");
this.chat_log.classList.add("chat-log");
this.chat_log.style.fontSize = $cs.opts.values["chat-size"] + "px";

this.el_body = document.createElement("div");
this.el_body.classList.add("tab-body");
this.el_body.classList.add("tab-body");
this.el_body.id = this.name;
this.el_body.style.display = "none";

chat_input_w.classList.add("chat-input-wrapper");

this.chat_input.classList.add("chat-input");
this.chat_input.setAttribute("type", "text");
this.chat_input.addEventListener("keyup", (function(elem) {
Expand Down Expand Up @@ -132,7 +138,9 @@ Tab.prototype.show = function() {
this.el_lst.classList.remove("tab-active");
this.el_lst.classList.add("tab-current");
this.el_body.style.display = "block";
$cs.opts.restore()
this.chat_log.scrollTop = 42000;
this.chat_log.style.fontSize = $cs.opts.values["chat-size"] + "px";
this.chat_input.focus();
};

Expand All @@ -156,11 +164,10 @@ Tab.prototype.flushText = function() {
Tab.prototype.appendMessage = function(msg) {
this.history_index = 0;
this.chat_log.innerHTML += '<div class="chat-message">' + $cs.ui.formatMessage(msg) + '</div>';

if (!(typeof msg.login !== "undefined" && msg.login !== null)) {
this.history.push(msg.message);
}

this.flushText();
this.chat_log.scrollTop = 42 * this.buff_len;
};

0 comments on commit 6a4af66

Please sign in to comment.