UNPKG

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