mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
web: Remove unchecked casts of event objects.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
1da729e49f
commit
9c9c453d5a
@@ -1,6 +1,7 @@
|
||||
// todo: Refactor pills subsystem to use modern javascript classes?
|
||||
|
||||
import $ from "jquery";
|
||||
import assert from "minimalistic-assert";
|
||||
|
||||
import render_input_pill from "../templates/input_pill.hbs";
|
||||
|
||||
@@ -408,9 +409,8 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
|
||||
e.preventDefault();
|
||||
|
||||
// get text representation of clipboard
|
||||
const text = ((e.originalEvent ?? e) as ClipboardEvent).clipboardData?.getData(
|
||||
"text/plain",
|
||||
);
|
||||
assert(e.originalEvent instanceof ClipboardEvent);
|
||||
const text = e.originalEvent.clipboardData?.getData("text/plain");
|
||||
|
||||
// insert text manually
|
||||
document.execCommand("insertText", false, text);
|
||||
@@ -440,10 +440,8 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
|
||||
store.$parent.on("copy", ".pill", (e) => {
|
||||
const element: HTMLElement = e.currentTarget;
|
||||
const {item} = funcs.getByElement(element)!;
|
||||
(e.originalEvent as ClipboardEvent).clipboardData?.setData(
|
||||
"text/plain",
|
||||
store.get_text_from_item(item),
|
||||
);
|
||||
assert(e.originalEvent instanceof ClipboardEvent);
|
||||
e.originalEvent.clipboardData?.setData("text/plain", store.get_text_from_item(item));
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import $ from "jquery";
|
||||
import Micromodal from "micromodal";
|
||||
import assert from "minimalistic-assert";
|
||||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as overlay_util from "./overlay_util";
|
||||
@@ -105,7 +106,8 @@ export function open(
|
||||
const $micromodal = $(id_selector);
|
||||
|
||||
$micromodal.find(".modal__container").on("animationend", (event) => {
|
||||
const animation_name = (event.originalEvent as AnimationEvent).animationName;
|
||||
assert(event.originalEvent instanceof AnimationEvent);
|
||||
const animation_name = event.originalEvent.animationName;
|
||||
if (animation_name === "mmfadeIn") {
|
||||
// Micromodal adds the is-open class before the modal animation
|
||||
// is complete, which isn't really helpful since a modal is open after the
|
||||
@@ -198,7 +200,8 @@ export function close(modal_id: string, conf: Pick<ModalConfig, "on_hidden"> = {
|
||||
// mechanism as a convenience for hooks only known when
|
||||
// closing the modal.
|
||||
$micromodal.find(".modal__container").on("animationend", (event) => {
|
||||
const animation_name = (event.originalEvent as AnimationEvent).animationName;
|
||||
assert(event.originalEvent instanceof AnimationEvent);
|
||||
const animation_name = event.originalEvent.animationName;
|
||||
if (animation_name === "mmfadeOut" && conf.on_hidden) {
|
||||
conf.on_hidden();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import $ from "jquery";
|
||||
import Micromodal from "micromodal";
|
||||
import assert from "minimalistic-assert";
|
||||
|
||||
import * as blueslip from "../blueslip";
|
||||
|
||||
@@ -77,7 +78,8 @@ export function open(modal_id: string, recursive_call_count: number = 0): void {
|
||||
const $micromodal = $(id_selector);
|
||||
|
||||
$micromodal.find(".modal__container").on("animationend", (event) => {
|
||||
const animation_name = (event.originalEvent as AnimationEvent).animationName;
|
||||
assert(event.originalEvent instanceof AnimationEvent);
|
||||
const animation_name = event.originalEvent.animationName;
|
||||
if (animation_name === "mmfadeIn") {
|
||||
// Micromodal adds the is-open class before the modal animation
|
||||
// is complete, which isn't really helpful since a modal is open after the
|
||||
|
||||
@@ -8,6 +8,8 @@ const blueslip = require("./lib/zblueslip");
|
||||
const $ = require("./lib/zjquery");
|
||||
|
||||
set_global("document", {});
|
||||
class ClipboardEvent {}
|
||||
set_global("ClipboardEvent", ClipboardEvent);
|
||||
|
||||
const noop = () => {};
|
||||
const example_img_link = "http://example.com/example.png";
|
||||
@@ -163,16 +165,16 @@ run_test("copy from pill", ({mock_template}) => {
|
||||
|
||||
const $pill_stub = "<pill-stub RED>";
|
||||
|
||||
const e = {
|
||||
currentTarget: $pill_stub,
|
||||
originalEvent: {
|
||||
clipboardData: {
|
||||
const originalEvent = new ClipboardEvent();
|
||||
originalEvent.clipboardData = {
|
||||
setData(format, text) {
|
||||
assert.equal(format, "text/plain");
|
||||
copied_text = text;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const e = {
|
||||
currentTarget: $pill_stub,
|
||||
originalEvent,
|
||||
preventDefault: noop,
|
||||
};
|
||||
|
||||
@@ -198,15 +200,15 @@ run_test("paste to input", ({mock_template}) => {
|
||||
|
||||
const paste_text = "blue,yellow";
|
||||
|
||||
const e = {
|
||||
originalEvent: {
|
||||
clipboardData: {
|
||||
const originalEvent = new ClipboardEvent();
|
||||
originalEvent.clipboardData = {
|
||||
getData(format) {
|
||||
assert.equal(format, "text/plain");
|
||||
return paste_text;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const e = {
|
||||
originalEvent,
|
||||
preventDefault: noop,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user