From 0c4c096e2605dddd6acdc5791c6226e4ff265bb2 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Sun, 21 Sep 2014 14:55:24 +0200 Subject: [PATCH] Various fixes --- public/js/cryptalk_modules/cryptalk.js | 19 +++++++++++++++---- public/js/cryptalk_modules/templates.js | 1 + server.js | 1 - 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/public/js/cryptalk_modules/cryptalk.js b/public/js/cryptalk_modules/cryptalk.js index ff26b18..9ac1967 100644 --- a/public/js/cryptalk_modules/cryptalk.js +++ b/public/js/cryptalk_modules/cryptalk.js @@ -12,7 +12,9 @@ define('cryptalk', { room, hash, nick, + mute = false, + history = [], history_pos = -1, history_keep = 4, @@ -154,7 +156,8 @@ define('cryptalk', { // The Document object is bound to this element. // 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(); } @@ -174,8 +177,14 @@ define('cryptalk', { 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; } - 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 if (e.keyCode !== 13 || !(buffer = components.input[0].value)) { @@ -248,7 +257,9 @@ define('cryptalk', { }) .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) { diff --git a/public/js/cryptalk_modules/templates.js b/public/js/cryptalk_modules/templates.js index 3c6cb6a..719e738 100644 --- a/public/js/cryptalk_modules/templates.js +++ b/public/js/cryptalk_modules/templates.js @@ -85,6 +85,7 @@ define({ server: { person_joined: 'A person joined 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.', command_failed: 'Server command failed, you\'re probably trying to du something bogus.', bogus: 'Received a bogus message from server.', diff --git a/server.js b/server.js index 07c3952..b0ed501 100644 --- a/server.js +++ b/server.js @@ -8,7 +8,6 @@ app.use(express.static(__dirname + '/public')); app.io.route('room', { generate: function(req) { var room = uuid.v4(); - req.socket.emit('message:server', 'Room ' + room + ' generated'); req.socket.emit('room:generated',room); }, join: function(req) {