toggle method

bool toggle (String value, [ bool shouldAdd ])

Adds the class value to the element if it is not on it, removes it if it is.

If shouldAdd is true, then we always add that value to the element. If shouldAdd is false then we always remove value from the element.

Implementation

bool toggle(String value, [bool shouldAdd]) {
  _validateToken(value);
  Set<String> s = readClasses();
  bool result = false;
  if (shouldAdd == null) shouldAdd = !s.contains(value);
  if (shouldAdd) {
    s.add(value);
    result = true;
  } else {
    s.remove(value);
  }
  writeClasses(s);
  return result;
}