mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use or_else in Document.find_fragment_node.
This commit is contained in:
parent
c96018152f
commit
75ee535e3c
1 changed files with 13 additions and 16 deletions
|
@ -282,9 +282,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
|
||||||
/// Attempt to find a named element in this page's document.
|
/// Attempt to find a named element in this page's document.
|
||||||
/// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
|
/// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
|
||||||
fn find_fragment_node(self, fragid: DOMString) -> Option<Temporary<Element>> {
|
fn find_fragment_node(self, fragid: DOMString) -> Option<Temporary<Element>> {
|
||||||
match self.GetElementById(fragid.clone()) {
|
self.GetElementById(fragid.clone()).or_else(|| {
|
||||||
Some(node) => Some(node),
|
|
||||||
None => {
|
|
||||||
let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
|
let check_anchor = |&node: &JSRef<HTMLAnchorElement>| {
|
||||||
let elem: JSRef<Element> = ElementCast::from_ref(node);
|
let elem: JSRef<Element> = ElementCast::from_ref(node);
|
||||||
elem.get_attribute(ns!(""), "name").root().map_or(false, |attr| {
|
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))
|
.filter_map(|node| HTMLAnchorElementCast::to_ref(node))
|
||||||
.find(check_anchor)
|
.find(check_anchor)
|
||||||
.map(|node| Temporary::from_rooted(ElementCast::from_ref(node)))
|
.map(|node| Temporary::from_rooted(ElementCast::from_ref(node)))
|
||||||
}
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue