MCPcopy
hub / github.com/ampproject/amphtml / installStylesForDoc

Function installStylesForDoc

src/style-installer.js:36–71  ·  view source on GitHub ↗
(
  ampdoc,
  cssText,
  cb,
  opt_isRuntimeCss,
  opt_ext
)

Source from the content-addressed store, hash-verified

34 * @return {!Element}
35 */
36export function installStylesForDoc(
37 ampdoc,
38 cssText,
39 cb,
40 opt_isRuntimeCss,
41 opt_ext
42) {
43 const cssRoot = ampdoc.getHeadNode();
44 const style = insertStyleElement(
45 cssRoot,
46 maybeTransform(cssRoot, cssText),
47 opt_isRuntimeCss || false,
48 opt_ext || null
49 );
50
51 if (cb) {
52 const rootNode = ampdoc.getRootNode();
53 // Styles aren't always available synchronously. E.g. if there is a
54 // pending style download, it will have to finish before the new
55 // style is visible.
56 // For this reason we poll until the style becomes available.
57 // Sync case.
58 if (styleLoaded(rootNode, style)) {
59 cb(style);
60 return style;
61 }
62 // Poll until styles are available.
63 const interval = setInterval(() => {
64 if (styleLoaded(rootNode, style)) {
65 clearInterval(interval);
66 cb(style);
67 }
68 }, 4);
69 }
70 return style;
71}
72
73/**
74 * Creates the properly configured style element.

Callers 15

attachShadowDoc_Method · 0.90
mergeShadowHead_Method · 0.90
amp.jsFile · 0.90
installElement_Method · 0.90
amp-inabox.jsFile · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90

Calls 8

insertStyleElementFunction · 0.85
maybeTransformFunction · 0.85
styleLoadedFunction · 0.70
cbFunction · 0.50
setIntervalFunction · 0.50
clearIntervalFunction · 0.50
getHeadNodeMethod · 0.45
getRootNodeMethod · 0.45

Tested by

no test coverage detected