mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 20:16:54 +03:00
implement lastElementChild
This commit is contained in:
parent
b1ca83ad8c
commit
bec8711528
@ -89,6 +89,37 @@ getter firstElementChild %{
|
||||
%}
|
||||
|
||||
getter lastElementChild %{
|
||||
dom_node *element;
|
||||
dom_exception exc;
|
||||
dom_node_type node_type;
|
||||
dom_node *sib_node;
|
||||
|
||||
exc = dom_node_get_last_child(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 previousElementSibling %{
|
||||
|
11
test/js/dom-element-lastElementChild.html
Normal file
11
test/js/dom-element-lastElementChild.html
Normal file
@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="tst.css">
|
||||
<title>DOM lastElementChild reference</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>DOM lastElementChild reference</h1>
|
||||
<p><b>head.lastElementChild:</b> <script>document.write(document.head.lastElementChild.textContent);</script></p>
|
||||
<p><b>body.lastElementChild:</b> <script>document.write(document.body.lastElementChild.textContent);</script></p>
|
||||
</body>
|
||||
</html>
|
@ -24,7 +24,8 @@
|
||||
<h2>DOM tests</h2>
|
||||
<h3>Reference method tests</h3>
|
||||
<ul>
|
||||
<li><a href="doc-dom1.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="doc-dom2.html">getElementById</a></li>
|
||||
<li><a href="dom-getElementsByTagName.html">getElementsByTagName</a></li>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user