MCPcopy Index your code
hub / github.com/ampproject/amphtml / adoptServicesAndResources

Function adoptServicesAndResources

src/runtime.js:373–393  ·  view source on GitHub ↗

* Adopt shared runtimes variables between both multi-doc and single-doc pages * @param {!Window} global Global scope to adopt.

(global)

Source from the content-addressed store, hash-verified

371 * @param {!Window} global Global scope to adopt.
372 */
373function adoptServicesAndResources(global) {
374 const {documentElement} = global.document;
375
376 const ampdocService = Services.ampdocServiceFor(global);
377 const ampdoc = ampdocService.getSingleDoc();
378 global.AMP.ampdoc = ampdoc;
379
380 const viewer = Services.viewerForDoc(documentElement);
381 global.AMP.viewer = viewer;
382
383 if (getMode().development) {
384 global.AMP.toggleRuntime = viewer.toggleRuntime.bind(viewer);
385 global.AMP.resources = Services.resourcesForDoc(documentElement);
386 }
387
388 const viewport = Services.viewportForDoc(documentElement);
389 global.AMP.viewport = {};
390 global.AMP.viewport.getScrollLeft = viewport.getScrollLeft.bind(viewport);
391 global.AMP.viewport.getScrollWidth = viewport.getScrollWidth.bind(viewport);
392 global.AMP.viewport.getWidth = viewport.getWidth.bind(viewport);
393}
394
395/**
396 * Adopt MultiDocManager dependencies

Callers 2

adoptFunction · 0.85
adoptWithMultidocDepsFunction · 0.85

Calls 2

getModeFunction · 0.90
getSingleDocMethod · 0.80

Tested by

no test coverage detected