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

[mujs] element.querySelector

This commit is contained in:
Witold Filipczyk 2024-05-07 16:09:30 +02:00
parent 6f64f8e9db
commit 1b954141eb

View File

@ -28,6 +28,7 @@
#include "document/libdom/renderer2.h" #include "document/libdom/renderer2.h"
#include "document/view.h" #include "document/view.h"
#include "ecmascript/ecmascript.h" #include "ecmascript/ecmascript.h"
#include "ecmascript/ecmascript-c.h"
#include "ecmascript/mujs/mapa.h" #include "ecmascript/mujs/mapa.h"
#include "ecmascript/mujs.h" #include "ecmascript/mujs.h"
#include "ecmascript/mujs/attr.h" #include "ecmascript/mujs/attr.h"
@ -2693,36 +2694,25 @@ mjs_element_querySelector(js_State *J)
#ifdef ECMASCRIPT_DEBUG #ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__); fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif #endif
// TODO dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
#if 0
xmlpp::Element *el = static_cast<xmlpp::Element *>(mjs_getprivate(J, 0));
if (!el) { if (!el) {
js_pushboolean(J, 0);
return;
}
const char *str = js_tostring(J, 1);
xmlpp::ustring css = str;
xmlpp::ustring xpath = css2xpath(css);
xmlpp::Node::NodeSet elements;
try {
elements = el->find(xpath);
} catch (xmlpp::exception &e) {
js_pushnull(J); js_pushnull(J);
return; return;
} }
const char *selector = js_tostring(J, 1);
for (auto node: elements) if (!selector) {
{ js_pushnull(J);
if (isAncestor(el, node)) return;
{
mjs_push_element(J, node);
return;
}
} }
#endif void *ret = walk_tree_query(el, selector, 0);
js_pushnull(J);
if (!ret) {
js_pushnull(J);
return;
}
mjs_push_element(J, ret);
} }
static void static void