Skip to content

Commit

Permalink
Fix remove attribute (#441)
Browse files Browse the repository at this point in the history
* build: upgrade dom requirement and loosen version range

* docs: update examples

* feature: trim whitespace when there are only template children
closes #363

* maintenance: phpstorm analysis improvements

* tweak: remove data-element attribute

* tweak: remove attribute data-element

* tweak: remove elements as last step
  • Loading branch information
g105b authored Jul 20, 2023
1 parent 6829c86 commit 70581eb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/DocumentBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ public function cleanupDocument():void {
$xpathResult = $this->document->evaluate(
"//*/@*[starts-with(name(), 'data-bind')] | //*/@*[starts-with(name(), 'data-list')] | //*/@*[starts-with(name(), 'data-template')] | //*/@*[starts-with(name(), 'data-table-key')]"
);

$elementsToRemove = [];
/** @var Attr $item */
foreach($xpathResult as $item) {
if($item->ownerElement->hasAttribute("data-element")) {
$item->ownerElement->remove();
array_push($elementsToRemove, $item->ownerElement);
continue;
}

Expand All @@ -155,6 +157,10 @@ public function cleanupDocument():void {
foreach($this->document->querySelectorAll("[data-element]") as $dataElement) {
$dataElement->removeAttribute("data-element");
}

foreach($elementsToRemove as $element) {
$element->remove();
}
}

private function bind(
Expand Down

0 comments on commit 70581eb

Please sign in to comment.