Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1306)

Unified Diff: sdk/lib/html/html_common/css_class_set.dart

Issue 18583004: Added boolean to toggle. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/element_classes_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/html_common/css_class_set.dart
diff --git a/sdk/lib/html/html_common/css_class_set.dart b/sdk/lib/html/html_common/css_class_set.dart
index 18a80e71c998491195b0f1b6362b45a411583b75..dddf69f00accf9dc00569057a694bb0ed51b7c6d 100644
--- a/sdk/lib/html/html_common/css_class_set.dart
+++ b/sdk/lib/html/html_common/css_class_set.dart
@@ -13,15 +13,19 @@ abstract class CssClassSetImpl implements CssClassSet {
/**
* 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.
*/
- bool toggle(String value) {
+ bool toggle(String value, [bool shouldAdd]) {
Set<String> s = readClasses();
bool result = false;
- if (s.contains(value)) {
- s.remove(value);
- } else {
+ if (shouldAdd == null) shouldAdd = !s.contains(value);
+ if (shouldAdd) {
s.add(value);
result = true;
+ } else {
+ s.remove(value);
}
writeClasses(s);
return result;
@@ -133,9 +137,12 @@ abstract class CssClassSetImpl implements CssClassSet {
* Iterate through [iterable]'s items, and add it if it is not on it, or
* remove it if it is. This is the Dart equivalent of jQuery's
* [toggleClass](http://api.jquery.com/toggleClass/).
+ * If [shouldAdd] is true, then we always add all the classes in [iterable]
+ * element. If [shouldAdd] is false then we always remove all the classes in
+ * [iterable] from the element.
*/
- void toggleAll(Iterable<String> iterable) {
- iterable.forEach(toggle);
+ void toggleAll(Iterable<String> iterable, [bool shouldAdd]) {
+ iterable.forEach((e) => toggle(e, shouldAdd));
}
void retainAll(Iterable<String> iterable) {
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/html/element_classes_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698