| OLD | NEW |
| (Empty) | |
| 1 /** |
| 2 @license |
| 3 Copyright (c) 2017 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt |
| 9 */ |
| 10 |
| 11 'use strict'; |
| 12 |
| 13 /** @type {Promise<void>} */ |
| 14 let readyPromise = null; |
| 15 |
| 16 /** @type {?function(?function())} */ |
| 17 let whenReady = window['HTMLImports'] && window['HTMLImports']['whenReady'] || n
ull; |
| 18 |
| 19 /** @type {function()} */ |
| 20 let resolveFn; |
| 21 |
| 22 /** |
| 23 * @param {?function()} callback |
| 24 */ |
| 25 export default function documentWait(callback) { |
| 26 requestAnimationFrame(function() { |
| 27 if (whenReady) { |
| 28 whenReady(callback) |
| 29 } else { |
| 30 if (!readyPromise) { |
| 31 readyPromise = new Promise((resolve) => {resolveFn = resolve}); |
| 32 if (document.readyState === 'complete') { |
| 33 resolveFn(); |
| 34 } else { |
| 35 document.addEventListener('readystatechange', () => { |
| 36 if (document.readyState === 'complete') { |
| 37 resolveFn(); |
| 38 } |
| 39 }); |
| 40 } |
| 41 } |
| 42 readyPromise.then(function(){ callback && callback(); }); |
| 43 } |
| 44 }); |
| 45 } |
| OLD | NEW |