zjquery: Fix event parameter of invoked handlers.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-20 20:46:22 -07:00 committed by Tim Abbott
parent af3a79ab31
commit 2bbd8265b9
2 changed files with 17 additions and 11 deletions

View File

@ -846,7 +846,7 @@ run_test("finish", () => {
let compose_finished_event_checked = false;
$(document).trigger = function (e) {
assert.equal(e.name, "compose_finished.zulip");
assert.equal(e.type, "compose_finished.zulip");
compose_finished_event_checked = true;
};
let send_message_called = false;

View File

@ -1,5 +1,14 @@
const noop = function () {};
class Event {
constructor(type, props) {
this.type = type;
Object.assign(this, props);
}
preventDefault() {}
stopPropagation() {}
}
exports.make_event_store = (selector) => {
/*
@ -104,9 +113,11 @@ exports.make_event_store = (selector) => {
child_on.set(event_name, handler);
},
trigger: function ($element, ev) {
const ev_name = typeof ev === "string" ? ev : ev.name;
const func = on_functions.get(ev_name);
trigger: function ($element, ev, data) {
if (typeof ev === "string") {
ev = new Event(ev, data);
}
const func = on_functions.get(ev.type);
if (!func) {
// It's possible that test code will trigger events
@ -117,7 +128,7 @@ exports.make_event_store = (selector) => {
return;
}
func.call($element, ev.data);
func.call($element, ev, data);
},
};
@ -533,12 +544,7 @@ exports.make_zjquery = function (opts) {
return res;
};
zjquery.Event = function (name, data) {
return {
name: name,
data: data,
};
};
zjquery.Event = (type, props) => new Event(type, props);
fn.after = function (s) {
return s;