Better fix for previous commit

This commit is contained in:
calzoneman 2013-03-31 20:29:39 -05:00
parent 28b9bdb54d
commit a0c26ee0e5
1 changed files with 61 additions and 67 deletions

View File

@ -197,70 +197,67 @@ $("#register").click(function() {
});
});
function initChatCallback() {
$("#chatline").keydown(function(ev) {
if(ev.keyCode == 13 && $("#chatline").val() != "") {
socket.emit("chatMsg", {
msg: $("#chatline").val()
});
$("#chatline").keydown(function(ev) {
if(ev.keyCode == 13 && $("#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());
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;
if(CHATHISTIDX > 0) {
CHATHISTIDX--;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
else if(ev.keyCode == 38) {
if(CHATHISTIDX == CHATHIST.length) {
CHATHIST.push($("#chatline").val());
}
if(CHATHISTIDX > 0) {
CHATHISTIDX--;
$("#chatline").val(CHATHIST[CHATHISTIDX]);
}
ev.preventDefault();
return false;
ev.preventDefault();
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();
return false;
}
});
$("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; });
$("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; });
}
initChatCallback();
ev.preventDefault();
return false;
}
});
$("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; });
$("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; });
$("#opt_submit").click(function() {
@ -316,14 +313,13 @@ function largeLayout() {
VWIDTH = "770";
VHEIGHT = "430";
$("#ytapiplayer").attr("width", "770").attr("height", "430");
var chat = $("#chatdiv").remove();
var chat = $("#chatdiv").detach();
$("#layoutrow").remove();
var r = $("<div />").addClass("row").insertAfter($(".row")[1]);
r.attr("id", "layoutrow");
chat.removeClass().addClass("span8 offset2").appendTo(r);
$("#userlist").css("width", "200px");
//$("#chatline").css("width", "756px");
initChatCallback();
}
function hugeLayout() {
@ -331,7 +327,7 @@ function hugeLayout() {
VHEIGHT = "658";
$("#videodiv").removeClass().addClass("span12");
$("#ytapiplayer").attr("width", "1170").attr("height", "658");
var chat = $("#chatdiv").remove();
var chat = $("#chatdiv").detach();
$("#layoutrow").remove();
var r = $("<div />").addClass("row").insertAfter($(".row")[1]);
r.attr("id", "layoutrow");
@ -339,7 +335,6 @@ function hugeLayout() {
$("#userlist").css("width", "200px").css("height", "200px");
$("#messagebuffer").css("height", "200px");
//$("#chatline").css("width", "1156px");
initChatCallback();
}
function narrowLayout() {
@ -347,18 +342,17 @@ function narrowLayout() {
VHEIGHT = "321";
$("#videodiv").removeClass().addClass("span6");
$("#ytapiplayer").attr("width", "570").attr("height", "321");
var chat = $("#chatdiv").remove();
var chat = $("#chatdiv").detach();
$("#layoutrow").remove();
var r = $("<div />").addClass("row").insertAfter($(".row")[1]);
r.attr("id", "layoutrow");
chat.removeClass().addClass("span6").appendTo(r);
$("#userlist").css("width", "150px");
//$("#chatline").css("width", "556px");
initChatCallback();
}
function synchtubeLayout() {
$("#videodiv").remove().insertBefore($("#chatdiv"));
$("#videodiv").detach().insertBefore($("#chatdiv"));
}
function onYouTubeIframeAPIReady() {