OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** Dart APIs for interacting with the JavaScript Custom Elements polyfill. */ | 5 /** Dart APIs for interacting with the JavaScript Custom Elements polyfill. */ |
6 library custom_element.polyfill; | 6 library custom_element.polyfill; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 import 'dart:js' as js; | 10 import 'dart:js' as js; |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 var customElements = js.context['CustomElements']; | 36 var customElements = js.context['CustomElements']; |
37 if (customElements == null) { | 37 if (customElements == null) { |
38 // Return true if native document.register, otherwise false. | 38 // Return true if native document.register, otherwise false. |
39 // (Maybe the polyfill isn't loaded yet. Wait for it.) | 39 // (Maybe the polyfill isn't loaded yet. Wait for it.) |
40 return document.supportsRegister; | 40 return document.supportsRegister; |
41 } | 41 } |
42 | 42 |
43 return customElements['ready'] == true; | 43 return customElements['ready'] == true; |
44 } | 44 } |
| 45 |
| 46 /** |
| 47 * Loads `custom-elements.debug.js` or `custom-elements.min.js` by adding the |
| 48 * script tag to the page. Returns a future that completes when custom elements |
| 49 * are ready (equivalent to [customElementsReady]). |
| 50 * |
| 51 * Normally you should add this to your HTML file |
| 52 * (the Polymer package will do this automatically), but loading dynamically |
| 53 * can be useful for scenarios such as tests. |
| 54 */ |
| 55 Future loadCustomElementPolyfill() { |
| 56 if (!document.supportsRegister && !js.context.hasProperty('CustomElements')) { |
| 57 var script = new ScriptElement() |
| 58 ..src = '/packages/custom_element/custom-elements.debug.js'; |
| 59 document.head.append(script); |
| 60 return document.on['WebComponentsReady'].first; |
| 61 } |
| 62 return new Future.value(); |
| 63 } |
OLD | NEW |