@override
()
| 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 | }); |
no test coverage detected