Chromium Code Reviews| 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; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * A future that completes once all custom elements in the initial HTML page | 13 * A future that completes once all custom elements in the initial HTML page |
| 14 * have been upgraded. | 14 * have been upgraded. |
| 15 * | 15 * |
| 16 * This is needed because the native implementation can update the elements | 16 * This is needed because the native implementation can update the elements |
| 17 * while parsing the HTML document, but the custom element polyfill cannot, | 17 * while parsing the HTML document, but the custom element polyfill cannot, |
| 18 * so it completes this future once all elements are upgraded. | 18 * so it completes this future once all elements are upgraded. |
| 19 */ | 19 */ |
| 20 Future customElementsReady = () { | 20 Future customElementsReady = () { |
| 21 if (_isReady) return new Future.value(); | 21 if (_isReady) return new Future.value(); |
| 22 | 22 |
| 23 // Not upgraded. Wait for the polyfill to fire the WebComponentsReady event. | 23 // Not upgraded. Wait for the polyfill to fire the WebComponentsReady event. |
| 24 return document.body.on['WebComponentsReady'].first; | 24 // Note: we listen on document (not on document.body) to allow this polyfill |
| 25 // to be loaded in the HEAD element. | |
| 26 return document.on['WebComponentsReady'].first; | |
|
Siggi Cherem (dart-lang)
2013/10/23 00:51:33
without this some app fail to run in chrome if the
| |
| 25 }(); | 27 }(); |
| 26 | 28 |
| 27 // Return true if we are using the polyfill and upgrade is complete, or if we | 29 // Return true if we are using the polyfill and upgrade is complete, or if we |
| 28 // have native document.register and therefore the browser took care of it. | 30 // have native document.register and therefore the browser took care of it. |
| 29 // Otherwise return false, including the case where we can't find the polyfill. | 31 // Otherwise return false, including the case where we can't find the polyfill. |
| 30 bool get _isReady { | 32 bool get _isReady { |
| 31 // If we don't have dart:js, assume things are ready | 33 // If we don't have dart:js, assume things are ready |
| 32 if (js.context == null) return true; | 34 if (js.context == null) return true; |
| 33 | 35 |
| 34 var customElements = js.context['CustomElements']; | 36 var customElements = js.context['CustomElements']; |
| 35 if (customElements == null) { | 37 if (customElements == null) { |
| 36 // Return true if native document.register, otherwise false. | 38 // Return true if native document.register, otherwise false. |
| 37 // (Maybe the polyfill isn't loaded yet. Wait for it.) | 39 // (Maybe the polyfill isn't loaded yet. Wait for it.) |
| 38 return document.supportsRegister; | 40 return document.supportsRegister; |
| 39 } | 41 } |
| 40 | 42 |
| 41 return customElements['ready'] == true; | 43 return customElements['ready'] == true; |
| 42 } | 44 } |
| OLD | NEW |