From 22d0ee55f68ac6ff4d964b86531aa28dbde15d4c Mon Sep 17 00:00:00 2001 From: Jeff Arnold Date: Tue, 26 Nov 2013 17:42:39 -0500 Subject: [PATCH] autosize_textarea() is slow, so avoid it while the user is waiting We need to resize the textarea when it is changed via .val(). By clearing and resizing the compose box when it is closed, we can avoid calling autosize_textarea() when the user opens the compose box. This saves at least 15ms on every compose and might also be a cause of longer delays. (imported from commit fe6e092efcd1c4b95a868ee66653448f99af84c0) --- static/js/compose.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/js/compose.js b/static/js/compose.js index 86f40c8f7e..882effd663 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -61,7 +61,6 @@ function show_box(tabname, focus_area, opts) { } $("#send-status").removeClass(status_classes).hide(); $('#compose').css({visibility: "visible"}); - autosize_textarea(); $(".new_message_textarea").css("min-height", "3em"); if (focus_area !== undefined && @@ -97,6 +96,7 @@ function clear_box() { exports.snapshot_message(); clear_invites(); $("#compose").find('input[type=text], textarea').val(''); + autosize_textarea(); $("#send-status").hide(0); } @@ -206,7 +206,7 @@ exports.start = function (msg_type, opts) { opts = fill_in_opts_from_current_narrowed_view(msg_type, opts); - if (!same_recipient_as_before(msg_type, opts)) { + if (compose.composing() && !same_recipient_as_before(msg_type, opts)) { // Clear the compose box if the existing message is to a different recipient clear_box(); } @@ -882,6 +882,7 @@ $(function () { compose.start('stream'); } textbox.val(textbox.val() + contents); + autosize_textarea(); } }); });