Use or_else in Document.find_fragment_node.

This commit is contained in:
Ms2ger 2014-10-03 09:20:54 +02:00
parent c96018152f
commit 75ee535e3c

View file

@ -282,9 +282,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
/// Attempt to find a named element in this page's document.
/// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
fn find_fragment_node(self, fragid: DOMString) -> Option<Temporary<Element>> {
match self.GetElementById(fragid.clone()) {
Some(node) => Some(node),
None => {
self.GetElementById(fragid.clone()).or_else(|| {
let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
let elem: JSRef<Element> = ElementCast::from_ref(node);
elem.get_attribute(ns!(""), "name").root().map_or(false, |attr| {
@ -296,8 +294,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
.filter_map(|node| HTMLAnchorElementCast::to_ref(node))
.find(check_anchor)
.map(|node| Temporary::from_rooted(ElementCast::from_ref(node)))
}
}
})
}
}