1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

[mujs] element.click()

This commit is contained in:
Witold Filipczyk 2023-09-11 18:52:14 +02:00
parent d12919cabd
commit d7255e44d9
2 changed files with 105 additions and 51 deletions

View File

@ -1525,6 +1525,59 @@ mjs_element_appendChild(js_State *J)
js_pushnull(J);
}
static void
mjs_element_click(js_State *J)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view;
struct document *doc;
struct session *ses;
int offset, linknum;
if (!vs) {
js_pushundefined(J);
return;
}
doc_view = vs->doc_view;
if (!doc_view) {
js_pushundefined(J);
return;
}
doc = doc_view->document;
if (!el) {
js_pushundefined(J);
return;
}
offset = find_offset(doc->element_map_rev, el);
if (offset < 0) {
js_pushundefined(J);
return;
}
linknum = get_link_number_by_offset(doc, offset);
if (linknum < 0) {
js_pushundefined(J);
return;
}
ses = doc_view->session;
jump_to_link_number(ses, doc_view, linknum);
if (enter(ses, doc_view, 0) == FRAME_EVENT_REFRESH) {
refresh_view(ses, doc_view, 0);
} else {
print_screen_status(ses);
}
js_pushundefined(J);
}
static void
mjs_element_cloneNode(js_State *J)
{
@ -2287,6 +2340,7 @@ mjs_push_element(js_State *J, void *node)
js_newuserdata(J, "element", el_private, mjs_element_finalizer);
addmethod(J, "addEventListener", mjs_element_addEventListener, 3);
addmethod(J, "appendChild",mjs_element_appendChild, 1);
addmethod(J, "click", mjs_element_click, 0);
addmethod(J, "cloneNode", mjs_element_cloneNode, 1);
addmethod(J, "closest", mjs_element_closest, 1);
addmethod(J, "contains", mjs_element_contains, 1);

View File

@ -1597,6 +1597,57 @@ js_element_appendChild(JSContext *ctx, JSValueConst this_val, int argc, JSValueC
return JS_NULL;
}
static JSValue
js_element_click(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id));
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view;
struct document *doc;
struct session *ses;
int offset, linknum;
if (!vs) {
return JS_UNDEFINED;
}
doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
doc = doc_view->document;
if (!el) {
return JS_UNDEFINED;
}
offset = find_offset(doc->element_map_rev, el);
if (offset < 0) {
return JS_UNDEFINED;
}
linknum = get_link_number_by_offset(doc, offset);
if (linknum < 0) {
return JS_UNDEFINED;
}
ses = doc_view->session;
jump_to_link_number(ses, doc_view, linknum);
if (enter(ses, doc_view, 0) == FRAME_EVENT_REFRESH) {
refresh_view(ses, doc_view, 0);
} else {
print_screen_status(ses);
}
return JS_UNDEFINED;
}
static JSValue
js_element_cloneNode(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
@ -1651,57 +1702,6 @@ isAncestor(dom_node *el, dom_node *node)
return false;
}
static JSValue
js_element_click(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
REF_JS(this_val);
dom_node *el = (dom_node *)(js_getopaque(this_val, js_element_class_id));
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)JS_GetContextOpaque(ctx);
struct view_state *vs = interpreter->vs;
struct document_view *doc_view;
struct document *doc;
struct session *ses;
int offset, linknum;
if (!vs) {
return JS_UNDEFINED;
}
doc_view = vs->doc_view;
if (!doc_view) {
return JS_UNDEFINED;
}
doc = doc_view->document;
if (!el) {
return JS_UNDEFINED;
}
offset = find_offset(doc->element_map_rev, el);
if (offset < 0) {
return JS_UNDEFINED;
}
linknum = get_link_number_by_offset(doc, offset);
if (linknum < 0) {
return JS_UNDEFINED;
}
ses = doc_view->session;
jump_to_link_number(ses, doc_view, linknum);
if (enter(ses, doc_view, 0) == FRAME_EVENT_REFRESH) {
refresh_view(ses, doc_view, 0);
} else {
print_screen_status(ses);
}
return JS_UNDEFINED;
}
static JSValue
js_element_closest(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)