forked from ampproject/worker-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for nextElementSibling and previousElementSibling (amppro…
…ject#1132) * Add support for nextElementSibling and previousElementSibling * update compat table * fix tests * also add to CharacterData * bump filesize * Flesh out one more aspect of test case. * bumped wrong filesize * babel loose mode compat: dont spread Set (ampproject#1133) * add comment node to test
- Loading branch information
Showing
7 changed files
with
131 additions
and
5 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
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,33 @@ | ||
import { NodeType } from '../../transfer/TransferrableNodes'; | ||
import { Element } from './Element'; | ||
import { Node } from './Node'; | ||
|
||
export function getPreviousElementSibling(node: Node): Element | null { | ||
let parentNodes = node.parentNode && node.parentNode.childNodes; | ||
if (!parentNodes) { | ||
return null; | ||
} | ||
|
||
for (let i = parentNodes.indexOf(node) - 1; i >= 0; i--) { | ||
let node = parentNodes[i]; | ||
if (node.nodeType === NodeType.ELEMENT_NODE) { | ||
return node as Element; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
export function getNextElementSibling(node: Node): Element | null { | ||
let parentNodes = node.parentNode && node.parentNode.childNodes; | ||
if (!parentNodes) { | ||
return null; | ||
} | ||
|
||
for (let i = parentNodes.indexOf(node) + 1; i < parentNodes.length; i++) { | ||
let node = parentNodes[i]; | ||
if (node.nodeType === NodeType.ELEMENT_NODE) { | ||
return node as Element; | ||
} | ||
} | ||
return null; | ||
} |
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