1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-26 01:15:37 +00:00

[mujs] window.event

This commit is contained in:
Witold Filipczyk 2023-09-21 18:57:26 +02:00
parent ced7b7b294
commit fb1c70564e
4 changed files with 11 additions and 9 deletions

View File

@ -25,6 +25,8 @@ struct keyboard {
unicode_val_T keyCode;
};
extern struct term_event last_event;
static void
mjs_keyboardEvent_finalizer(js_State *J, void *val)
{
@ -44,7 +46,7 @@ mjs_push_keyboardEvent(js_State *J, struct term_event *ev)
js_error(J, "out of memory");
return;
}
keyCode = keyb->keyCode = get_kbd_key(ev);
keyCode = keyb->keyCode = ev ? get_kbd_key(ev) : 0;
js_newobject(J);
{
@ -79,10 +81,12 @@ mjs_keyboardEvent_get_property_keyCode(js_State *J)
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
struct keyboard *keyb = (struct keyboard *)js_touserdata(J, 0, "event");
unicode_val_T code;
if (!keyb) {
js_pushnull(J);
return;
}
js_pushnumber(J, keyb->keyCode);
code = keyb->keyCode ?: get_kbd_key(&last_event);
js_pushnumber(J, code);
}

View File

@ -64,8 +64,6 @@ struct el_message {
struct el_window *elwin;
};
extern struct term_event last_event;
static
void mjs_window_finalizer(js_State *J, void *val)
{
@ -100,7 +98,7 @@ mjs_window_get_property_event(js_State *J)
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
mjs_push_keyboardEvent(J, &last_event);
mjs_push_keyboardEvent(J, NULL);
}
static void
@ -650,9 +648,9 @@ mjs_window_init(js_State *J)
addproperty(J, "top", mjs_window_get_property_top, NULL);
addproperty(J, "window", mjs_window_get_property_self, NULL);
}
js_defglobal(J, "window", JS_DONTENUM);
js_defglobal(J, "window", 0);
js_dostring(J, "function alert(text) { return window.alert(text); }\n"
js_dostring(J, "var event = window.event; function alert(text) { return window.alert(text); }\n"
"function clearTimeout(h) { return window.clearTimeout(h); }\n"
"function open(a, b, c) { return window.open(a, b, c); }\n"
"function setTimeout(a, b) { return window.setTimeout(a, b); }\n"

View File

@ -404,6 +404,7 @@ quickjs_eval_boolback(struct ecmascript_interpreter *interpreter,
JS_ToInt32(ctx, &ret, r);
return ret;
}

View File

@ -86,7 +86,6 @@ current_link_evhook(struct document_view *doc_view, enum script_event_hook_type
if (!link) return -1;
if (!doc_view->vs->ecmascript) return -1;
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
void *mapa = (void *)doc_view->document->element_map;
if (mapa) {
@ -97,7 +96,7 @@ current_link_evhook(struct document_view *doc_view, enum script_event_hook_type
check_element_event(doc_view->vs->ecmascript, elem, event_name, NULL);
}
}
#endif
if (!link->event_hooks) return -1;
foreach (evhook, *link->event_hooks) {