Skip to content

Commit

Permalink
compose: Make a toggler for full screen size compose box.
Browse files Browse the repository at this point in the history
This commit makes a working toggler in compose_actions that changes the
max height and max height accordingly making the compose box full size.
The compose_height.js maintains the state of the height of the compose
box and according to it, the toggler updates the height. Also, when the
compose box is closed, the compose box is reset to it's default behaviour
and height as expected. So, everytime user need not toggle for every
message.

Fixes #17660
  • Loading branch information
Signior-X committed Mar 26, 2021
1 parent e0ed88f commit 04db46a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions static/js/compose.js
Expand Up @@ -13,6 +13,7 @@ import * as channel from "./channel";
import * as common from "./common";
import * as compose_actions from "./compose_actions";
import * as compose_fade from "./compose_fade";
import * as compose_height from "./compose_height";
import * as compose_pm_pill from "./compose_pm_pill";
import * as compose_state from "./compose_state";
import * as compose_ui from "./compose_ui";
Expand Down Expand Up @@ -1296,6 +1297,12 @@ export function initialize() {
clear_preview_area();
});

// Expansion and Collapsing of the composebox from original height to full height
$("#compose").on("click", "#full_size_compose_button", (e) => {
e.preventDefault();
compose_height.toggle_compose_height();
});

uppy = upload.setup_upload({
mode: "compose",
});
Expand Down
3 changes: 3 additions & 0 deletions static/js/compose_actions.js
Expand Up @@ -7,6 +7,7 @@ import * as channel from "./channel";
import * as common from "./common";
import * as compose from "./compose";
import * as compose_fade from "./compose_fade";
import * as compose_height from "./compose_height";
import * as compose_pm_pill from "./compose_pm_pill";
import * as compose_state from "./compose_state";
import * as compose_ui from "./compose_ui";
Expand Down Expand Up @@ -268,6 +269,8 @@ export function start(msg_type, opts) {
}

export function cancel() {
// As user closes the compose box, restore the compose box max height
compose_height.reset_compose_box_height();
$("#compose-textarea").height(40 + "px");

if (page_params.narrow !== undefined) {
Expand Down
54 changes: 54 additions & 0 deletions static/js/compose_height.js
@@ -0,0 +1,54 @@
// Making this similar to compose_state.js

import $ from "jquery";

import * as blueslip from "./blueslip";
import * as compose_ui from "./compose_ui";

const compose_textarea = $("#compose-textarea");
let is_full_size = false; // true or false

function get_expected_full_height() {
// This returns the full size of the compose box
// Panels can have different height and this calculates it accordignly
return window.innerHeight - 138 - Number.parseInt($("#panels").css("height"), 10);
}

// Some functions to handle the state explicitely
export function set_is_full_size(is_full) {
is_full_size = is_full;
}

export function get_is_full_size() {
return is_full_size;
}

export function make_compose_box_full_size() {
compose_textarea.css("max-height", get_expected_full_height());
compose_textarea.css("height", get_expected_full_height());
$("#floating_recipient_bar").css("z-index", -1);
}

export function make_compose_box_original_size() {
compose_textarea.css("max-height", "calc(50vh - 50px)");
$("#floating_recipient_bar").css("z-index", 98);
}

export function toggle_compose_height() {
if (is_full_size) {
make_compose_box_original_size();
set_is_full_size(false);

// Finally make the textarea autoresize accordingly
compose_ui.autosize_textarea($("#compose-textarea"));
} else {
// Makes the compose_box full size
make_compose_box_full_size();
set_is_full_size(true);
}
}

export function reset_compose_box_height() {
set_is_full_size(false);
make_compose_box_original_size();
}
1 change: 1 addition & 0 deletions templates/zerver/app/compose.html
Expand Up @@ -101,6 +101,7 @@
<a role="button" id="undo_markdown_preview" class="message-control-button fa fa-edit" aria-label="{{ _('Write') }}" tabindex=0 style="display:none;" title="{{ _('Write') }}"></a>
<a role="button" class="message-control-button fa fa-video-camera video_link" aria-label="{{ _('Add video call') }}" tabindex=0 title="{{ _('Add video call') }}"></a>
<a role="button" class="message-control-button fa fa-smile-o" aria-label="{{_('Add emoji')}}" id="emoji_map" tabindex=0 title="{{ _('Add emoji') }}"></a>
<a role="button" class="message-control-button fa fa-expand" aria-label="{{_('Expand composebox')}}" id="full_size_compose_button" tabindex=0 title="{{ _('Expand composebox') }}"></a>
<a class="message-control-link drafts-link" href="#drafts" title="{{ _('Drafts') }} (d)">{{ _('Drafts') }}</a>
<a role="button" class="message-control-link" tabindex=0 data-overlay-trigger="message-formatting">{{ _('Help') }}</a>
<span id="sending-indicator"></span>
Expand Down

0 comments on commit 04db46a

Please sign in to comment.