mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-26 22:09:43 +03:00
implement previousElementSibling and nextElementSibling
This commit is contained in:
parent
bec8711528
commit
99d3633e03
@ -123,7 +123,67 @@ getter lastElementChild %{
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
getter previousElementSibling %{
|
getter previousElementSibling %{
|
||||||
%}
|
dom_node *element;
|
||||||
|
dom_exception exc;
|
||||||
|
dom_node_type node_type;
|
||||||
|
dom_node *sib_node;
|
||||||
|
|
||||||
|
exc = dom_node_get_previous_sibling(private->node, &element);
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return JS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (element != NULL) {
|
||||||
|
exc = dom_node_get_node_type(element, &node_type);
|
||||||
|
if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
|
||||||
|
/* found it */
|
||||||
|
jsret = jsapi_new_HTMLElement(cx,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
(dom_element *)element,
|
||||||
|
private->htmlc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
exc = dom_node_get_previous_sibling(element, &sib_node);
|
||||||
|
dom_node_unref(element);
|
||||||
|
if (exc == DOM_NO_ERR) {
|
||||||
|
element = sib_node;
|
||||||
|
} else {
|
||||||
|
element = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
getter nextElementSibling %{
|
getter nextElementSibling %{
|
||||||
%}
|
dom_node *element;
|
||||||
|
dom_exception exc;
|
||||||
|
dom_node_type node_type;
|
||||||
|
dom_node *sib_node;
|
||||||
|
|
||||||
|
exc = dom_node_get_next_sibling(private->node, &element);
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return JS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (element != NULL) {
|
||||||
|
exc = dom_node_get_node_type(element, &node_type);
|
||||||
|
if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
|
||||||
|
/* found it */
|
||||||
|
jsret = jsapi_new_HTMLElement(cx,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
(dom_element *)element,
|
||||||
|
private->htmlc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
exc = dom_node_get_next_sibling(element, &sib_node);
|
||||||
|
dom_node_unref(element);
|
||||||
|
if (exc == DOM_NO_ERR) {
|
||||||
|
element = sib_node;
|
||||||
|
} else {
|
||||||
|
element = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
14
test/js/dom-element-next_prev_ElementSibling.html
Normal file
14
test/js/dom-element-next_prev_ElementSibling.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DOM previousElementSibling and nextElementSibling reference</title>
|
||||||
|
<!-- comment node should be skipped -->
|
||||||
|
<link rel="stylesheet" type="text/css" href="tst.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>DOM previousElementSibling and nextElementSibling reference</h1>
|
||||||
|
<!-- comment node should be skipped -->
|
||||||
|
<p><b>head.lastElementChild.previousElementSibling:</b> <script>document.write(document.head.lastElementChild.previousElementSibling.textContent);</script></p>
|
||||||
|
<!-- comment node should be skipped -->
|
||||||
|
<p><b>body.firstElementChild.nextElementSibling:</b> <script>document.write(document.body.firstElementChild.nextElementSibling.textContent);</script></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -26,6 +26,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><a href="dom-element-firstElementChild.html">firstElementChild</a></li>
|
<li><a href="dom-element-firstElementChild.html">firstElementChild</a></li>
|
||||||
<li><a href="dom-element-lastElementChild.html">lastElementChild</a></li>
|
<li><a href="dom-element-lastElementChild.html">lastElementChild</a></li>
|
||||||
|
<li><a href="dom-element-next_prev_ElementSibling.html">previousElementSibling nextElementSibling</a></li>
|
||||||
<li><a href="doc-dom2.html">getElementById</a></li>
|
<li><a href="doc-dom2.html">getElementById</a></li>
|
||||||
<li><a href="dom-getElementsByTagName.html">getElementsByTagName</a></li>
|
<li><a href="dom-getElementsByTagName.html">getElementsByTagName</a></li>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user