mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[mujs] element.querySelectorAll
This commit is contained in:
parent
57202954bb
commit
3d92071eba
@ -2716,38 +2716,52 @@ mjs_element_querySelectorAll(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
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_getcontext(J);
|
||||||
#if 0
|
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||||
xmlpp::Element *el = static_cast<xmlpp::Element *>(mjs_getprivate(J, 0));
|
struct document *document = doc_view->document;
|
||||||
|
|
||||||
if (!el) {
|
if (!document->dom) {
|
||||||
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;
|
|
||||||
xmlpp::Node::NodeSet *res = new(std::nothrow) xmlpp::Node::NodeSet;
|
|
||||||
|
|
||||||
if (!res) {
|
|
||||||
js_pushnull(J);
|
js_pushnull(J);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
|
||||||
|
|
||||||
try {
|
if (!el) {
|
||||||
elements = el->find(xpath);
|
js_pushnull(J);
|
||||||
} catch (xmlpp::exception &e) {}
|
return;
|
||||||
|
|
||||||
for (auto node: elements)
|
|
||||||
{
|
|
||||||
if (isAncestor(el, node)) {
|
|
||||||
res->push_back(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mjs_push_collection(J, res);
|
const char *selector = js_tostring(J, 1);
|
||||||
#endif
|
|
||||||
js_pushnull(J);
|
if (!selector) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dom_string *tag_name = NULL;
|
||||||
|
dom_exception exc = dom_string_create((const uint8_t *)"B", 1, &tag_name);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !tag_name) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dom_element *element = NULL;
|
||||||
|
exc = dom_document_create_element(document->dom, tag_name, &element);
|
||||||
|
dom_string_unref(tag_name);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !element) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
walk_tree_query_append((dom_node *)element, el, selector, 0);
|
||||||
|
|
||||||
|
dom_nodelist *nodes = NULL;
|
||||||
|
exc = dom_node_get_child_nodes(element, &nodes);
|
||||||
|
dom_node_unref(element);
|
||||||
|
|
||||||
|
if (exc != DOM_NO_ERR || !nodes) {
|
||||||
|
js_pushnull(J);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mjs_push_nodelist(J, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user