mirror of https://github.com/zulip/zulip.git
message_list_hover: Convert module to TypeScript.
This commit is contained in:
parent
afa741f248
commit
7302499485
|
@ -146,7 +146,7 @@ EXEMPT_FILES = make_set(
|
||||||
"web/src/message_list.ts",
|
"web/src/message_list.ts",
|
||||||
"web/src/message_list_data.ts",
|
"web/src/message_list_data.ts",
|
||||||
"web/src/message_list_data_cache.ts",
|
"web/src/message_list_data_cache.ts",
|
||||||
"web/src/message_list_hover.js",
|
"web/src/message_list_hover.ts",
|
||||||
"web/src/message_list_tooltips.ts",
|
"web/src/message_list_tooltips.ts",
|
||||||
"web/src/message_list_view.ts",
|
"web/src/message_list_view.ts",
|
||||||
"web/src/message_lists.ts",
|
"web/src/message_lists.ts",
|
||||||
|
|
|
@ -9,8 +9,8 @@ import * as rows from "./rows";
|
||||||
import * as thumbnail from "./thumbnail";
|
import * as thumbnail from "./thumbnail";
|
||||||
import {user_settings} from "./user_settings";
|
import {user_settings} from "./user_settings";
|
||||||
|
|
||||||
let $current_message_hover;
|
let $current_message_hover: JQuery | undefined;
|
||||||
export function message_unhover() {
|
export function message_unhover(): void {
|
||||||
if ($current_message_hover === undefined) {
|
if ($current_message_hover === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,11 @@ export function message_unhover() {
|
||||||
$current_message_hover = undefined;
|
$current_message_hover = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function message_hover($message_row) {
|
export function message_hover($message_row: JQuery): void {
|
||||||
const id = rows.id($message_row);
|
const id = rows.id($message_row);
|
||||||
assert(message_lists.current !== undefined);
|
assert(message_lists.current !== undefined);
|
||||||
const message = message_lists.current.get(id);
|
const message = message_lists.current.get(id);
|
||||||
|
assert(message !== undefined);
|
||||||
|
|
||||||
if ($current_message_hover && rows.id($current_message_hover) === id) {
|
if ($current_message_hover && rows.id($current_message_hover) === id) {
|
||||||
return;
|
return;
|
||||||
|
@ -54,8 +55,8 @@ export function message_hover($message_row) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initialize() {
|
export function initialize(): void {
|
||||||
$("#main_div").on("mouseover", ".message-list .message_row", function () {
|
$("#main_div").on("mouseover", ".message-list .message_row", function (this: HTMLElement) {
|
||||||
const $row = $(this).closest(".message_row");
|
const $row = $(this).closest(".message_row");
|
||||||
message_hover($row);
|
message_hover($row);
|
||||||
});
|
});
|
||||||
|
@ -64,12 +65,12 @@ export function initialize() {
|
||||||
message_unhover();
|
message_unhover();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#main_div").on("mouseover", ".sender_info_hover", function () {
|
$("#main_div").on("mouseover", ".sender_info_hover", function (this: HTMLElement) {
|
||||||
const $row = $(this).closest(".message_row");
|
const $row = $(this).closest(".message_row");
|
||||||
$row.addClass("sender_info_hovered");
|
$row.addClass("sender_info_hovered");
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#main_div").on("mouseout", ".sender_info_hover", function () {
|
$("#main_div").on("mouseout", ".sender_info_hover", function (this: HTMLElement) {
|
||||||
const $row = $(this).closest(".message_row");
|
const $row = $(this).closest(".message_row");
|
||||||
$row.removeClass("sender_info_hovered");
|
$row.removeClass("sender_info_hovered");
|
||||||
});
|
});
|
||||||
|
@ -77,7 +78,7 @@ export function initialize() {
|
||||||
$("#main_div").on(
|
$("#main_div").on(
|
||||||
"mouseover",
|
"mouseover",
|
||||||
'.message-list div.message_inline_image img[data-animated="true"]',
|
'.message-list div.message_inline_image img[data-animated="true"]',
|
||||||
function () {
|
function (this: HTMLElement) {
|
||||||
if (user_settings.web_animate_image_previews !== "on_hover") {
|
if (user_settings.web_animate_image_previews !== "on_hover") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +88,7 @@ export function initialize() {
|
||||||
);
|
);
|
||||||
$img.attr(
|
$img.attr(
|
||||||
"src",
|
"src",
|
||||||
$img.attr("src").replace(/\/[^/]+$/, "/" + thumbnail.animated_format.name),
|
$img.attr("src")!.replace(/\/[^/]+$/, "/" + thumbnail.animated_format.name),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -95,7 +96,7 @@ export function initialize() {
|
||||||
$("#main_div").on(
|
$("#main_div").on(
|
||||||
"mouseout",
|
"mouseout",
|
||||||
'.message-list div.message_inline_image img[data-animated="true"]',
|
'.message-list div.message_inline_image img[data-animated="true"]',
|
||||||
function () {
|
function (this: HTMLElement) {
|
||||||
if (user_settings.web_animate_image_previews !== "on_hover") {
|
if (user_settings.web_animate_image_previews !== "on_hover") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -103,17 +104,17 @@ export function initialize() {
|
||||||
$img.closest(".message_inline_image").addClass("message_inline_animated_image_still");
|
$img.closest(".message_inline_image").addClass("message_inline_animated_image_still");
|
||||||
$img.attr(
|
$img.attr(
|
||||||
"src",
|
"src",
|
||||||
$img.attr("src").replace(/\/[^/]+$/, "/" + thumbnail.preferred_format.name),
|
$img.attr("src")!.replace(/\/[^/]+$/, "/" + thumbnail.preferred_format.name),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
function handle_video_preview_mouseenter($elem) {
|
function handle_video_preview_mouseenter($elem: JQuery): void {
|
||||||
// Set image height and css vars for play button position, if not done already
|
// Set image height and css vars for play button position, if not done already
|
||||||
const setPosition = !$elem.data("entered-before");
|
const setPosition = !$elem.data("entered-before");
|
||||||
if (setPosition) {
|
if (setPosition) {
|
||||||
const imgW = $elem.find("img")[0].width;
|
const imgW = $elem.find("img")[0]!.width;
|
||||||
const imgH = $elem.find("img")[0].height;
|
const imgH = $elem.find("img")[0]!.height;
|
||||||
// Ensure height doesn't change on mouse enter
|
// Ensure height doesn't change on mouse enter
|
||||||
$elem.css("height", `${imgH}px`);
|
$elem.css("height", `${imgH}px`);
|
||||||
// variables to set play button position
|
// variables to set play button position
|
||||||
|
@ -125,7 +126,7 @@ export function initialize() {
|
||||||
$elem.addClass("fa fa-play");
|
$elem.addClass("fa fa-play");
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#main_div").on("mouseenter", ".youtube-video a", function () {
|
$("#main_div").on("mouseenter", ".youtube-video a", function (this: HTMLElement) {
|
||||||
handle_video_preview_mouseenter($(this));
|
handle_video_preview_mouseenter($(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ export function initialize() {
|
||||||
$(this).removeClass("fa fa-play");
|
$(this).removeClass("fa fa-play");
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#main_div").on("mouseenter", ".embed-video a", function () {
|
$("#main_div").on("mouseenter", ".embed-video a", function (this: HTMLElement) {
|
||||||
handle_video_preview_mouseenter($(this));
|
handle_video_preview_mouseenter($(this));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue