* @param {!Document} doc * @param {string} cssText * @param {function()} cb
(doc, cssText, cb)
| 299 | * @param {function()} cb |
| 300 | */ |
| 301 | function installStylesLegacy(doc, cssText, cb) { |
| 302 | const style = doc.createElement('style'); |
| 303 | style.textContent = cssText; |
| 304 | doc.head.appendChild(style); |
| 305 | |
| 306 | // Styles aren't always available synchronously. E.g. if there is a |
| 307 | // pending style download, it will have to finish before the new |
| 308 | // style is visible. |
| 309 | // For this reason we poll until the style becomes available. |
| 310 | // Sync case. |
| 311 | const styleLoaded = () => { |
| 312 | const sheets = doc.styleSheets; |
| 313 | for (let i = 0; i < sheets.length; i++) { |
| 314 | const sheet = sheets[i]; |
| 315 | if (sheet.ownerNode == style) { |
| 316 | return true; |
| 317 | } |
| 318 | } |
| 319 | return false; |
| 320 | }; |
| 321 | |
| 322 | if (styleLoaded()) { |
| 323 | cb(); |
| 324 | } else { |
| 325 | const interval = setInterval(() => { |
| 326 | if (styleLoaded()) { |
| 327 | clearInterval(interval); |
| 328 | cb(); |
| 329 | } |
| 330 | }, 4); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | export function createServedIframe(src) { |
| 335 | return new Promise(function (resolve, reject) { |
no test coverage detected