public function toggleClass($class, $switch = NULL)
{
$callback = Constraints::isCallable($class);
$this->each(function (\DOMElement $node, $index) use($class, $switch, $callback) {
if ($callback) {
$classString = $callback($node, $index, $node->getAttribute('class'));
} else {
$classString = $class;
}
if (empty($classString) && !(bool) $switch) {
if ($node->hasAttribute('class')) {
$node->removeAttribute('class');
}
} else {
$modified = $this->changeClassString($node->getAttribute('class'), $classString, $switch);
if (FALSE !== $modified) {
if (empty($modified)) {
$node->removeAttribute('class');
} else {
$node->setAttribute('class', $modified);
}
}
}
}, TRUE);
return $this;
}