refactor: Move `replace_emoji_with_text` from `ui` to `ui_util`.

This commit is contained in:
Lalit 2023-04-25 10:08:51 +05:30 committed by Tim Abbott
parent e132a68193
commit b55ee161e2
3 changed files with 10 additions and 11 deletions

View File

@ -23,7 +23,6 @@ import * as settings_config from "./settings_config";
import * as spoilers from "./spoilers"; import * as spoilers from "./spoilers";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_ui_updates from "./stream_ui_updates"; import * as stream_ui_updates from "./stream_ui_updates";
import * as ui from "./ui";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
import * as unread from "./unread"; import * as unread from "./unread";
import * as unread_ops from "./unread_ops"; import * as unread_ops from "./unread_ops";
@ -258,7 +257,7 @@ export function process_notification(notification) {
let notification_source; let notification_source;
// Convert the content to plain text, replacing emoji with their alt text // Convert the content to plain text, replacing emoji with their alt text
const $content = $("<div>").html(message.content); const $content = $("<div>").html(message.content);
ui.replace_emoji_with_text($content); ui_util.replace_emoji_with_text($content);
spoilers.hide_spoilers_in_notification($content); spoilers.hide_spoilers_in_notification($content);
if ( if (

View File

@ -3,15 +3,6 @@ import SimpleBar from "simplebar";
// What, if anything, obscures the home tab? // What, if anything, obscures the home tab?
export function replace_emoji_with_text($element) {
$element.find(".emoji").replaceWith(function () {
if ($(this).is("img")) {
return $(this).attr("alt");
}
return $(this).text();
});
}
export function get_content_element($element) { export function get_content_element($element) {
const element = $element.expectOne()[0]; const element = $element.expectOne()[0];
const sb = SimpleBar.instances.get(element); const sb = SimpleBar.instances.get(element);

View File

@ -21,6 +21,15 @@ export function place_caret_at_end(el: HTMLElement): void {
} }
} }
export function replace_emoji_with_text($element: JQuery): void {
$element.find(".emoji").replaceWith(function () {
if ($(this).is("img")) {
return $(this).attr("alt") ?? "";
}
return $(this).text();
});
}
export function blur_active_element(): void { export function blur_active_element(): void {
// this blurs anything that may perhaps be actively focused on. // this blurs anything that may perhaps be actively focused on.
if (document.activeElement instanceof HTMLElement) { if (document.activeElement instanceof HTMLElement) {