mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Implement Element::set_custom_attribute.
This commit is contained in:
parent
63ed36cfce
commit
285a06ff59
1 changed files with 19 additions and 1 deletions
|
@ -619,6 +619,7 @@ pub trait AttributeHandlers {
|
|||
value: DOMString,
|
||||
prefix: Option<DOMString>);
|
||||
fn set_attribute(self, name: &Atom, value: AttrValue);
|
||||
fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult;
|
||||
fn do_set_attribute(self, local_name: Atom, value: AttrValue,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool);
|
||||
|
@ -688,6 +689,23 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
ns!(""), None, |attr| *attr.local_name() == *name);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/dom.html#attr-data-*
|
||||
fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||
// Step 1.
|
||||
match xml_name_type(name.as_slice()) {
|
||||
InvalidXMLName => return Err(InvalidCharacter),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Steps 2-5.
|
||||
let name = Atom::from_slice(name.as_slice());
|
||||
let value = self.parse_attribute(&ns!(""), &name, value);
|
||||
self.do_set_attribute(name.clone(), value, name.clone(), ns!(""), None, |attr| {
|
||||
*attr.name() == name && *attr.namespace() == ns!("")
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_set_attribute(self, local_name: Atom, value: AttrValue,
|
||||
name: Atom, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool) {
|
||||
|
@ -943,7 +961,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
let name = Atom::from_slice(name.as_slice());
|
||||
let value = self.parse_attribute(&ns!(""), &name, value);
|
||||
self.do_set_attribute(name.clone(), value, name.clone(), ns!(""), None, |attr| {
|
||||
attr.name().as_slice() == name.as_slice()
|
||||
*attr.name() == name
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue