diff --git a/group/templates/group/group_reply_list.html b/group/templates/group/group_reply_list.html index 58a73e943d..76ce381c2a 100644 --- a/group/templates/group/group_reply_list.html +++ b/group/templates/group/group_reply_list.html @@ -12,6 +12,6 @@ {% endfor %} - +

输入不能为空且应少于150个字符。

diff --git a/group/templates/group/msg_reply_js.html b/group/templates/group/msg_reply_js.html index b0a49e2685..9dbd340ddd 100644 --- a/group/templates/group/msg_reply_js.html +++ b/group/templates/group/msg_reply_js.html @@ -8,7 +8,8 @@ $('.reply, .replyclose').hover( ); $('.reply').click(function() { var msg_id = $(this).attr('data'), - msg_bd = $(this).parent(); + msg_bd = $(this).parent(), + reply_cnt = msg_bd.find('.reply-cnt'); $.ajax({ url: '{{ SITE_ROOT }}group/reply/' + msg_id + '/', dataType: 'json', @@ -16,11 +17,16 @@ $('.reply').click(function() { contentType: 'application/json; charset=utf-8', success: function(data) { msg_bd.children('.reply-bd').html(data['html']).attr('class', 'reply-bd'); - msg_bd.find('.reply-at').click(function() { - msg_bd.find('.reply-input').val('@' + $(this).attr('data') + ' ').focus(); - }); + var reply_input = msg_bd.find('.reply-input'), + error = msg_bd.find('.error'); + function handleReplyInput() { + reply_input.val('@' + $(this).attr('data') + ' '); + var pos = reply_input.val().length; + setSelectionRange(reply_input[0], pos, pos); + } + msg_bd.find('.reply-at').click(handleReplyInput); msg_bd.find('.submit').click(function() { - var reply = $.trim(msg_bd.find('.reply-input').val()); + var reply = $.trim(reply_input.val()); if (reply && reply.length <= 150) { $.ajax({ type: "POST", @@ -32,17 +38,14 @@ $('.reply').click(function() { data: "message=" + reply, success: function(data) { msg_bd.find('.reply-list').append(data['html']); - msg_bd.find('.reply-input').val(''); - msg_bd.find('.error').attr('class', 'error hide'); - var reply_cnt = parseInt(msg_bd.find('.reply-cnt').html()) + 1 || 1; - msg_bd.find('.reply-cnt').html(reply_cnt + ' '); - msg_bd.find('.reply-at').click(function() { - msg_bd.find('.reply-input').val('@' + $(this).attr('data') + ' ').focus(); - }); + reply_input.val(''); + error.attr('class', 'error hide'); + reply_cnt.html((parseInt(reply_cnt.html()) + 1 || 1) + ' '); + msg_bd.find('.reply-at').click(handleReplyInput); } }); } else { - msg_bd.find('.error').removeClass('hide'); + error.removeClass('hide'); } }); } @@ -56,3 +59,17 @@ $('.replyclose').click(function() { $(this).addClass('hide'); $(this).prev().removeClass('hide'); // show 'reply' }); + +function setSelectionRange(input, selectionStart, selectionEnd) { + if (input.setSelectionRange) { + input.focus(); + input.setSelectionRange(selectionStart, selectionEnd); + } + else if (input.createTextRange) { + var range = input.createTextRange(); + range.collapse(true); + range.moveEnd('character', selectionEnd); + range.moveStart('character', selectionStart); + range.select(); + } +} diff --git a/group/templates/group/new_msg_reply.html b/group/templates/group/new_msg_reply.html index 624ff40408..affcecab99 100644 --- a/group/templates/group/new_msg_reply.html +++ b/group/templates/group/new_msg_reply.html @@ -44,7 +44,7 @@ {% endfor %} - +

输入不能为空且应少于150个字符。

@@ -62,12 +62,18 @@ diff --git a/media/css/seahub.css b/media/css/seahub.css index 6c5b34b932..924f3b5042 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -739,6 +739,10 @@ p { } .reply-input { width:82%; + padding:0 1px; + height:20px; + line-height:20px; + vertical-align:bottom; } .reply-at { font-size:12px;