Skip to content
Permalink
Browse files

Implement DOMTokenList.toggle

  • Loading branch information
brunoabinader committed Dec 26, 2014
1 parent 2cfb464 commit 5afcf3ef652b71e340363d52cbd28db7c1dc70a4
Showing with 27 additions and 1 deletion.
  1. +25 −0 components/script/dom/domtokenlist.rs
  2. +2 −1 components/script/dom/webidls/DOMTokenList.webidl
@@ -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)
}
}
}
}
}
@@ -14,7 +14,8 @@ interface DOMTokenList {
void add(DOMString... tokens);
[Throws]
void remove(DOMString... tokens);
[Throws]
boolean toggle(DOMString token, optional boolean force);

//boolean toggle(DOMString token, optional boolean force);
//stringifier;
};

0 comments on commit 5afcf3e

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