1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

[mujs] document.addEventListener fixes and sample html file

This commit is contained in:
Witold Filipczyk 2024-05-29 16:37:14 +02:00
parent 4f6a439cbc
commit 5c3ab7781d
2 changed files with 34 additions and 3 deletions

View File

@ -915,7 +915,19 @@ mjs_document_addEventListener(js_State *J)
}
js_copy(J, 2);
const char *fun = js_ref(J);
struct el_listener *l;
foreach(l, doc_private->listeners) {
if (strcmp(l->typ, method)) {
continue;
}
if (l->fun == fun) {
mem_free(method);
js_pushundefined(J);
return;
}
}
struct el_listener *n = (struct el_listener *)mem_calloc(1, sizeof(*n));
if (!n) {
@ -1003,7 +1015,7 @@ mjs_document_removeEventListener(js_State *J)
if (exc != DOM_NO_ERR || !typ) {
continue;
}
dom_event_target_remove_event_listener(doc, typ, doc_private->listener, false);
//dom_event_target_remove_event_listener(doc, typ, doc_private->listener, false);
dom_string_unref(typ);
js_unref(J, l->fun);
@ -1713,9 +1725,9 @@ document_event_handler(dom_event *event, void *pw)
}
// interpreter->heartbeat = add_heartbeat(interpreter);
struct el_listener *l;
struct el_listener *l, *next;
foreach(l, doc_private->listeners) {
foreachsafe(l, next, doc_private->listeners) {
if (strcmp(l->typ, dom_string_data(typ))) {
continue;
}

View File

@ -0,0 +1,19 @@
<html>
<head>
<!--<script src="jquery.js"></script>-->
</head>
<body>
<div id="test">A</div>
<script>
function ff()
{
document.removeEventListener("DOMContentLoaded", ff);
alert('Loaded');
}
document.addEventListener("DOMContentLoaded", ff);
//$(document).ready(function(){
// alert('READY');
//});
</script>
</body>
</html>