mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
zjquery: Add generic event setter/handler.
This commit is contained in:
committed by
Steve Howell
parent
5b0954c29d
commit
ad154da174
@@ -18,7 +18,16 @@ exports.make_zjquery = function () {
|
|||||||
var attrs = new Dict();
|
var attrs = new Dict();
|
||||||
var classes = new Dict();
|
var classes = new Dict();
|
||||||
var on_functions = new Dict();
|
var on_functions = new Dict();
|
||||||
var click_func;
|
|
||||||
|
function generic_event(event_name, arg) {
|
||||||
|
if (typeof(arg) === 'function') {
|
||||||
|
on_functions.set(event_name, arg);
|
||||||
|
} else {
|
||||||
|
var handler = on_functions.get(event_name);
|
||||||
|
assert(handler);
|
||||||
|
handler(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var self = {
|
var self = {
|
||||||
val: function () {
|
val: function () {
|
||||||
@@ -123,14 +132,8 @@ exports.make_zjquery = function () {
|
|||||||
funcs.push(f);
|
funcs.push(f);
|
||||||
return self.wrapper;
|
return self.wrapper;
|
||||||
},
|
},
|
||||||
click: function (f) {
|
click: function (arg) {
|
||||||
if (f) {
|
generic_event('click', arg);
|
||||||
assert.equal(typeof(f), "function");
|
|
||||||
click_func = f;
|
|
||||||
} else {
|
|
||||||
assert(click_func);
|
|
||||||
click_func();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
remove: function () {
|
remove: function () {
|
||||||
if (my_parent) {
|
if (my_parent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user