1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[mujs] event.preventDefault

This commit is contained in:
Witold Filipczyk 2024-03-10 18:11:44 +01:00
parent da7a525c99
commit 0d28694b45

View File

@ -22,6 +22,8 @@ static void mjs_event_get_property_composed(js_State *J);
static void mjs_event_get_property_defaultPrevented(js_State *J); static void mjs_event_get_property_defaultPrevented(js_State *J);
static void mjs_event_get_property_type(js_State *J); static void mjs_event_get_property_type(js_State *J);
static void mjs_event_preventDefault(js_State *J);
struct eljs_event { struct eljs_event {
char *type_; char *type_;
unsigned int bubbles:1; unsigned int bubbles:1;
@ -55,6 +57,7 @@ mjs_push_event(js_State *J, char *type_)
js_newobject(J); js_newobject(J);
{ {
js_newuserdata(J, "event", event, mjs_event_finalizer); js_newuserdata(J, "event", event, mjs_event_finalizer);
addmethod(J, "preventDefault", mjs_event_preventDefault, 0);
addproperty(J, "bubbles", mjs_event_get_property_bubbles, NULL); addproperty(J, "bubbles", mjs_event_get_property_bubbles, NULL);
addproperty(J, "cancelable", mjs_event_get_property_cancelable, NULL); addproperty(J, "cancelable", mjs_event_get_property_cancelable, NULL);
addproperty(J, "composed", mjs_event_get_property_composed, NULL); addproperty(J, "composed", mjs_event_get_property_composed, NULL);
@ -138,6 +141,24 @@ mjs_event_get_property_type(js_State *J)
js_pushstring(J, event->type_ ?: ""); js_pushstring(J, event->type_ ?: "");
} }
static void
mjs_event_preventDefault(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct eljs_event *event = (struct eljs_event *)js_touserdata(J, 0, "event");
if (!event) {
js_pushnull(J);
return;
}
if (event->cancelable) {
event->defaultPrevented = 1;
}
js_pushundefined(J);
}
static void static void
mjs_event_fun(js_State *J) mjs_event_fun(js_State *J)
{ {
@ -163,6 +184,7 @@ mjs_event_constructor(js_State *J)
js_newobject(J); js_newobject(J);
{ {
js_newuserdata(J, "event", event, mjs_event_finalizer); js_newuserdata(J, "event", event, mjs_event_finalizer);
addmethod(J, "preventDefault", mjs_event_preventDefault, 0);
addproperty(J, "bubbles", mjs_event_get_property_bubbles, NULL); addproperty(J, "bubbles", mjs_event_get_property_bubbles, NULL);
addproperty(J, "cancelable", mjs_event_get_property_cancelable, NULL); addproperty(J, "cancelable", mjs_event_get_property_cancelable, NULL);
addproperty(J, "composed", mjs_event_get_property_composed, NULL); addproperty(J, "composed", mjs_event_get_property_composed, NULL);