-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the polyfill implementation
- Loading branch information
Showing
9 changed files
with
96 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @package s9e\SweetDOM | ||
* @copyright Copyright (c) The s9e authors | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
*/ | ||
namespace s9e\SweetDOM\NodeTraits; | ||
|
||
use DOMElement; | ||
use DOMException; | ||
use DOMNode; | ||
use const DOM_SYNTAX_ERR; | ||
use function strtolower; | ||
|
||
trait ParentNodePolyfill | ||
{ | ||
public function insertAdjacentElement(string $where, DOMElement $element): ?DOMElement | ||
{ | ||
$this->insertAdjacentNode($where, $element); | ||
|
||
return $element; | ||
} | ||
|
||
public function insertAdjacentText(string $where, string $data): void | ||
{ | ||
$node = $this->ownerDocument->createTextNode($data); | ||
$this->insertAdjacentNode($where, $node); | ||
} | ||
|
||
public function replaceChildren(...$nodes): void | ||
{ | ||
while (isset($this->lastChild)) | ||
{ | ||
$this->lastChild->remove(); | ||
} | ||
$this->append(...$nodes); | ||
} | ||
|
||
/** | ||
* Insert given node relative to this element's position | ||
* | ||
* @param string $where One of 'beforebegin', 'afterbegin', 'beforeend', 'afterend' | ||
* @param DOMNode $node | ||
* @return void | ||
*/ | ||
private function insertAdjacentNode(string $where, DOMNode $node): void | ||
{ | ||
match (strtolower($where)) | ||
{ | ||
'afterbegin' => $this->prepend($node), | ||
'afterend' => $this->after($node), | ||
'beforebegin' => $this->before($node), | ||
'beforeend' => $this->appendChild($node), | ||
default => throw new DOMException("'$where' is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'", DOM_SYNTAX_ERR) | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters