Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions WebFiori/Ui/HTMLNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Iterator;
use ReturnTypeWillChange;
use WebFiori\Collections\LinkedList;
use WebFiori\Collections\Vector;
use WebFiori\Collections\Stack;
use WebFiori\Ui\Exceptions\InvalidNodeNameException;
use WebFiori\Ui\Exceptions\TemplateNotFoundException;
Expand Down Expand Up @@ -273,7 +274,7 @@ public function __construct(string $name = 'div', array $attrs = []) {
$this->setIsVoidNode(true);
} else {
$this->setIsVoidNode(false);
$this->childrenList = new LinkedList();
$this->childrenList = new Vector();
}
}
$this->setAttributes($attrs);
Expand Down Expand Up @@ -988,7 +989,10 @@ public function getAttributeValue(string $attrName) {
*/
public function getChild(int $index) {
if (!$this->isTextNode() && !$this->isComment() && !$this->isVoidNode()) {
return $this->children()->get($index);
if ($index >= 0 && $index < $this->children()->size()) {
return $this->children()->get($index);
}
return null;
}
}
/**
Expand Down Expand Up @@ -1777,16 +1781,19 @@ public function removeAttributes() {
public function removeChild($nodeInstOrId) {
if (!$this->isVoidNode()) {
if ($nodeInstOrId instanceof HTMLNode) {
$child = $this->children()->removeElement($nodeInstOrId);
$child = $this->children()->remove($nodeInstOrId);

return $this->removeChHelper($child);
} else if (gettype($nodeInstOrId) == 'string') {
$toRemove = $this->getChildByID($nodeInstOrId);
$child = $this->children()->removeElement($toRemove);
$child = $this->children()->remove($toRemove);

return $this->removeChHelper($child);
} else if (gettype($nodeInstOrId) == 'integer') {
return $this->children()->remove($nodeInstOrId);
if ($nodeInstOrId >= 0 && $nodeInstOrId < $this->children()->size()) {
return $this->children()->removeAt($nodeInstOrId);
}
return null;
}
}
}
Expand Down Expand Up @@ -2502,7 +2509,7 @@ private function closeAsCode(array $FO) : string {
* @param LinkedList $chNodes The list of child nodes.
* @return null|HTMLNode Description
*/
private function getChildByIDHelper(string $val, ?LinkedList $chNodes) {
private function getChildByIDHelper(string $val, ?Vector $chNodes) {
$chCount = $chNodes !== null ? $chNodes->size() : 0;

for ($x = 0 ; $x < $chCount ; $x++) {
Expand Down Expand Up @@ -2536,7 +2543,7 @@ private function getChildByIDHelper(string $val, ?LinkedList $chNodes) {
* @param LinkedList $list The list to populate with results.
* @return LinkedList
*/
private function getChildrenByTagHelper(string $val,LinkedList $chList, LinkedList $list) : LinkedList {
private function getChildrenByTagHelper(string $val,Vector $chList, LinkedList $list) : LinkedList {
$chCount = $chList->size();

for ($x = 0 ; $x < $chCount ; $x++) {
Expand Down
2 changes: 1 addition & 1 deletion WebFiori/Ui/HTMLTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function removeCol(int $colIndex) : array {

if ($colIndex < $this->cols() && $this->cols() > 1) {
foreach ($this as $row) {
$colCells[] = $row->children()->remove($colIndex);
$colCells[] = $row->children()->removeAt($colIndex);
}
$this->cols--;
}
Expand Down
Loading