script: Add a function to check whether a node is before another one in DOM order.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-08-17 10:19:09 +02:00
parent 4304a1d054
commit f6bfd44ad6
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -385,6 +385,17 @@ impl Node {
}
}
/// Returns true if this node is before `other` in the same connected DOM
/// tree.
pub fn is_before(&self, other: &Node) -> bool {
let cmp = other.CompareDocumentPosition(self);
if cmp & NodeConstants::DOCUMENT_POSITION_DISCONNECTED != 0 {
return false;
}
cmp & NodeConstants::DOCUMENT_POSITION_PRECEDING != 0
}
/// Return all registered mutation observers for this node.
pub fn registered_mutation_observers(&self) -> RefMut<Vec<RegisteredObserver>> {
self.mutation_observers.borrow_mut()