mirror of https://github.com/zulip/zulip.git
zjquery: Fix event parameter of invoked handlers.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
af3a79ab31
commit
2bbd8265b9
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue