mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Implement DOMTokenList.toggle
This commit is contained in:
parent
2cfb4648ce
commit
5afcf3ef65
2 changed files with 27 additions and 1 deletions
|
@ -128,4 +128,29 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
|
||||||
element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
|
element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
|
||||||
|
fn Toggle(self, token: DOMString, force: Option<bool>) -> Fallible<bool> {
|
||||||
|
let element = self.element.root();
|
||||||
|
let mut atoms = element.get_tokenlist_attribute(&self.local_name);
|
||||||
|
let token = try!(self.check_token_exceptions(token.as_slice()));
|
||||||
|
match atoms.iter().position(|atom| *atom == token) {
|
||||||
|
Some(index) => match force {
|
||||||
|
Some(true) => Ok(true),
|
||||||
|
_ => {
|
||||||
|
atoms.remove(index);
|
||||||
|
element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => match force {
|
||||||
|
Some(false) => Ok(false),
|
||||||
|
_ => {
|
||||||
|
atoms.push(token);
|
||||||
|
element.set_atomic_tokenlist_attribute(&self.local_name, atoms);
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ interface DOMTokenList {
|
||||||
void add(DOMString... tokens);
|
void add(DOMString... tokens);
|
||||||
[Throws]
|
[Throws]
|
||||||
void remove(DOMString... tokens);
|
void remove(DOMString... tokens);
|
||||||
|
[Throws]
|
||||||
|
boolean toggle(DOMString token, optional boolean force);
|
||||||
|
|
||||||
//boolean toggle(DOMString token, optional boolean force);
|
|
||||||
//stringifier;
|
//stringifier;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue