Add node_id and node_has_id

This commit is contained in:
Patrick Walton 2012-11-16 19:02:38 -08:00
parent fa7f985d08
commit fbd3bf0c8e

View file

@ -66,4 +66,27 @@ impl NodeSelectHandler: SelectHandler<Node> {
fn node_is_root(node: &Node) -> bool {
self.parent_node(node).is_none()
}
fn node_id(node: &Node) -> Option<~str> {
do node.read |data| {
match *data.kind {
Element(ref data) => data.get_attr("id"),
_ => fail ~"attempting to style non-element node"
}
}
}
fn node_has_id(node: &Node, id: &str) -> bool {
do node.read |data| {
match *data.kind {
Element(ref data) => {
match data.get_attr("id") {
None => false,
Some(existing_id) => str::eq_slice(id, existing_id)
}
}
_ => fail ~"attempting to style non-element node"
}
}
}
}