Enable to update id attribute for Document.getElementById(). (#740)

This commit is contained in:
Tetsuharu OHZEKI 2013-11-12 23:04:05 +09:00
parent 072ff20140
commit aa72c413ed
3 changed files with 48 additions and 6 deletions

View file

@ -340,6 +340,28 @@ impl Document {
self.idmap.pop(id);
});
}
pub fn update_idmap(&mut self,
abstract_self: AbstractNode<ScriptView>,
new_id: DOMString,
old_id: Option<DOMString>) {
// remove old ids if the old ones are not same as the new one.
match old_id {
Some(ref old_id) if new_id != *old_id => {
self.idmap.remove(old_id);
}
_ => ()
}
// TODO: support the case if multiple elements which haves same id are in the same document.
self.idmap.mangle(new_id, abstract_self,
|_, new_node: AbstractNode<ScriptView>| -> AbstractNode<ScriptView> {
new_node
},
|_, old_node: &mut AbstractNode<ScriptView>, new_node: AbstractNode<ScriptView>| {
*old_node = new_node;
});
}
}
#[inline(always)]