From 7e55e7b3d24bf4e9e3668e44842cd73d46d0d3cc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 6 Jun 2013 15:56:44 -0400 Subject: [PATCH] fixing quoting that broke with the introduction of the new post window --- public/src/app.js | 6 ------ public/src/forum/topic.js | 11 ++++++++--- public/src/modules/composer.js | 15 +++++++++------ src/websockets.js | 1 + 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 451f73e493..79b9636ce8 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -30,12 +30,6 @@ var socket, console.log(data); }); - socket.on('api:posts.getRawPost', function(data) { - var contentEl = document.getElementById('post_content'); - - contentEl.value = data.post; - }); - socket.on('connect', function(data){ if(reconnecting) { setTimeout(function(){ diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 6052629665..aacaae19ab 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -443,10 +443,15 @@ if (thread_state.locked !== '1') { var pid = $(this).parents('li').attr('data-pid'); - require(['composer'], function(cmp) { - cmp.push(tid); - $('.post-window textarea').val('> ' + $('#content_' + pid).html() + '\n'); + socket.once('api:posts.getRawPost', function(data) { + quoted = '> ' + data.post.replace(/\n/g, '\n> ') + '\n\n'; + require(['composer'], function(cmp) { + cmp.push(tid, null, null, quoted); + }); }); + socket.emit('api:posts.getRawPost', { pid: pid }); + // $('.post-window textarea').val('> ' + $('#content_' + pid).html() + '\n'); + // }); } }); diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 217772fae8..50a2673fe5 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -28,12 +28,12 @@ define(function() { '' + '' + '
' + - '' + - '' + - '' + + '' + + '' + + '' + '
' + '' + - '' + + '' + ''; composer.listEl = composer.btnContainer.querySelector('ul'); @@ -167,11 +167,12 @@ define(function() { } } - composer.push = function(tid, cid, pid) { + composer.push = function(tid, cid, pid, text) { socket.emit('api:composer.push', { tid: tid, // Replying cid: cid, // Posting - pid: pid // Editing + pid: pid, // Editing + body: text // Predefined text }); } @@ -202,6 +203,8 @@ define(function() { // Direct user focus to the correct element if ((parseInt(post_data.tid) || parseInt(post_data.pid)) > 0) { bodyEl.focus(); + bodyEl.selectionStart = bodyEl.value.length; + bodyEl.selectionEnd = bodyEl.value.length; } else if (parseInt(post_data.cid) > 0) { titleEl.focus(); } diff --git a/src/websockets.js b/src/websockets.js index 916ab20255..e59784f518 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -316,6 +316,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), if (parseInt(data.tid) > 0) { topics.get_topic(data.tid, uid, function(topicData) { topicData.tid = data.tid; + if (data.body) topicData.body = data.body; socket.emit('api:composer.push', topicData); }); } else if (parseInt(data.cid) > 0) {