Chromium Code Reviews| 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 library trydart.shadow_root; | 5 library trydart.shadow_root; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'selection.dart' show | |
| 10 TrySelection; | |
| 11 | |
| 12 import 'html_to_text.dart' show | |
| 13 htmlToText; | |
| 14 | |
| 9 void setShadowRoot(Element node, text) { | 15 void setShadowRoot(Element node, text) { |
| 10 if (text is String) { | 16 if (text is String) { |
| 11 text = new Text(text); | 17 text = new Text(text); |
| 12 } | 18 } |
| 13 getShadowRoot(node) | 19 getShadowRoot(node) |
| 14 ..nodes.clear() | 20 ..nodes.clear() |
| 15 ..append(text); | 21 ..append(text); |
| 16 } | 22 } |
| 17 | 23 |
| 18 | 24 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 32 } | 38 } |
| 33 | 39 |
| 34 void removeShadowRootPolyfill(Element root) { | 40 void removeShadowRootPolyfill(Element root) { |
| 35 if (!ShadowRoot.supported) { | 41 if (!ShadowRoot.supported) { |
| 36 List<Node> polyfill = root.querySelectorAll('[try-dart-shadow-root]'); | 42 List<Node> polyfill = root.querySelectorAll('[try-dart-shadow-root]'); |
| 37 for (Element element in polyfill) { | 43 for (Element element in polyfill) { |
| 38 element.remove(); | 44 element.remove(); |
| 39 } | 45 } |
| 40 } | 46 } |
| 41 } | 47 } |
| 48 | |
| 49 String getText(Element node) { | |
| 50 if (ShadowRoot.supported) return node.text; | |
| 51 StringBuffer buffer = new StringBuffer(); | |
| 52 htmlToText(node, buffer, new TrySelection.empty(node)); | |
| 53 return '$buffer'; | |
|
ahe
2014/05/08 09:07:53
Firefox or htmlToText adds one too many newlines t
| |
| 54 } | |
| OLD | NEW |