Repository navigation
Add DOMNode::compareDocumentPosition() - #12146
Conversation
| . Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_PRECEDING. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_CONTAINS. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC. |
There was a problem hiding this comment.
Would it make sense to make this an enum?
There was a problem hiding this comment.
I thought about that too. The problem is that they're bitflags, so they might be OR'ed with eachother. That's something not supported with enums right now.
There was a problem hiding this comment.
Enum sets would be nice to have indeed :(
| . Added constant DOMNode::DOCUMENT_POSITION_DISCONNECTED. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_PRECEDING. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_FOLLOWING. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_CONTAINS. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY. | ||
| . Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC. |
There was a problem hiding this comment.
Enum sets would be nice to have indeed :(
|
|
||
| /* Special case: comparing children and attributes. | ||
| * They belong to a different tree and are therefore hard to compare, but spec demands attributes to precede children | ||
| * according to the pre-order DFS numbering. |
There was a problem hiding this comment.
Depth-first search. I'll write it out in full.
| --EXPECT-- | ||
| --- Compare 0 and 1 --- | ||
| int(36) | ||
| --- Compare 0 and 2 --- | ||
| int(36) | ||
| --- Compare 1 and 2 --- | ||
| int(36) | ||
| --- Compare 1 and 0 --- | ||
| int(34) | ||
| --- Compare 2 and 0 --- | ||
| int(34) | ||
| --- Compare 2 and 1 --- | ||
| int(34) |
There was a problem hiding this comment.
I'll clean it up so it's easier to understand.
| echo "--- strong & bar ---\n"; | ||
| var_dump($bar->nextElementSibling->compareDocumentPosition($bar) === DOMNode::DOCUMENT_POSITION_PRECEDING); | ||
| var_dump($bar->compareDocumentPosition($bar->nextElementSibling) === DOMNode::DOCUMENT_POSITION_FOLLOWING); |
There was a problem hiding this comment.
How would the two strong tags compare?
There was a problem hiding this comment.
I'll add a test for this.
Reference: https://dom.spec.whatwg.org/#dom-node-comparedocumentposition