webcomponents-bundle-index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. @license
  3. Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
  4. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  5. The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  6. The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
  7. Code distributed by Google as part of the polymer project is also
  8. subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
  9. */
  10. 'use strict';
  11. /*
  12. * Polyfills loaded: HTML Imports, Custom Elements, Shady DOM/Shady CSS, platform polyfills, template
  13. * Used in: webcomponents bundle to load ALL the things
  14. */
  15. import './webcomponents-sd-ce-pf-index.js';
  16. const customElements = window.customElements;
  17. let shouldFlush = false;
  18. /** @type {?function()} */
  19. let flusher = null;
  20. if (customElements['polyfillWrapFlushCallback']) {
  21. customElements['polyfillWrapFlushCallback']((flush) => {
  22. flusher = flush;
  23. if (shouldFlush) {
  24. flush();
  25. }
  26. });
  27. }
  28. function flushAndFire() {
  29. if (window.HTMLTemplateElement.bootstrap) {
  30. window.HTMLTemplateElement.bootstrap(window.document);
  31. }
  32. flusher && flusher();
  33. shouldFlush = true;
  34. window.WebComponents.ready = true;
  35. document.dispatchEvent(new CustomEvent('WebComponentsReady', { bubbles: true }));
  36. }
  37. if (document.readyState !== 'complete') {
  38. // this script may come between DCL and load, so listen for both, and cancel load listener if DCL fires
  39. window.addEventListener('load', flushAndFire)
  40. window.addEventListener('DOMContentLoaded', () => {
  41. window.removeEventListener('load', flushAndFire);
  42. flushAndFire();
  43. });
  44. } else {
  45. flushAndFire();
  46. }