mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Add node_id and node_has_id
This commit is contained in:
parent
fa7f985d08
commit
fbd3bf0c8e
1 changed files with 23 additions and 0 deletions
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue