Various fixes

This commit is contained in:
Hexagon 2014-09-21 14:55:24 +02:00
parent c0630dcffc
commit 0c4c096e26
3 changed files with 16 additions and 5 deletions

View File

@ -12,7 +12,9 @@ define('cryptalk', {
room, room,
hash, hash,
nick, nick,
mute = false, mute = false,
history = [], history = [],
history_pos = -1, history_pos = -1,
history_keep = 4, history_keep = 4,
@ -154,7 +156,8 @@ define('cryptalk', {
// The Document object is bound to this element. // The Document object is bound to this element.
// If the active element is not the input, focus on it and exit the function. // If the active element is not the input, focus on it and exit the function.
if (components.input[0] !== $.activeElement()) { // Ignore this when ctrl and/or alt is pressed!
if (components.input[0] !== $.activeElement() && !e.ctrlKey && !e.altKey) {
return components.input.focus(); return components.input.focus();
} }
@ -174,8 +177,14 @@ define('cryptalk', {
if (e.keyCode == 38 ) { history_pos = (history_pos > history.length - 2) ? -1 : history_pos = history_pos + 1; } if (e.keyCode == 38 ) { history_pos = (history_pos > history.length - 2) ? -1 : history_pos = history_pos + 1; }
else { history_pos = (history_pos <= 0) ? -1 : history_pos = history_pos - 1; } else { history_pos = (history_pos <= 0) ? -1 : history_pos = history_pos - 1; }
return components.input[0].value = (history_pos == -1) ? '' : history[history.length-1-history_pos]; var input = components.input[0];
} input.value = (history_pos == -1) ? '' : history[history.length-1-history_pos];
// Wierd hack to move caret to end of input-box
setTimeout(function() {if(input.setSelectionRange) input.setSelectionRange(input.value.length, input.value.length);}, 0);
return;
}
// Return immediatly if the buffer is empty or if the hit key was not <enter> // Return immediatly if the buffer is empty or if the hit key was not <enter>
if (e.keyCode !== 13 || !(buffer = components.input[0].value)) { if (e.keyCode !== 13 || !(buffer = components.input[0].value)) {
@ -248,7 +257,9 @@ define('cryptalk', {
}) })
.on('room:generated', function (data) { .on('room:generated', function (data) {
socket.emit('room:join', data); var sanitized = $.escapeHtml(data);
post('server', $.template(templates.server.room_generated, { payload: sanitized }));
socket.emit('room:join', sanitized);
}) })
.on('room:joined', function (data) { .on('room:joined', function (data) {

View File

@ -85,6 +85,7 @@ define({
server: { server: {
person_joined: 'A person joined this room.', person_joined: 'A person joined this room.',
person_left: 'A person left this room.', person_left: 'A person left this room.',
room_generated: 'Room {payload} generated.',
person_count: 'There is {payload} person(s) in this room, including you.', person_count: 'There is {payload} person(s) in this room, including you.',
command_failed: 'Server command failed, you\'re probably trying to du something bogus.', command_failed: 'Server command failed, you\'re probably trying to du something bogus.',
bogus: 'Received a bogus message from server.', bogus: 'Received a bogus message from server.',

View File

@ -8,7 +8,6 @@ app.use(express.static(__dirname + '/public'));
app.io.route('room', { app.io.route('room', {
generate: function(req) { generate: function(req) {
var room = uuid.v4(); var room = uuid.v4();
req.socket.emit('message:server', 'Room ' + room + ' generated');
req.socket.emit('room:generated',room); req.socket.emit('room:generated',room);
}, },
join: function(req) { join: function(req) {