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

Function adoptShadowMode

src/runtime.js:414–453  ·  view source on GitHub ↗
(global)

Source from the content-addressed store, hash-verified

412 * @return {!Promise}
413 */
414export function adoptShadowMode(global) {
415 return adoptShared(global, (global, extensions) => {
416 // shadow mode already adopted
417 if (global.AMP.attachShadowDoc) {
418 return Promise.resolve();
419 }
420
421 // Dependencies to the MultiDocManager
422 adoptMultiDocDeps(global);
423
424 const manager = new MultidocManager(
425 global,
426 Services.ampdocServiceFor(global),
427 extensions,
428 Services.timerFor(global)
429 );
430
431 /**
432 * Registers a shadow root document via a fully fetched document.
433 * @param {!Element} hostElement
434 * @param {!Document} doc
435 * @param {string} url
436 * @param {!{[key: string]: string}=} opt_initParams
437 * @return {!Object}
438 */
439 global.AMP.attachShadowDoc = manager.attachShadowDoc.bind(manager);
440
441 /**
442 * Registers a shadow root document via a stream.
443 * @param {!Element} hostElement
444 * @param {string} url
445 * @param {!{[key: string]: string}=} opt_initParams
446 * @return {!Object}
447 */
448 global.AMP.attachShadowDocAsStream =
449 manager.attachShadowDocAsStream.bind(manager);
450
451 return waitForBodyOpenPromise(global.document);
452 });
453}
454
455/**
456 * For a given extension, checks that its version is the same

Callers 3

test-runtime.jsFile · 0.90
amp-shadow.jsFile · 0.90
setupMethod · 0.90

Calls 4

waitForBodyOpenPromiseFunction · 0.90
adoptSharedFunction · 0.85
adoptMultiDocDepsFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected