Skip to content
Permalink
Browse files

Implement Element::set_custom_attribute.

  • Loading branch information
brunoabinader authored and Ms2ger committed Dec 23, 2014
1 parent 63ed36c commit 285a06ff590b194f28da09971982b7c726f55bba
Showing with 19 additions and 1 deletion.
  1. +19 −1 components/script/dom/element.rs
@@ -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(())
}

0 comments on commit 285a06f

Please sign in to comment.
You can’t perform that action at this time.