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

Method layoutCallback

extensions/amp-script/0.1/amp-script.js:248–362  ·  view source on GitHub ↗

@override

()

Source from the content-addressed store, hash-verified

246
247 /** @override */
248 layoutCallback() {
249 this.layoutCompleted_ = true;
250
251 // Layouts that use sizers (responsive, fluid) require the worker-dom
252 // subtree to be wrapped in a "fill content" container. This is because
253 // these layouts do _not_ constrain the size of the amp-script element
254 // via inline styles (they use sizerElement). However, this breaks
255 // "container" layout so only do it selectively.
256 let container;
257 if (this.element.sizerElement) {
258 container = this.win.document.createElement('div');
259 applyFillContent(container, /* replacedContent */ true);
260 // Reparent all real children to the container.
261 const realChildren = realChildElements(this.element);
262 for (let i = 0; i < realChildren.length; i++) {
263 container.appendChild(realChildren[i]);
264 }
265 this.element.appendChild(container);
266 }
267
268 this.userActivation_ = new UserActivationTracker(this.element);
269
270 // The displayed name of the combined script in dev tools.
271 this.debugId_ = this.element.hasAttribute('src')
272 ? `amp-script[src="${this.element.getAttribute('src')}"].js`
273 : `amp-script[script="${this.element.getAttribute('script')}"].js`;
274
275 const authorScriptPromise = this.getAuthorScript_(this.debugId_);
276 if (!authorScriptPromise) {
277 user().error(TAG, '"src" or "script" attribute is required.');
278 return Promise.reject(cancellation());
279 }
280
281 const workerAndAuthorScripts = Promise.all([
282 this.getWorkerScript_(),
283 authorScriptPromise,
284 ]).then((results) => {
285 const workerScript = results[0];
286 const authorScript = results[1];
287
288 if (
289 !this.development_ &&
290 this.service_.sizeLimitExceeded(authorScript.length, this.sandboxed_)
291 ) {
292 user().error(
293 TAG,
294 'Maximum total script size exceeded (%s). %s is disabled. ' +
295 'See https://amp.dev/documentation/components/amp-script/#size-of-javascript-code.',
296 this.sandboxed_
297 ? MAX_TOTAL_SANDBOXED_SCRIPT_SIZE
298 : MAX_TOTAL_NONSANDBOXED_SCRIPT_SIZE,
299 this.debugId_
300 );
301 this.element.classList.add('i-amphtml-broken');
302 return [];
303 }
304 return [workerScript, authorScript];
305 });

Callers 1

test-amp-script.jsFile · 0.45

Calls 15

getAuthorScript_Method · 0.95
getWorkerScript_Method · 0.95
applyFillContentFunction · 0.90
realChildElementsFunction · 0.90
userFunction · 0.90
cancellationFunction · 0.90
getModeFunction · 0.90
devFunction · 0.90
getAttributeMethod · 0.80
sizeLimitExceededMethod · 0.80
expandLongTaskMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected