| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library trydart.shadow_root; |
| 6 |
| 7 import 'dart:html'; |
| 8 |
| 9 void setShadowRoot(Element node, text) { |
| 10 if (text is String) { |
| 11 text = new Text(text); |
| 12 } |
| 13 getShadowRoot(node) |
| 14 ..nodes.clear() |
| 15 ..append(text); |
| 16 } |
| 17 |
| 18 |
| 19 /* ShadowRoot or Element */ getShadowRoot(Element node) { |
| 20 if (ShadowRoot.supported) { |
| 21 ShadowRoot root = node.shadowRoot; |
| 22 return root != null ? root : node.createShadowRoot(); |
| 23 } else { |
| 24 Element root = node.querySelector('[try-dart-shadow-root]'); |
| 25 if (root == null) { |
| 26 root = new SpanElement() |
| 27 ..setAttribute('try-dart-shadow-root', ''); |
| 28 node.append(root); |
| 29 } |
| 30 return root; |
| 31 } |
| 32 } |
| 33 |
| 34 void removeShadowRootPolyfill(Element root) { |
| 35 if (!ShadowRoot.supported) { |
| 36 List<Node> polyfill = root.querySelectorAll('[try-dart-shadow-root]'); |
| 37 for (Element element in polyfill) { |
| 38 element.remove(); |
| 39 } |
| 40 } |
| 41 } |
| OLD | NEW |