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?
|
// todo: Refactor pills subsystem to use modern javascript classes?
|
||||||
|
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import render_input_pill from "../templates/input_pill.hbs";
|
import render_input_pill from "../templates/input_pill.hbs";
|
||||||
|
|
||||||
@@ -408,9 +409,8 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// get text representation of clipboard
|
// get text representation of clipboard
|
||||||
const text = ((e.originalEvent ?? e) as ClipboardEvent).clipboardData?.getData(
|
assert(e.originalEvent instanceof ClipboardEvent);
|
||||||
"text/plain",
|
const text = e.originalEvent.clipboardData?.getData("text/plain");
|
||||||
);
|
|
||||||
|
|
||||||
// insert text manually
|
// insert text manually
|
||||||
document.execCommand("insertText", false, text);
|
document.execCommand("insertText", false, text);
|
||||||
@@ -440,10 +440,8 @@ export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T
|
|||||||
store.$parent.on("copy", ".pill", (e) => {
|
store.$parent.on("copy", ".pill", (e) => {
|
||||||
const element: HTMLElement = e.currentTarget;
|
const element: HTMLElement = e.currentTarget;
|
||||||
const {item} = funcs.getByElement(element)!;
|
const {item} = funcs.getByElement(element)!;
|
||||||
(e.originalEvent as ClipboardEvent).clipboardData?.setData(
|
assert(e.originalEvent instanceof ClipboardEvent);
|
||||||
"text/plain",
|
e.originalEvent.clipboardData?.setData("text/plain", store.get_text_from_item(item));
|
||||||
store.get_text_from_item(item),
|
|
||||||
);
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import Micromodal from "micromodal";
|
import Micromodal from "micromodal";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as overlay_util from "./overlay_util";
|
import * as overlay_util from "./overlay_util";
|
||||||
@@ -105,7 +106,8 @@ export function open(
|
|||||||
const $micromodal = $(id_selector);
|
const $micromodal = $(id_selector);
|
||||||
|
|
||||||
$micromodal.find(".modal__container").on("animationend", (event) => {
|
$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") {
|
if (animation_name === "mmfadeIn") {
|
||||||
// Micromodal adds the is-open class before the modal animation
|
// Micromodal adds the is-open class before the modal animation
|
||||||
// is complete, which isn't really helpful since a modal is open after the
|
// 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
|
// mechanism as a convenience for hooks only known when
|
||||||
// closing the modal.
|
// closing the modal.
|
||||||
$micromodal.find(".modal__container").on("animationend", (event) => {
|
$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) {
|
if (animation_name === "mmfadeOut" && conf.on_hidden) {
|
||||||
conf.on_hidden();
|
conf.on_hidden();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import Micromodal from "micromodal";
|
import Micromodal from "micromodal";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import * as blueslip from "../blueslip";
|
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);
|
const $micromodal = $(id_selector);
|
||||||
|
|
||||||
$micromodal.find(".modal__container").on("animationend", (event) => {
|
$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") {
|
if (animation_name === "mmfadeIn") {
|
||||||
// Micromodal adds the is-open class before the modal animation
|
// Micromodal adds the is-open class before the modal animation
|
||||||
// is complete, which isn't really helpful since a modal is open after the
|
// 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");
|
const $ = require("./lib/zjquery");
|
||||||
|
|
||||||
set_global("document", {});
|
set_global("document", {});
|
||||||
|
class ClipboardEvent {}
|
||||||
|
set_global("ClipboardEvent", ClipboardEvent);
|
||||||
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
const example_img_link = "http://example.com/example.png";
|
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 $pill_stub = "<pill-stub RED>";
|
||||||
|
|
||||||
const e = {
|
const originalEvent = new ClipboardEvent();
|
||||||
currentTarget: $pill_stub,
|
originalEvent.clipboardData = {
|
||||||
originalEvent: {
|
|
||||||
clipboardData: {
|
|
||||||
setData(format, text) {
|
setData(format, text) {
|
||||||
assert.equal(format, "text/plain");
|
assert.equal(format, "text/plain");
|
||||||
copied_text = text;
|
copied_text = text;
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
},
|
const e = {
|
||||||
|
currentTarget: $pill_stub,
|
||||||
|
originalEvent,
|
||||||
preventDefault: noop,
|
preventDefault: noop,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -198,15 +200,15 @@ run_test("paste to input", ({mock_template}) => {
|
|||||||
|
|
||||||
const paste_text = "blue,yellow";
|
const paste_text = "blue,yellow";
|
||||||
|
|
||||||
const e = {
|
const originalEvent = new ClipboardEvent();
|
||||||
originalEvent: {
|
originalEvent.clipboardData = {
|
||||||
clipboardData: {
|
|
||||||
getData(format) {
|
getData(format) {
|
||||||
assert.equal(format, "text/plain");
|
assert.equal(format, "text/plain");
|
||||||
return paste_text;
|
return paste_text;
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
},
|
const e = {
|
||||||
|
originalEvent,
|
||||||
preventDefault: noop,
|
preventDefault: noop,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user