From 66e2975bed750c15f7cdb9f3b09de9887bd8bd68 Mon Sep 17 00:00:00 2001 From: Belga Date: Thu, 30 Oct 2014 09:51:57 +0100 Subject: [PATCH] Issue #4: font-size option now available in options --- lib/options.js | 19 ++++++++++++++++--- lib/tab.nsui.js | 16 ++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) mode change 100644 => 100755 lib/tab.nsui.js diff --git a/lib/options.js b/lib/options.js index 4afacdc..bf0494f 100644 --- a/lib/options.js +++ b/lib/options.js @@ -33,6 +33,9 @@ OptionsManager.prototype.types = { }, "checkbox": function(elem) { return elem.checked; + }, + "number": function(elem) { + return elem.value; } }, "set": { @@ -48,6 +51,9 @@ OptionsManager.prototype.types = { } else { elem.setAttribute('checked'); } + }, + "number": function(elem, val) { + elem.value = val; } } }; @@ -81,7 +87,7 @@ 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; @@ -89,7 +95,7 @@ OptionsManager.prototype.savePart = function(pass) { 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]; @@ -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() { @@ -151,3 +157,10 @@ OptionsManager.prototype.setElemValue = function(elem, val) { this.types.set[type](elem, val); } }; + +function isNumberKey(evt){ + var charCode = (evt.which) ? evt.which : event.keyCode + if (charCode > 31 && (charCode < 48 || charCode > 57)) + return false; + return true; +} diff --git a/lib/tab.nsui.js b/lib/tab.nsui.js old mode 100644 new mode 100755 index c4f8f26..982b06b --- a/lib/tab.nsui.js +++ b/lib/tab.nsui.js @@ -22,6 +22,8 @@ var Tab = function(name) { this.buff_len = 1000; this.history_index = 0; this.history = []; + this.options = new OptionsManager(); + this.options.restore(); this.initListElement(); this.initBodyElement(); }; @@ -62,16 +64,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 = this.options.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) { @@ -126,6 +133,7 @@ Tab.prototype.hide = function() { }; Tab.prototype.show = function() { + this.options.restore(); if (typeof this.showHandler !== "undefined") { this.showHandler(); } @@ -133,6 +141,7 @@ Tab.prototype.show = function() { this.el_lst.classList.add("tab-current"); this.el_body.style.display = "block"; this.chat_log.scrollTop = 42000; + this.chat_log.style.fontSize = this.options.values["chat-size"] + "px"; this.chat_input.focus(); }; @@ -156,11 +165,10 @@ Tab.prototype.flushText = function() { Tab.prototype.appendMessage = function(msg) { this.history_index = 0; this.chat_log.innerHTML += '
' + $cs.ui.formatMessage(msg) + '
'; - + if (!(typeof msg.login !== "undefined" && msg.login !== null)) { this.history.push(msg.message); } - this.flushText(); this.chat_log.scrollTop = 42 * this.buff_len; };