| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Provides a Map abstraction on top of data-* attributes, similar to the | 6 * Provides a Map abstraction on top of data-* attributes, similar to the |
| 7 * dataSet in the old DOM. | 7 * dataSet in the old DOM. |
| 8 */ | 8 */ |
| 9 class _DataAttributeMap implements Map<String, String> { | 9 class _DataAttributeMap implements AttributeMap { |
| 10 | 10 |
| 11 final Map<String, String> _attributes; | 11 final Map<String, String> _attributes; |
| 12 | 12 |
| 13 _DataAttributeMap(this._attributes); | 13 _DataAttributeMap(this._attributes); |
| 14 | 14 |
| 15 // interface Map | 15 // interface Map |
| 16 | 16 |
| 17 // TODO: Use lazy iterator when it is available on Map. | 17 // TODO: Use lazy iterator when it is available on Map. |
| 18 bool containsValue(String value) => getValues().some((v) => v == value); | 18 bool containsValue(String value) => getValues().some((v) => v == value); |
| 19 | 19 |
| 20 bool containsKey(String key) => _attributes.containsKey(_attr(key)); | 20 bool containsKey(String key) => _attributes.containsKey(_attr(key)); |
| 21 | 21 |
| 22 String operator [](String key) => _attributes[_attr(key)]; | 22 String operator [](String key) => _attributes[_attr(key)]; |
| 23 | 23 |
| 24 void operator []=(String key, String value) { | 24 void operator []=(String key, value) { |
| 25 _attributes[_attr(key)] = value; | 25 _attributes[_attr(key)] = '$value'; |
| 26 } | 26 } |
| 27 | 27 |
| 28 String putIfAbsent(String key, String ifAbsent()) { | 28 String putIfAbsent(String key, String ifAbsent()) { |
| 29 if (!containsKey(key)) { | 29 if (!containsKey(key)) { |
| 30 return this[key] = ifAbsent(); | 30 return this[key] = ifAbsent(); |
| 31 } | 31 } |
| 32 return this[key]; | 32 return this[key]; |
| 33 } | 33 } |
| 34 | 34 |
| 35 String remove(String key) => _attributes.remove(_attr(key)); | 35 String remove(String key) => _attributes.remove(_attr(key)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 // TODO: Use lazy iterator when it is available on Map. | 74 // TODO: Use lazy iterator when it is available on Map. |
| 75 bool isEmpty() => length == 0; | 75 bool isEmpty() => length == 0; |
| 76 | 76 |
| 77 // Helpers. | 77 // Helpers. |
| 78 String _attr(String key) => 'data-$key'; | 78 String _attr(String key) => 'data-$key'; |
| 79 bool _matches(String key) => key.startsWith('data-'); | 79 bool _matches(String key) => key.startsWith('data-'); |
| 80 String _strip(String key) => key.substring(5); | 80 String _strip(String key) => key.substring(5); |
| 81 } | 81 } |
| 82 | 82 |
| OLD | NEW |