Skip to content

Commit

Permalink
Implement previous/nextElementSibling
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Apr 27, 2015
1 parent 57acf12 commit 84c6ca9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Dom/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* @property-read Node $firstChild
* @property-read Node $lastChild
* @property-read Node $previousSibling
* @property-read Node $previousElementSibling
* @property-read Node $nextSibling
* @property-read Node $nextElementSibling
* @property-read DOMNamedNodeMap $attributes
* @property-read Document $ownerDocument
* @property Document $document
Expand Down Expand Up @@ -136,6 +138,28 @@ public function __get($name) {
return html_entity_decode($innerHTML);
break;

case "previousElementSibling":
$sibling = $this;

while(!is_null($sibling)
&& !$sibling->domNode instanceof \DOMElement) {
$sibling = $sibling->previousSibling;
}

return $sibling;
break;

case "nextElementSibling":
$sibling = $this;

while(!is_null($sibling)
&& !$sibling->domNode instanceof \DOMElement) {
$sibling = $sibling->nextSibling;
}

return $sibling;
break;

default:
if(property_exists($this->domNode, $name)) {
$value = $this->domNode->$name;
Expand Down Expand Up @@ -508,4 +532,4 @@ public function getElementsByClassName($classNames) {
return $this->querySelectorAll($query);
}

}#
}#

0 comments on commit 84c6ca9

Please sign in to comment.