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

Function importShadowBody

src/shadow-embed.js:160–191  ·  view source on GitHub ↗
(shadowRoot, body, deep)

Source from the content-addressed store, hash-verified

158 * @return {!Element}
159 */
160export function importShadowBody(shadowRoot, body, deep) {
161 const doc = shadowRoot.ownerDocument;
162 let resultBody;
163 if (isShadowCssSupported()) {
164 resultBody = dev().assertElement(doc.importNode(body, deep));
165 } else {
166 resultBody = doc.createElement('amp-body');
167 setInitialDisplay(resultBody, 'block');
168 for (let i = 0; i < body.attributes.length; i++) {
169 resultBody.setAttribute(
170 body.attributes[0].name,
171 body.attributes[0].value
172 );
173 }
174 if (deep) {
175 for (let n = body.firstChild; !!n; n = n.nextSibling) {
176 resultBody.appendChild(doc.importNode(n, true));
177 }
178 }
179 }
180 setStyle(resultBody, 'position', 'relative');
181 const oldBody = shadowRoot['body'];
182 if (oldBody) {
183 shadowRoot.removeChild(oldBody);
184 }
185 shadowRoot.appendChild(resultBody);
186 Object.defineProperty(shadowRoot, 'body', {
187 configurable: true,
188 value: resultBody,
189 });
190 return resultBody;
191}
192
193/**
194 * If necessary, transforms CSS to isolate AMP CSS within the shaodw root and

Callers 3

attachShadowDocMethod · 0.90

Calls 6

isShadowCssSupportedFunction · 0.90
devFunction · 0.90
setInitialDisplayFunction · 0.90
setStyleFunction · 0.90
assertElementMethod · 0.80
setAttributeMethod · 0.45

Tested by

no test coverage detected