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

Method attachShadowDoc

src/multidoc-manager.js:219–251  ·  view source on GitHub ↗

* Implementation for `attachShadowDoc` function. Attaches the shadow doc and * configures ampdoc for it. * @param {!Element} hostElement * @param {!Document} doc * @param {string} url * @param {!{[key: string]: string}=} opt_initParams * @return {!./runtime.ShadowDoc}

(hostElement, doc, url, opt_initParams)

Source from the content-addressed store, hash-verified

217 * @return {!./runtime.ShadowDoc}
218 */
219 attachShadowDoc(hostElement, doc, url, opt_initParams) {
220 user().assertString(url);
221 dev().fine(TAG, 'Attach shadow doc:', doc);
222 // TODO(dvoytenko, #9490): once stable, port full document case to emulated
223 // stream.
224 return this.attachShadowDoc_(
225 hostElement,
226 url,
227 opt_initParams,
228 (amp, shadowRoot, ampdoc) => {
229 // Install extensions.
230 this.mergeShadowHead_(ampdoc, shadowRoot, doc);
231
232 // Append body.
233 if (doc.body) {
234 const body = importShadowBody(shadowRoot, doc.body, /* deep */ true);
235 body.classList.add('amp-shadow');
236 ampdoc.setBody(body);
237 }
238
239 // TODO(dvoytenko): find a better and more stable way to make content
240 // visible. E.g. integrate with dynamic classes. In shadow case
241 // specifically, we have to wait for stubbing to complete, which may
242 // take awhile due to importNode.
243 setTimeout(() => {
244 ampdoc.signals().signal(CommonSignals_Enum.RENDER_START);
245 setStyle(hostElement, 'visibility', 'visible');
246 }, 50);
247
248 return Promise.resolve();
249 }
250 );
251 }
252
253 /**
254 * Implementation for `attachShadowDocAsStream` function. Attaches the shadow

Callers 6

test-runtime.jsFile · 0.80
attachFunction · 0.80
attachDocumentToPageMethod · 0.80
attachShadowDoc_Method · 0.80
showMethod · 0.80
setupMethod · 0.80

Calls 13

attachShadowDoc_Method · 0.95
mergeShadowHead_Method · 0.95
userFunction · 0.90
devFunction · 0.90
importShadowBodyFunction · 0.90
setStyleFunction · 0.90
assertStringMethod · 0.80
fineMethod · 0.80
setBodyMethod · 0.80
resolveMethod · 0.80
addMethod · 0.45
signalMethod · 0.45

Tested by

no test coverage detected