Fix layouts breaking chat

This commit is contained in:
calzoneman 2013-03-31 20:10:57 -05:00
parent c97e6f3f84
commit 28b9bdb54d
1 changed files with 64 additions and 58 deletions

View File

@ -61,7 +61,7 @@ if(window.location.search) {
} }
if(params["novideo"] != undefined) { if(params["novideo"] != undefined) {
$(".span7").remove(); $("#videodiv").remove();
} }
if(params["channel"] == undefined) { if(params["channel"] == undefined) {
@ -197,68 +197,71 @@ $("#register").click(function() {
}); });
}); });
$("#chatline").keydown(function(ev) { function initChatCallback() {
if(ev.keyCode == 13 && $("#chatline").val() != "") { $("#chatline").keydown(function(ev) {
socket.emit("chatMsg", { if(ev.keyCode == 13 && $("#chatline").val() != "") {
msg: $("#chatline").val() socket.emit("chatMsg", {
}); msg: $("#chatline").val()
CHATHIST.push($("#chatline").val()); });
if(CHATHIST.length > 10)
CHATHIST.shift();
CHATHISTIDX = CHATHIST.length;
$("#chatline").val("");
}
else if(ev.keyCode == 9) { // Tab completion
var words = $("#chatline").val().split(" ");
var current = words[words.length - 1].toLowerCase();
var users = $("#userlist").children();
var match = null;
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML.toLowerCase();
if(name.indexOf(current) == 0 && match == null) {
match = users[i].children[1].innerHTML;
}
else if(name.indexOf(current) == 0) {
match = null;
break;
}
}
if(match != null) {
words[words.length - 1] = match;
if(words.length == 1)
words[0] += ": ";
else
words[words.length - 1] += " ";
$("#chatline").val(words.join(" "));
}
ev.preventDefault();
return false;
}
else if(ev.keyCode == 38) {
if(CHATHISTIDX == CHATHIST.length) {
CHATHIST.push($("#chatline").val()); CHATHIST.push($("#chatline").val());
if(CHATHIST.length > 10)
CHATHIST.shift();
CHATHISTIDX = CHATHIST.length;
$("#chatline").val("");
} }
if(CHATHISTIDX > 0) { else if(ev.keyCode == 9) { // Tab completion
CHATHISTIDX--; var words = $("#chatline").val().split(" ");
$("#chatline").val(CHATHIST[CHATHISTIDX]); var current = words[words.length - 1].toLowerCase();
var users = $("#userlist").children();
var match = null;
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML.toLowerCase();
if(name.indexOf(current) == 0 && match == null) {
match = users[i].children[1].innerHTML;
}
else if(name.indexOf(current) == 0) {
match = null;
break;
}
}
if(match != null) {
words[words.length - 1] = match;
if(words.length == 1)
words[0] += ": ";
else
words[words.length - 1] += " ";
$("#chatline").val(words.join(" "));
}
ev.preventDefault();
return false;
} }
else if(ev.keyCode == 38) {
if(CHATHISTIDX == CHATHIST.length) {
CHATHIST.push($("#chatline").val());
}
if(CHATHISTIDX > 0) {
CHATHISTIDX--;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault(); ev.preventDefault();
return false; return false;
}
else if(ev.keyCode == 40) {
if(CHATHISTIDX < CHATHIST.length - 1) {
CHATHISTIDX++;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
} }
else if(ev.keyCode == 40) {
if(CHATHISTIDX < CHATHIST.length - 1) {
CHATHISTIDX++;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault(); ev.preventDefault();
return false; return false;
} }
}); });
$("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; });
$("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; });
}
initChatCallback();
$("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; });
$("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; });
$("#opt_submit").click(function() { $("#opt_submit").click(function() {
var ptitle = $("#opt_pagetitle").val(); var ptitle = $("#opt_pagetitle").val();
@ -320,6 +323,7 @@ function largeLayout() {
chat.removeClass().addClass("span8 offset2").appendTo(r); chat.removeClass().addClass("span8 offset2").appendTo(r);
$("#userlist").css("width", "200px"); $("#userlist").css("width", "200px");
//$("#chatline").css("width", "756px"); //$("#chatline").css("width", "756px");
initChatCallback();
} }
function hugeLayout() { function hugeLayout() {
@ -335,6 +339,7 @@ function hugeLayout() {
$("#userlist").css("width", "200px").css("height", "200px"); $("#userlist").css("width", "200px").css("height", "200px");
$("#messagebuffer").css("height", "200px"); $("#messagebuffer").css("height", "200px");
//$("#chatline").css("width", "1156px"); //$("#chatline").css("width", "1156px");
initChatCallback();
} }
function narrowLayout() { function narrowLayout() {
@ -349,6 +354,7 @@ function narrowLayout() {
chat.removeClass().addClass("span6").appendTo(r); chat.removeClass().addClass("span6").appendTo(r);
$("#userlist").css("width", "150px"); $("#userlist").css("width", "150px");
//$("#chatline").css("width", "556px"); //$("#chatline").css("width", "556px");
initChatCallback();
} }
function synchtubeLayout() { function synchtubeLayout() {