| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** A Set that stores the CSS class names for an element. */ | 7 /** A Set that stores the CSS class names for an element. */ |
| 8 abstract class CssClassSet implements Set<String> { | 8 abstract class CssClassSet implements Set<String> { |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Adds the class [value] to the element if it is not on it, removes it if it | 11 * Adds the class [value] to the element if it is not on it, removes it if it |
| 12 * is. | 12 * is. |
| 13 * |
| 14 * If [shouldAdd] is true, then we always add that [value] to the element. If |
| 15 * [shouldAdd] is false then we always remove [value] from the element. |
| 13 */ | 16 */ |
| 14 bool toggle(String value); | 17 bool toggle(String value, [bool shouldAdd]); |
| 15 | 18 |
| 16 /** | 19 /** |
| 17 * Returns [:true:] if classes cannot be added or removed from this | 20 * Returns [:true:] if classes cannot be added or removed from this |
| 18 * [:CssClassSet:]. | 21 * [:CssClassSet:]. |
| 19 */ | 22 */ |
| 20 bool get frozen; | 23 bool get frozen; |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * Determine if this element contains the class [value]. | 26 * Determine if this element contains the class [value]. |
| 24 * | 27 * |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 * [removeClass](http://api.jquery.com/removeClass/). | 62 * [removeClass](http://api.jquery.com/removeClass/). |
| 60 */ | 63 */ |
| 61 void removeAll(Iterable<String> iterable); | 64 void removeAll(Iterable<String> iterable); |
| 62 | 65 |
| 63 /** | 66 /** |
| 64 * Toggles all classes specified in [iterable] on element. | 67 * Toggles all classes specified in [iterable] on element. |
| 65 * | 68 * |
| 66 * Iterate through [iterable]'s items, and add it if it is not on it, or | 69 * Iterate through [iterable]'s items, and add it if it is not on it, or |
| 67 * remove it if it is. This is the Dart equivalent of jQuery's | 70 * remove it if it is. This is the Dart equivalent of jQuery's |
| 68 * [toggleClass](http://api.jquery.com/toggleClass/). | 71 * [toggleClass](http://api.jquery.com/toggleClass/). |
| 72 * If [shouldAdd] is true, then we always add all the classes in [iterable] |
| 73 * element. If [shouldAdd] is false then we always remove all the classes in |
| 74 * [iterable] from the element. |
| 69 */ | 75 */ |
| 70 void toggleAll(Iterable<String> iterable); | 76 void toggleAll(Iterable<String> iterable, [bool shouldAdd]); |
| 71 } | 77 } |
| 72 | 78 |
| 73 /** | 79 /** |
| 74 * A set (union) of the CSS classes that are present in a set of elements. | 80 * A set (union) of the CSS classes that are present in a set of elements. |
| 75 * Implemented separately from _ElementCssClassSet for performance. | 81 * Implemented separately from _ElementCssClassSet for performance. |
| 76 */ | 82 */ |
| 77 class _MultiElementCssClassSet extends CssClassSetImpl { | 83 class _MultiElementCssClassSet extends CssClassSetImpl { |
| 78 final Iterable<Element> _elementIterable; | 84 final Iterable<Element> _elementIterable; |
| 79 Iterable<_ElementCssClassSet> _elementCssClassSetIterable; | 85 Iterable<_ElementCssClassSet> _elementCssClassSetIterable; |
| 80 | 86 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 106 * className property of this element. | 112 * className property of this element. |
| 107 */ | 113 */ |
| 108 void modify( f(Set<String> s)) { | 114 void modify( f(Set<String> s)) { |
| 109 _elementCssClassSetIterable.forEach((e) => e.modify(f)); | 115 _elementCssClassSetIterable.forEach((e) => e.modify(f)); |
| 110 } | 116 } |
| 111 | 117 |
| 112 /** | 118 /** |
| 113 * Adds the class [value] to the element if it is not on it, removes it if it | 119 * Adds the class [value] to the element if it is not on it, removes it if it |
| 114 * is. | 120 * is. |
| 115 */ | 121 */ |
| 116 bool toggle(String value) => | 122 bool toggle(String value, [bool shouldAdd]) => |
| 117 _modifyWithReturnValue((e) => e.toggle(value)); | 123 _modifyWithReturnValue((e) => e.toggle(value, shouldAdd)); |
| 118 | 124 |
| 119 /** | 125 /** |
| 120 * Remove the class [value] from element, and return true on successful | 126 * Remove the class [value] from element, and return true on successful |
| 121 * removal. | 127 * removal. |
| 122 * | 128 * |
| 123 * This is the Dart equivalent of jQuery's | 129 * This is the Dart equivalent of jQuery's |
| 124 * [removeClass](http://api.jquery.com/removeClass/). | 130 * [removeClass](http://api.jquery.com/removeClass/). |
| 125 */ | 131 */ |
| 126 bool remove(Object value) => _modifyWithReturnValue((e) => e.remove(value)); | 132 bool remove(Object value) => _modifyWithReturnValue((e) => e.remove(value)); |
| 127 | 133 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 146 } | 152 } |
| 147 } | 153 } |
| 148 return s; | 154 return s; |
| 149 } | 155 } |
| 150 | 156 |
| 151 void writeClasses(Set<String> s) { | 157 void writeClasses(Set<String> s) { |
| 152 List list = new List.from(s); | 158 List list = new List.from(s); |
| 153 _element.$dom_className = s.join(' '); | 159 _element.$dom_className = s.join(' '); |
| 154 } | 160 } |
| 155 } | 161 } |
| OLD | NEW |