Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for css class selection #499

Merged
merged 4 commits into from Jun 12, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -86,6 +86,36 @@ impl SelectHandler<AbstractNode<LayoutView>> for NodeSelectHandler {
}
}

fn with_node_classes<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element() |element_n| {
f(element_n.get_attr("class"))
}
}

fn node_has_class(&self, node: &AbstractNode<LayoutView>, class: &str) -> bool {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element |element_n| {
match element_n.get_attr("class") {
None => false,
Some(existing_classes) => {
let mut ret = false;
for str::each_split_char(existing_classes, ' ') |s| {
if s == class {
ret = true;
break;
}
}
ret
}
}
}
}

fn with_node_id<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R {
if !node.is_element() {
fail!(~"attempting to style non-element node");
@@ -0,0 +1,20 @@
<html>
<head>
<style type="text/css">
.c1 { color: red; }
.c2 { background: blue; }
#i1 { color: green; }
</style>
<script>
document.write("ok");
</script>
</head>
<body>
<div>
<div id='i1'>Hello</div>
<div class='c1'>World</div>
<div class='c2'>Hello</div>
<div class='c1 c2'>World</div>
</div>
</body>
</html>
File renamed without changes.
File renamed without changes.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.