mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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);
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue