/** * There are a few tags with CSS resource in them that are preloaded in the page * in each of those there is a "onload" handler which invokes the loadCSS callback * defined here. * We are monitoring 3 main CSS files - the runtime, the global and the page. * When each load we check to see if we can append them all in a batch. If threre * is no page css (which may happen on inner pages) then we do not wait for it */ (function () { let cssLinks = {}; function loadCssLink(link) { link.onload = null; link.rel = "stylesheet"; link.type = "text/css"; } function checkCss() { const pageCssLink = document.querySelector("[id*='CssLink']"); const widgetCssLink = document.querySelector("[id*='widgetCSS']"); if (cssLinks && cssLinks.runtime && cssLinks.global && (!pageCssLink || cssLinks.page) && (!widgetCssLink || cssLinks.widget)) { const storedRuntimeCssLink = cssLinks.runtime; const storedPageCssLink = cssLinks.page; const storedGlobalCssLink = cssLinks.global; const storedWidgetCssLink = cssLinks.widget; storedGlobalCssLink.disabled = true; loadCssLink(storedGlobalCssLink); if (storedPageCssLink) { storedPageCssLink.disabled = true; loadCssLink(storedPageCssLink); } if(storedWidgetCssLink) { storedWidgetCssLink.disabled = true; loadCssLink(storedWidgetCssLink); } storedRuntimeCssLink.disabled = true; loadCssLink(storedRuntimeCssLink); requestAnimationFrame(() => { setTimeout(() => { storedRuntimeCssLink.disabled = false; storedGlobalCssLink.disabled = false; if (storedPageCssLink) { storedPageCssLink.disabled = false; } if (storedWidgetCssLink) { storedWidgetCssLink.disabled = false; } // (SUP-4179) Clear the accumulated cssLinks only when we're // sure that the document has finished loading and the document // has been parsed. if(document.readyState === 'interactive') { cssLinks = null; } }, 0); }); } } function loadCSS(link) { try { var urlParams = new URLSearchParams(window.location.search); var noCSS = !!urlParams.get("nocss"); var cssTimeout = urlParams.get("cssTimeout") || 0; if (noCSS) { return; } if (link.href && link.href.includes("d-css-runtime")) { cssLinks.runtime = link; checkCss(); } else if (link.id === "siteGlobalCss") { cssLinks.global = link; checkCss(); } else if (link.id && link.id.includes("CssLink")) { cssLinks.page = link; checkCss(); } else if (link.id && link.id.includes("widgetCSS")) { cssLinks.widget = link; checkCss(); } else { requestIdleCallback(function () { window.setTimeout(function () { loadCssLink(link); }, parseInt(cssTimeout, 10)); }); } } catch (e) { throw e } } window.loadCSS = window.loadCSS || loadCSS; })();