| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // TODO(jmesserly): everything in this file is copied straight from "dart:html". | 5 // TODO(jmesserly): everything in this file is copied straight from "dart:html". |
| 6 library html.dom.src; | 6 library html.dom.src; |
| 7 | 7 |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'package:html/dom.dart'; | 9 import 'package:html/dom.dart'; |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 * [:CssClassSet:]. | 48 * [:CssClassSet:]. |
| 49 */ | 49 */ |
| 50 bool get frozen; | 50 bool get frozen; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Determine if this element contains the class [value]. | 53 * Determine if this element contains the class [value]. |
| 54 * | 54 * |
| 55 * This is the Dart equivalent of jQuery's | 55 * This is the Dart equivalent of jQuery's |
| 56 * [hasClass](http://api.jquery.com/hasClass/). | 56 * [hasClass](http://api.jquery.com/hasClass/). |
| 57 */ | 57 */ |
| 58 bool contains(String value); | 58 bool contains(Object value); |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Add the class [value] to element. | 61 * Add the class [value] to element. |
| 62 * | 62 * |
| 63 * This is the Dart equivalent of jQuery's | 63 * This is the Dart equivalent of jQuery's |
| 64 * [addClass](http://api.jquery.com/addClass/). | 64 * [addClass](http://api.jquery.com/addClass/). |
| 65 * | 65 * |
| 66 * If this corresponds to one element. Returns true if [value] was added to | 66 * If this corresponds to one element. Returns true if [value] was added to |
| 67 * the set, otherwise false. | 67 * the set, otherwise false. |
| 68 * | 68 * |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 * [addClass](http://api.jquery.com/addClass/). | 86 * [addClass](http://api.jquery.com/addClass/). |
| 87 */ | 87 */ |
| 88 void addAll(Iterable<String> iterable); | 88 void addAll(Iterable<String> iterable); |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Remove all classes specified in [iterable] from element. | 91 * Remove all classes specified in [iterable] from element. |
| 92 * | 92 * |
| 93 * This is the Dart equivalent of jQuery's | 93 * This is the Dart equivalent of jQuery's |
| 94 * [removeClass](http://api.jquery.com/removeClass/). | 94 * [removeClass](http://api.jquery.com/removeClass/). |
| 95 */ | 95 */ |
| 96 void removeAll(Iterable<String> iterable); | 96 void removeAll(Iterable<Object> iterable); |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Toggles all classes specified in [iterable] on element. | 99 * Toggles all classes specified in [iterable] on element. |
| 100 * | 100 * |
| 101 * Iterate through [iterable]'s items, and add it if it is not on it, or | 101 * Iterate through [iterable]'s items, and add it if it is not on it, or |
| 102 * remove it if it is. This is the Dart equivalent of jQuery's | 102 * remove it if it is. This is the Dart equivalent of jQuery's |
| 103 * [toggleClass](http://api.jquery.com/toggleClass/). | 103 * [toggleClass](http://api.jquery.com/toggleClass/). |
| 104 * If [shouldAdd] is true, then we always add all the classes in [iterable] | 104 * If [shouldAdd] is true, then we always add all the classes in [iterable] |
| 105 * element. If [shouldAdd] is false then we always remove all the classes in | 105 * element. If [shouldAdd] is false then we always remove all the classes in |
| 106 * [iterable] from the element. | 106 * [iterable] from the element. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 Iterator<String> get iterator => readClasses().iterator; | 144 Iterator<String> get iterator => readClasses().iterator; |
| 145 // interface Iterable - END | 145 // interface Iterable - END |
| 146 | 146 |
| 147 // interface Collection - BEGIN | 147 // interface Collection - BEGIN |
| 148 void forEach(void f(String element)) { | 148 void forEach(void f(String element)) { |
| 149 readClasses().forEach(f); | 149 readClasses().forEach(f); |
| 150 } | 150 } |
| 151 | 151 |
| 152 String join([String separator = ""]) => readClasses().join(separator); | 152 String join([String separator = ""]) => readClasses().join(separator); |
| 153 | 153 |
| 154 Iterable map(f(String element)) => readClasses().map(f); | 154 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(String e)) => readClasses().map(f); |
| 155 | 155 |
| 156 Iterable<String> where(bool f(String element)) => readClasses().where(f); | 156 Iterable<String> where(bool f(String element)) => readClasses().where(f); |
| 157 | 157 |
| 158 Iterable expand(Iterable f(String element)) => readClasses().expand(f); | 158 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(String element)) => readClasse
s().expand(f); |
| 159 | 159 |
| 160 bool every(bool f(String element)) => readClasses().every(f); | 160 bool every(bool f(String element)) => readClasses().every(f); |
| 161 | 161 |
| 162 bool any(bool f(String element)) => readClasses().any(f); | 162 bool any(bool f(String element)) => readClasses().any(f); |
| 163 | 163 |
| 164 bool get isEmpty => readClasses().isEmpty; | 164 bool get isEmpty => readClasses().isEmpty; |
| 165 | 165 |
| 166 bool get isNotEmpty => readClasses().isNotEmpty; | 166 bool get isNotEmpty => readClasses().isNotEmpty; |
| 167 | 167 |
| 168 int get length => readClasses().length; | 168 int get length => readClasses().length; |
| 169 | 169 |
| 170 String reduce(String combine(String value, String element)) { | 170 String reduce(String combine(String value, String element)) { |
| 171 return readClasses().reduce(combine); | 171 return readClasses().reduce(combine); |
| 172 } | 172 } |
| 173 | 173 |
| 174 dynamic fold(dynamic initialValue, | 174 dynamic/*=T*/ fold/*<T>*/(var/*=T*/ initialValue, |
| 175 dynamic combine(dynamic previousValue, String element)) { | 175 dynamic/*=T*/ combine(var/*=T*/ previousValue, String element)) { |
| 176 return readClasses().fold(initialValue, combine); | 176 return readClasses().fold(initialValue, combine); |
| 177 } | 177 } |
| 178 // interface Collection - END | 178 // interface Collection - END |
| 179 | 179 |
| 180 // interface Set - BEGIN | 180 // interface Set - BEGIN |
| 181 /** | 181 /** |
| 182 * Determine if this element contains the class [value]. | 182 * Determine if this element contains the class [value]. |
| 183 * | 183 * |
| 184 * This is the Dart equivalent of jQuery's | 184 * This is the Dart equivalent of jQuery's |
| 185 * [hasClass](http://api.jquery.com/hasClass/). | 185 * [hasClass](http://api.jquery.com/hasClass/). |
| 186 */ | 186 */ |
| 187 bool contains(String value) => readClasses().contains(value); | 187 bool contains(Object value) => readClasses().contains(value); |
| 188 | 188 |
| 189 /** Lookup from the Set interface. Not interesting for a String set. */ | 189 /** Lookup from the Set interface. Not interesting for a String set. */ |
| 190 String lookup(String value) => contains(value) ? value : null; | 190 String lookup(Object value) => contains(value) ? value as String : null; |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * Add the class [value] to element. | 193 * Add the class [value] to element. |
| 194 * | 194 * |
| 195 * This is the Dart equivalent of jQuery's | 195 * This is the Dart equivalent of jQuery's |
| 196 * [addClass](http://api.jquery.com/addClass/). | 196 * [addClass](http://api.jquery.com/addClass/). |
| 197 */ | 197 */ |
| 198 bool add(String value) { | 198 bool add(String value) { |
| 199 // TODO - figure out if we need to do any validation here | 199 // TODO - figure out if we need to do any validation here |
| 200 // or if the browser natively does enough. | 200 // or if the browser natively does enough. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 226 // TODO - see comment above about validation. | 226 // TODO - see comment above about validation. |
| 227 modify((s) => s.addAll(iterable)); | 227 modify((s) => s.addAll(iterable)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 /** | 230 /** |
| 231 * Remove all classes specified in [iterable] from element. | 231 * Remove all classes specified in [iterable] from element. |
| 232 * | 232 * |
| 233 * This is the Dart equivalent of jQuery's | 233 * This is the Dart equivalent of jQuery's |
| 234 * [removeClass](http://api.jquery.com/removeClass/). | 234 * [removeClass](http://api.jquery.com/removeClass/). |
| 235 */ | 235 */ |
| 236 void removeAll(Iterable<String> iterable) { | 236 void removeAll(Iterable<Object> iterable) { |
| 237 modify((s) => s.removeAll(iterable)); | 237 modify((s) => s.removeAll(iterable)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * Toggles all classes specified in [iterable] on element. | 241 * Toggles all classes specified in [iterable] on element. |
| 242 * | 242 * |
| 243 * Iterate through [iterable]'s items, and add it if it is not on it, or | 243 * Iterate through [iterable]'s items, and add it if it is not on it, or |
| 244 * remove it if it is. This is the Dart equivalent of jQuery's | 244 * remove it if it is. This is the Dart equivalent of jQuery's |
| 245 * [toggleClass](http://api.jquery.com/toggleClass/). | 245 * [toggleClass](http://api.jquery.com/toggleClass/). |
| 246 * If [shouldAdd] is true, then we always add all the classes in [iterable] | 246 * If [shouldAdd] is true, then we always add all the classes in [iterable] |
| 247 * element. If [shouldAdd] is false then we always remove all the classes in | 247 * element. If [shouldAdd] is false then we always remove all the classes in |
| 248 * [iterable] from the element. | 248 * [iterable] from the element. |
| 249 */ | 249 */ |
| 250 void toggleAll(Iterable<String> iterable, [bool shouldAdd]) { | 250 void toggleAll(Iterable<String> iterable, [bool shouldAdd]) { |
| 251 iterable.forEach((e) => toggle(e, shouldAdd)); | 251 iterable.forEach((e) => toggle(e, shouldAdd)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void retainAll(Iterable<String> iterable) { | 254 void retainAll(Iterable<Object> iterable) { |
| 255 modify((s) => s.retainAll(iterable)); | 255 modify((s) => s.retainAll(iterable)); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void removeWhere(bool test(String name)) { | 258 void removeWhere(bool test(String name)) { |
| 259 modify((s) => s.removeWhere(test)); | 259 modify((s) => s.removeWhere(test)); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void retainWhere(bool test(String name)) { | 262 void retainWhere(bool test(String name)) { |
| 263 modify((s) => s.retainWhere(test)); | 263 modify((s) => s.retainWhere(test)); |
| 264 } | 264 } |
| 265 | 265 |
| 266 bool containsAll(Iterable<String> collection) => | 266 bool containsAll(Iterable<Object> collection) => |
| 267 readClasses().containsAll(collection); | 267 readClasses().containsAll(collection); |
| 268 | 268 |
| 269 Set<String> intersection(Set<String> other) => | 269 Set<String> intersection(Set<Object> other) => |
| 270 readClasses().intersection(other); | 270 readClasses().intersection(other); |
| 271 | 271 |
| 272 Set<String> union(Set<String> other) => readClasses().union(other); | 272 Set<String> union(Set<String> other) => readClasses().union(other); |
| 273 | 273 |
| 274 Set<String> difference(Set<String> other) => readClasses().difference(other); | 274 Set<String> difference(Set<Object> other) => readClasses().difference(other); |
| 275 | 275 |
| 276 String get first => readClasses().first; | 276 String get first => readClasses().first; |
| 277 String get last => readClasses().last; | 277 String get last => readClasses().last; |
| 278 String get single => readClasses().single; | 278 String get single => readClasses().single; |
| 279 List<String> toList({bool growable: true}) => | 279 List<String> toList({bool growable: true}) => |
| 280 readClasses().toList(growable: growable); | 280 readClasses().toList(growable: growable); |
| 281 Set<String> toSet() => readClasses().toSet(); | 281 Set<String> toSet() => readClasses().toSet(); |
| 282 Iterable<String> take(int n) => readClasses().take(n); | 282 Iterable<String> take(int n) => readClasses().take(n); |
| 283 Iterable<String> takeWhile(bool test(String value)) => | 283 Iterable<String> takeWhile(bool test(String value)) => |
| 284 readClasses().takeWhile(test); | 284 readClasses().takeWhile(test); |
| 285 Iterable<String> skip(int n) => readClasses().skip(n); | 285 Iterable<String> skip(int n) => readClasses().skip(n); |
| 286 Iterable<String> skipWhile(bool test(String value)) => | 286 Iterable<String> skipWhile(bool test(String value)) => |
| 287 readClasses().skipWhile(test); | 287 readClasses().skipWhile(test); |
| 288 dynamic firstWhere(bool test(String value), {Object orElse()}) => | 288 String firstWhere(bool test(String value), {String orElse()}) => |
| 289 readClasses().firstWhere(test, orElse: orElse); | 289 readClasses().firstWhere(test, orElse: orElse); |
| 290 dynamic lastWhere(bool test(String value), {Object orElse()}) => | 290 String lastWhere(bool test(String value), {String orElse()}) => |
| 291 readClasses().lastWhere(test, orElse: orElse); | 291 readClasses().lastWhere(test, orElse: orElse); |
| 292 String singleWhere(bool test(String value)) => | 292 String singleWhere(bool test(String value)) => |
| 293 readClasses().singleWhere(test); | 293 readClasses().singleWhere(test); |
| 294 String elementAt(int index) => readClasses().elementAt(index); | 294 String elementAt(int index) => readClasses().elementAt(index); |
| 295 | 295 |
| 296 void clear() { | 296 void clear() { |
| 297 modify((s) => s.clear()); | 297 modify((s) => s.clear()); |
| 298 } | 298 } |
| 299 // interface Set - END | 299 // interface Set - END |
| 300 | 300 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 321 */ | 321 */ |
| 322 Set<String> readClasses(); | 322 Set<String> readClasses(); |
| 323 | 323 |
| 324 /** | 324 /** |
| 325 * Join all the elements of a set into one string and write | 325 * Join all the elements of a set into one string and write |
| 326 * back to the element. | 326 * back to the element. |
| 327 * This is intended to be overridden by specific implementations. | 327 * This is intended to be overridden by specific implementations. |
| 328 */ | 328 */ |
| 329 void writeClasses(Set<String> s); | 329 void writeClasses(Set<String> s); |
| 330 } | 330 } |
| OLD | NEW |