mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[mujs] element.matches
This commit is contained in:
parent
1b954141eb
commit
786cbf9500
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user