OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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. */ | |
8 abstract class CssClassSet implements Set<String> { | |
9 | |
10 /** | |
11 * Adds the class [value] to the element if it is not on it, removes it if it | |
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. | |
16 */ | |
17 bool toggle(String value, [bool shouldAdd]); | |
18 | |
19 /** | |
20 * Returns [:true:] if classes cannot be added or removed from this | |
21 * [:CssClassSet:]. | |
22 */ | |
23 bool get frozen; | |
24 | |
25 /** | |
26 * Determine if this element contains the class [value]. | |
27 * | |
28 * This is the Dart equivalent of jQuery's | |
29 * [hasClass](http://api.jquery.com/hasClass/). | |
30 */ | |
31 bool contains(String value); | |
32 | |
33 /** | |
34 * Add the class [value] to element. | |
35 * | |
36 * This is the Dart equivalent of jQuery's | |
37 * [addClass](http://api.jquery.com/addClass/). | |
38 * | |
39 * If this corresponds to one element. Returns true if [value] was added to | |
40 * the set, otherwise false. | |
41 * | |
42 * If this corresponds to many elements, null is always returned. | |
43 */ | |
44 bool add(String value); | |
45 | |
46 /** | |
47 * Remove the class [value] from element, and return true on successful | |
48 * removal. | |
49 * | |
50 * This is the Dart equivalent of jQuery's | |
51 * [removeClass](http://api.jquery.com/removeClass/). | |
52 */ | |
53 bool remove(Object value); | |
54 | |
55 /** | |
56 * Add all classes specified in [iterable] to element. | |
57 * | |
58 * This is the Dart equivalent of jQuery's | |
59 * [addClass](http://api.jquery.com/addClass/). | |
60 */ | |
61 void addAll(Iterable<String> iterable); | |
62 | |
63 /** | |
64 * Remove all classes specified in [iterable] from element. | |
65 * | |
66 * This is the Dart equivalent of jQuery's | |
67 * [removeClass](http://api.jquery.com/removeClass/). | |
68 */ | |
69 void removeAll(Iterable<String> iterable); | |
70 | |
71 /** | |
72 * Toggles all classes specified in [iterable] on element. | |
73 * | |
74 * Iterate through [iterable]'s items, and add it if it is not on it, or | |
75 * remove it if it is. This is the Dart equivalent of jQuery's | |
76 * [toggleClass](http://api.jquery.com/toggleClass/). | |
77 * If [shouldAdd] is true, then we always add all the classes in [iterable] | |
78 * element. If [shouldAdd] is false then we always remove all the classes in | |
79 * [iterable] from the element. | |
80 */ | |
81 void toggleAll(Iterable<String> iterable, [bool shouldAdd]); | |
82 } | |
83 | |
84 /** | 7 /** |
85 * A set (union) of the CSS classes that are present in a set of elements. | 8 * A set (union) of the CSS classes that are present in a set of elements. |
86 * Implemented separately from _ElementCssClassSet for performance. | 9 * Implemented separately from _ElementCssClassSet for performance. |
87 */ | 10 */ |
88 class _MultiElementCssClassSet extends CssClassSetImpl { | 11 class _MultiElementCssClassSet extends CssClassSetImpl { |
89 final Iterable<Element> _elementIterable; | 12 final Iterable<Element> _elementIterable; |
90 Iterable<_ElementCssClassSet> _elementCssClassSetIterable; | 13 Iterable<_ElementCssClassSet> _elementCssClassSetIterable; |
91 | 14 |
92 _MultiElementCssClassSet(this._elementIterable) { | 15 _MultiElementCssClassSet(this._elementIterable) { |
93 _elementCssClassSetIterable = new List.from(_elementIterable).map( | 16 _elementCssClassSetIterable = new List.from(_elementIterable).map( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 s.add(trimmed); | 80 s.add(trimmed); |
158 } | 81 } |
159 } | 82 } |
160 return s; | 83 return s; |
161 } | 84 } |
162 | 85 |
163 void writeClasses(Set<String> s) { | 86 void writeClasses(Set<String> s) { |
164 _element.className = s.join(' '); | 87 _element.className = s.join(' '); |
165 } | 88 } |
166 } | 89 } |
OLD | NEW |