Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

refactor: Create `compose_textarea` and extracted related handlers from `ui.js`.

Lalite132a6819349
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index de75fce3d11..34cea3f450c 100755
--- a/tools/test-js-with-node
+++ b/tools/test-js-with-node
@@ -67,6 +67,7 @@ EXEMPT_FILES = make_set(
"web/src/compose_fade.js",
"web/src/compose_recipient.js",
"web/src/compose_state.js",
+ "web/src/compose_textarea.js",
"web/src/compose_ui.js",
"web/src/compose_validate.js",
"web/src/composebox_typeahead.js",
diff --git a/web/src/compose_textarea.js b/web/src/compose_textarea.js
new file mode 100644
index 00000000000..f89c2fcfd8c
--- /dev/null
+++ b/web/src/compose_textarea.js
@@ -0,0 +1,25 @@
+import $ from "jquery";
+
+// Save the compose content cursor position and restore when we
+// shift-tab back in (see hotkey.js).
+let saved_compose_cursor = 0;
+
+function set_compose_textarea_handlers() {
+ $("#compose-textarea").on("blur", function () {
+ saved_compose_cursor = $(this).caret();
+ });
+
+ // on the end of the modified-message fade in, remove the fade-in-message class.
+ const animationEnd = "webkitAnimationEnd oanimationend msAnimationEnd animationend";
+ $("body").on(animationEnd, ".fade-in-message", function () {
+ $(this).removeClass("fade-in-message");
+ });
+}
+
+export function restore_compose_cursor() {
+ $("#compose-textarea").trigger("focus").caret(saved_compose_cursor);
+}
+
+export function initialize() {
+ set_compose_textarea_handlers();
+}
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 194ec50449e..101ea7c6ac2 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -8,6 +8,7 @@ import * as compose_actions from "./compose_actions";
import * as compose_banner from "./compose_banner";
import * as compose_recipient from "./compose_recipient";
import * as compose_state from "./compose_state";
+import * as compose_textarea from "./compose_textarea";
import * as condense from "./condense";
import * as copy_and_paste from "./copy_and_paste";
import * as deprecated_feature_notice from "./deprecated_feature_notice";
@@ -44,7 +45,6 @@ import * as stream_list from "./stream_list";
import * as stream_popover from "./stream_popover";
import * as stream_settings_ui from "./stream_settings_ui";
import * as topic_zoom from "./topic_zoom";
-import * as ui from "./ui";
import * as unread_ops from "./unread_ops";
import {user_settings} from "./user_settings";
@@ -557,7 +557,7 @@ export function process_shift_tab_key() {
if ($("#compose-send-button").is(":focus")) {
// Shift-Tab: go back to content textarea and restore
// cursor position.
- ui.restore_compose_cursor();
+ compose_textarea.restore_compose_cursor();
return true;
}
diff --git a/web/src/ui.js b/web/src/ui.js
index c7620cc4271..89f9a43db79 100644
--- a/web/src/ui.js
+++ b/web/src/ui.js
@@ -43,27 +43,3 @@ export function reset_scrollbar($element) {
element.scrollTop = 0;
}
}
-
-// Save the compose content cursor position and restore when we
-// shift-tab back in (see hotkey.js).
-let saved_compose_cursor = 0;
-
-export function set_compose_textarea_handlers() {
- $("#compose-textarea").on("blur", function () {
- saved_compose_cursor = $(this).caret();
- });
-
- // on the end of the modified-message fade in, remove the fade-in-message class.
- const animationEnd = "webkitAnimationEnd oanimationend msAnimationEnd animationend";
- $("body").on(animationEnd, ".fade-in-message", function () {
- $(this).removeClass("fade-in-message");
- });
-}
-
-export function restore_compose_cursor() {
- $("#compose-textarea").trigger("focus").caret(saved_compose_cursor);
-}
-
-export function initialize() {
- set_compose_textarea_handlers();
-}
diff --git a/web/src/ui_init.js b/web/src/ui_init.js
index 954dc8edfa2..b22741c0478 100644
--- a/web/src/ui_init.js
+++ b/web/src/ui_init.js
@@ -24,6 +24,7 @@ import * as compose from "./compose";
import * as compose_closed_ui from "./compose_closed_ui";
import * as compose_pm_pill from "./compose_pm_pill";
import * as compose_recipient from "./compose_recipient";
+import * as compose_textarea from "./compose_textarea";
import * as composebox_typeahead from "./composebox_typeahead";
import * as condense from "./condense";
import * as copy_and_paste from "./copy_and_paste";
@@ -668,6 +669,7 @@ export function initialize_everything() {
realm_playground.initialize(page_params.realm_playgrounds, generated_pygments_data);
compose.initialize();
composebox_typeahead.initialize(); // Must happen after compose.initialize()
+ compose_textarea.initialize();
search.initialize();
tutorial.initialize();
notifications.initialize();
@@ -694,7 +696,6 @@ export function initialize_everything() {
drafts.initialize();
sent_messages.initialize();
hotspots.initialize();
- ui.initialize();
typing.initialize();
starred_messages.initialize();
user_status_ui.initialize();