setting focus to the chat input when a tab is shown

This commit is contained in:
Rodolphe Breard 2012-11-27 09:24:35 +01:00
parent 66cd257546
commit 1f60d56ee2

View file

@ -16,6 +16,7 @@
var Tab = function(name) {
this.name = this.filterName(name);
this.chat_input = null;
this.wr_lst = document.getElementById("tab-lst");
this.wr_body = document.getElementById("tab-body-wrapper");
this.initListElement();
@ -58,9 +59,9 @@ Tab.prototype.initListElement = function() {
};
Tab.prototype.initBodyElement = function() {
var chat_input = document.createElement("input"),
chat_input_w = document.createElement("div");
var chat_input_w = document.createElement("div");
this.chat_input = document.createElement("input");
this.chat_log = document.createElement("pre");
this.chat_log.classList.add("chat-log");
this.el_body = document.createElement("div");
@ -68,9 +69,9 @@ Tab.prototype.initBodyElement = function() {
this.el_body.id = this.name;
this.el_body.style.display = "none";
chat_input_w.classList.add("chat-input-wrapper");
chat_input.classList.add("chat-input");
chat_input.setAttribute("type", "text");
chat_input.addEventListener("keyup", (function(elem) {
this.chat_input.classList.add("chat-input");
this.chat_input.setAttribute("type", "text");
this.chat_input.addEventListener("keyup", (function(elem) {
return function(event) {
if (event.keyCode == 13 && this.value != "") {
var msg = this.value;
@ -86,7 +87,7 @@ Tab.prototype.initBodyElement = function() {
};
})(this), false);
chat_input_w.appendChild(chat_input);
chat_input_w.appendChild(this.chat_input);
this.el_body.appendChild(this.chat_log);
this.el_body.appendChild(chat_input_w);
this.wr_body.appendChild(this.el_body);
@ -113,6 +114,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_input.focus();
};
Tab.prototype.isCurrent = function() {