1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-25 02:36:23 -04:00

[mujs] element.matches

This commit is contained in:
Witold Filipczyk 2024-05-07 16:36:02 +02:00
parent 1b954141eb
commit 786cbf9500
2 changed files with 11 additions and 23 deletions

View File

@ -24,6 +24,7 @@
#include "document/document.h"
#include "document/forms.h"
#include "document/libdom/corestrings.h"
#include "document/libdom/doc.h"
#include "document/libdom/mapa.h"
#include "document/libdom/renderer2.h"
#include "document/view.h"
@ -2657,35 +2658,21 @@ mjs_element_matches(js_State *J)
#ifdef ECMASCRIPT_DEBUG
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
#endif
// TODO
#if 0
xmlpp::Element *el = static_cast<xmlpp::Element *>(mjs_getprivate(J, 0));
dom_node *el = (dom_node *)(mjs_getprivate(J, 0));
if (!el) {
js_pushboolean(J, 0);
return;
}
const char *str = js_tostring(J, 1);
xmlpp::ustring css = str;
xmlpp::ustring xpath = css2xpath(css);
const char *selector = js_tostring(J, 1);
xmlpp::Node::NodeSet elements;
try {
elements = el->find(xpath);
} catch (xmlpp::exception &e) {
if (!selector) {
js_pushboolean(J, 0);
return;
}
void *res = el_match_selector(selector, el);
for (auto node: elements) {
if (node == el) {
js_pushboolean(J, 1);
return;
}
}
#endif
js_pushboolean(J, 0);
js_pushboolean(J, res);
}
static void

View File

@ -6,19 +6,20 @@
<script type="text/javascript">
console.error('element.matches');
console.error('element.matches.html');
var birds = document.getElementsByTagName('li');
var ch = false;
console.assert(birds.length === 3, '3');
for (var i = 0; i < birds.length; i++) {
if (birds[i].matches('.endangered')) {
console.assert(birds[i].innerHTML === 'Philippine eagle', birds[i].innerHTML);
if (birds.item(i).matches('.endangered')) {
console.assert(birds.item(i).innerHTML === 'Philippine eagle', birds.item(i).innerHTML);
ch = true;
}
}
console.assert(ch, 'was matched');
birds = document.querySelectorAll('li');
// birds = document.querySelectorAll('li');
ch = false;
// var counter = 0;