| 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_common; | 5 part of html_common; |
| 6 | 6 |
| 7 abstract class CssClassSetImpl implements CssClassSet { | 7 abstract class CssClassSetImpl implements CssClassSet { |
| 8 | 8 |
| 9 String toString() { | 9 String toString() { |
| 10 return readClasses().join(' '); | 10 return readClasses().join(' '); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 /** Lookup from the Set interface. Not interesting for a String set. */ | 86 /** Lookup from the Set interface. Not interesting for a String set. */ |
| 87 String lookup(String value) => contains(value) ? value : null; | 87 String lookup(String value) => contains(value) ? value : null; |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * Add the class [value] to element. | 90 * Add the class [value] to element. |
| 91 * | 91 * |
| 92 * This is the Dart equivalent of jQuery's | 92 * This is the Dart equivalent of jQuery's |
| 93 * [addClass](http://api.jquery.com/addClass/). | 93 * [addClass](http://api.jquery.com/addClass/). |
| 94 */ | 94 */ |
| 95 void add(String value) { | 95 bool add(String value) { |
| 96 // TODO - figure out if we need to do any validation here | 96 // TODO - figure out if we need to do any validation here |
| 97 // or if the browser natively does enough. | 97 // or if the browser natively does enough. |
| 98 modify((s) => s.add(value)); | 98 return modify((s) => s.add(value)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * Remove the class [value] from element, and return true on successful | 102 * Remove the class [value] from element, and return true on successful |
| 103 * removal. | 103 * removal. |
| 104 * | 104 * |
| 105 * This is the Dart equivalent of jQuery's | 105 * This is the Dart equivalent of jQuery's |
| 106 * [removeClass](http://api.jquery.com/removeClass/). | 106 * [removeClass](http://api.jquery.com/removeClass/). |
| 107 */ | 107 */ |
| 108 bool remove(Object value) { | 108 bool remove(Object value) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 /** | 200 /** |
| 201 * Helper method used to modify the set of css classes on this element. | 201 * Helper method used to modify the set of css classes on this element. |
| 202 * | 202 * |
| 203 * f - callback with: | 203 * f - callback with: |
| 204 * s - a Set of all the css class name currently on this element. | 204 * s - a Set of all the css class name currently on this element. |
| 205 * | 205 * |
| 206 * After f returns, the modified set is written to the | 206 * After f returns, the modified set is written to the |
| 207 * className property of this element. | 207 * className property of this element. |
| 208 */ | 208 */ |
| 209 void modify( f(Set<String> s)) { | 209 modify( f(Set<String> s)) { |
| 210 Set<String> s = readClasses(); | 210 Set<String> s = readClasses(); |
| 211 f(s); | 211 var ret = f(s); |
| 212 writeClasses(s); | 212 writeClasses(s); |
| 213 return ret; |
| 213 } | 214 } |
| 214 | 215 |
| 215 /** | 216 /** |
| 216 * Read the class names from the Element class property, | 217 * Read the class names from the Element class property, |
| 217 * and put them into a set (duplicates are discarded). | 218 * and put them into a set (duplicates are discarded). |
| 218 * This is intended to be overridden by specific implementations. | 219 * This is intended to be overridden by specific implementations. |
| 219 */ | 220 */ |
| 220 Set<String> readClasses(); | 221 Set<String> readClasses(); |
| 221 | 222 |
| 222 /** | 223 /** |
| 223 * Join all the elements of a set into one string and write | 224 * Join all the elements of a set into one string and write |
| 224 * back to the element. | 225 * back to the element. |
| 225 * This is intended to be overridden by specific implementations. | 226 * This is intended to be overridden by specific implementations. |
| 226 */ | 227 */ |
| 227 void writeClasses(Set<String> s); | 228 void writeClasses(Set<String> s); |
| 228 } | 229 } |
| OLD | NEW |