Skip to content

♻️ Extract applyFillContent into a standalone function #34858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

__css_import__;
import {Layout} from '../../../src/core/dom/layout';
import {Layout, applyFillContent} from '#core/dom/layout';

const TAG = 'amp-__component_name_hyphenated__';

export class Amp__component_name_pascalcase__ extends AMP.BaseElement {
/** @param {!AmpElement} element */
constructor(element) {
Expand All @@ -37,7 +37,7 @@ export class Amp__component_name_pascalcase__ extends AMP.BaseElement {
this.container_ = this.element.ownerDocument.createElement('div');
this.container_.textContent = this.myText_;
this.element.appendChild(this.container_);
this.applyFillContent(this.container_, /* replacedContent */ true);
applyFillContent(this.container_, /* replacedContent */ true);
}

/** @override */
Expand Down
4 changes: 2 additions & 2 deletions builtins/amp-img/amp-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {BaseElement} from '../../src/base-element';
import {Layout, isLayoutSizeDefined} from '#core/dom/layout';
import {Layout, applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {ReadyState} from '#core/constants/ready-state';
import {Services} from '#service';
import {dev} from '../../src/log';
Expand Down Expand Up @@ -222,7 +222,7 @@ export class AmpImg extends BaseElement {
if (!IS_ESM) {
guaranteeSrcForSrcsetUnsupportedBrowsers(this.img_);
}
this.applyFillContent(this.img_, true);
applyFillContent(this.img_, true);
propagateObjectFitStyles(this.element, this.img_);

if (!serverRendered) {
Expand Down
4 changes: 2 additions & 2 deletions builtins/amp-layout/amp-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {BaseElement} from '../../src/base-element';
import {Layout, isLayoutSizeDefined} from '#core/dom/layout';
import {Layout, applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {registerElement} from '#service/custom-element-registry';

class AmpLayout extends BaseElement {
Expand All @@ -35,7 +35,7 @@ class AmpLayout extends BaseElement {
return;
}
const container = this.win.document.createElement('div');
this.applyFillContent(container);
applyFillContent(container);
this.getRealChildNodes().forEach((child) => {
container.appendChild(child);
});
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-3d-gltf/0.1/amp-3d-gltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import {ActionTrust} from '#core/constants/action-constants';
import {Deferred} from '#core/data-structures/promise';
import {Services} from '#service';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {assertHttpsUrl, resolveRelativeUrl} from '../../../src/url';
import {dev, devAssert} from '../../../src/log';
import {dict} from '#core/types/object';
import {getIframe, preloadBootstrap} from '../../../src/3p-frame';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {listenFor, postMessage} from '../../../src/iframe-helper';
import {
observeContentSize,
Expand Down Expand Up @@ -166,7 +166,7 @@ export class Amp3dGltf extends AMP.BaseElement {

const iframe = getIframe(this.win, this.element, TYPE, this.context_);
iframe.title = this.element.title || 'GLTF 3D model';
this.applyFillContent(iframe, true);
applyFillContent(iframe, true);
this.iframe_ = iframe;
this.unlistenMessage_ = devAssert(this.listenGltfViewerMessages_());

Expand Down
11 changes: 8 additions & 3 deletions extensions/amp-a4a/0.1/amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {Deferred, tryResolve} from '#core/data-structures/promise';
import {DetachedDomStream, streamResponseToWriter} from '#core/dom/stream';
import {DomTransformStream} from '../../../src/utils/dom-tranform-stream';
import {GEO_IN_GROUP} from '../../amp-geo/0.1/amp-geo-in-group';
import {Layout, LayoutPriority, isLayoutSizeDefined} from '#core/dom/layout';
import {
Layout,
LayoutPriority,
applyFillContent,
isLayoutSizeDefined,
} from '#core/dom/layout';
import {Services} from '#service';
import {SignatureVerifier, VerificationStatus} from './signature-verifier';
import {
Expand Down Expand Up @@ -1817,7 +1822,7 @@ export class AmpA4A extends AMP.BaseElement {
width
);
if (!this.uiHandler.isStickyAd()) {
this.applyFillContent(this.iframe);
applyFillContent(this.iframe);
}

let body = '';
Expand Down Expand Up @@ -1908,7 +1913,7 @@ export class AmpA4A extends AMP.BaseElement {
)
);
if (!this.uiHandler.isStickyAd()) {
this.applyFillContent(this.iframe);
applyFillContent(this.iframe);
}
const fontsArray = [];
if (creativeMetaData.customStylesheets) {
Expand Down
1 change: 0 additions & 1 deletion extensions/amp-a4a/0.1/test/test-name-frame-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describes.realWin('NameFrameRenderer', realWinConfig, (env) => {
size: {width: '320', height: '50'},
requestUrl: 'http://www.google.com',
win: env.win,
applyFillContent: () => {},
sentinel: 's-1234',
};

Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-ad/0.1/amp-ad-xorigin-iframe-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
listenForOncePromise,
postMessageToWindows,
} from '../../../src/iframe-helper';
import {applyFillContent} from '#core/dom/layout';
import {dev, devAssert} from '../../../src/log';
import {dict} from '#core/types/object';
import {getData} from '../../../src/event-helper';
Expand Down Expand Up @@ -101,7 +102,7 @@ export class AmpAdXOriginIframeHandler {
this.iframe = iframe;
this.iframe.setAttribute('scrolling', 'no');
if (!this.uiHandler_.isStickyAd()) {
this.baseInstance_.applyFillContent(this.iframe);
applyFillContent(this.iframe);
}
const timer = Services.timerFor(this.baseInstance_.win);

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-addthis/0.1/amp-addthis.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {DwellMonitor} from './addthis-utils/monitors/dwell-monitor';
import {PostMessageDispatcher} from './post-message-dispatcher';
import {ScrollMonitor} from './addthis-utils/monitors/scroll-monitor';
import {Services} from '#service';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {callEng} from './addthis-utils/eng';
import {callLojson} from './addthis-utils/lojson';
import {callPjson} from './addthis-utils/pjson';
Expand All @@ -66,7 +67,6 @@ import {
import {getOgImage} from './addthis-utils/meta';
import {getWidgetOverload} from './addthis-utils/get-widget-id-overloaded-with-json-for-anonymous-mode';
import {internalRuntimeVersion} from '../../../src/internal-version';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {listen} from '../../../src/event-helper';
import {parseUrlDeprecated} from '../../../src/url';
import {setStyle} from '#core/dom/style';
Expand Down Expand Up @@ -310,7 +310,7 @@ class AmpAddThis extends AMP.BaseElement {
);
const iframeLoadPromise = this.loadPromise(iframe);

this.applyFillContent(iframe);
applyFillContent(iframe);
this.element.appendChild(iframe);
this.iframe_ = /** @type {HTMLIFrameElement} */ (iframe);

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-anim/0.1/amp-anim.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import * as st from '#core/dom/style';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {dev} from '../../../src/log';
import {guaranteeSrcForSrcsetUnsupportedBrowsers} from '#core/dom/img';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {
observeWithSharedInOb,
unobserveWithSharedInOb,
Expand Down Expand Up @@ -56,7 +56,7 @@ export class AmpAnim extends AMP.BaseElement {
this.img_ = new Image();
this.img_.setAttribute('decoding', 'async');
this.propagateAttributes(BUILD_ATTRIBUTES, this.img_);
this.applyFillContent(this.img_, true);
applyFillContent(this.img_, true);
propagateObjectFitStyles(this.element, this.img_);

// Remove role=img otherwise this breaks screen-readers focus and
Expand Down
8 changes: 6 additions & 2 deletions extensions/amp-apester-media/0.1/amp-apester-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {CSS} from '../../../build/amp-apester-media-0.1.css';
import {IntersectionObserver3pHost} from '../../../src/utils/intersection-observer-3p-host';
import {Services} from '#service';
import {addParamsToUrl} from '../../../src/url';
import {
applyFillContent,
getLengthNumeral,
isLayoutSizeDefined,
} from '#core/dom/layout';
import {dev, userAssert} from '../../../src/log';
import {dict} from '#core/types/object';
import {
Expand All @@ -26,7 +31,6 @@ import {
setFullscreenOff,
setFullscreenOn,
} from './utils';
import {getLengthNumeral, isLayoutSizeDefined} from '#core/dom/layout';
import {handleCompanionAds} from './monetization';
import {
observeWithSharedInOb,
Expand Down Expand Up @@ -245,7 +249,7 @@ class AmpApesterMedia extends AMP.BaseElement {
iframe.height = this.height_;
iframe.width = this.width_;
iframe.classList.add('amp-apester-iframe');
this.applyFillContent(iframe);
applyFillContent(iframe);
return iframe;
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-audio/0.1/amp-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
setMediaSession,
validateMediaMetadata,
} from '../../../src/mediasession-helper';
import {Layout, isLayoutSizeFixed} from '#core/dom/layout';
import {Layout, applyFillContent, isLayoutSizeFixed} from '#core/dom/layout';
import {assertHttpsUrl} from '../../../src/url';
import {closestAncestorElementBySelector} from '#core/dom/query';
import {dev, user} from '../../../src/log';
Expand Down Expand Up @@ -134,7 +134,7 @@ export class AmpAudio extends AMP.BaseElement {
audio
);

this.applyFillContent(audio);
applyFillContent(audio);
this.getRealChildNodes().forEach((child) => {
if (child.getAttribute && child.getAttribute('src')) {
assertHttpsUrl(child.getAttribute('src'), dev().assertElement(child));
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-beopinion/0.1/amp-beopinion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import {Services} from '#service';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {getIframe, preloadBootstrap} from '../../../src/3p-frame';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {listenFor} from '../../../src/iframe-helper';
import {removeElement} from '#core/dom';

Expand Down Expand Up @@ -72,7 +72,7 @@ class AmpBeOpinion extends AMP.BaseElement {
layoutCallback() {
const iframe = getIframe(this.win, this.element, TYPE);
iframe.title = this.element.title || 'BeOpinion content';
this.applyFillContent(iframe);
applyFillContent(iframe);
listenFor(
iframe,
'embed-size',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import {ActionTrust} from '#core/constants/action-constants';
import {Deferred} from '#core/data-structures/promise';
import {Services} from '#service';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {assertHttpsUrl} from '../../../src/url';
import {batchFetchJsonFor} from '../../../src/batched-json';
import {clamp} from '#core/math';
import {dict} from '#core/types/object';
import {getData, listen} from '../../../src/event-helper';
import {getIframe, preloadBootstrap} from '../../../src/3p-frame';
import {isFiniteNumber, isObject} from '#core/types';
import {isLayoutSizeDefined} from '#core/dom/layout';

import {parseJson} from '#core/types/object/json';
import {removeElement} from '#core/dom';
Expand Down Expand Up @@ -146,7 +146,7 @@ export class AmpBodymovinAnimation extends AMP.BaseElement {
iframe.title = this.element.title || 'Airbnb BodyMovin animation';
return Services.vsyncFor(this.win)
.mutatePromise(() => {
this.applyFillContent(iframe);
applyFillContent(iframe);
this.unlistenMessage_ = listen(
this.win,
'message',
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-brid-player/0.1/amp-brid-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import {
isFullscreenElement,
} from '#core/dom/fullscreen';

import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {
getConsentPolicyInfo,
getConsentPolicyState,
} from '../../../src/consent';
import {getData, listen} from '../../../src/event-helper';
import {htmlFor} from '#core/dom/static-template';
import {installVideoManagerForDoc} from '#service/video-manager-impl';
import {isLayoutSizeDefined} from '#core/dom/layout';

const TAG = 'amp-brid-player';

Expand Down Expand Up @@ -248,7 +248,7 @@ class AmpBridPlayer extends AMP.BaseElement {
`;

this.propagateAttributes(['aria-label'], placeholder);
this.applyFillContent(placeholder);
applyFillContent(placeholder);

const altText = placeholder.hasAttribute('aria-label')
? 'Loading video - ' + placeholder.getAttribute('aria-label')
Expand Down
6 changes: 3 additions & 3 deletions extensions/amp-byside-content/0.1/amp-byside-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import {CSS} from '../../../build/amp-byside-content-0.1.css';
import {Services} from '#service';
import {addParamsToUrl, assertHttpsUrl} from '../../../src/url';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {createElementWithAttributes, removeElement} from '#core/dom';
import {debounce} from '#core/types/function';
import {dict} from '#core/types/object';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {listenFor} from '../../../src/iframe-helper';
import {setStyles} from '#core/dom/style';
import {user, userAssert} from '../../../src/log';
Expand Down Expand Up @@ -170,7 +170,7 @@ export class AmpBysideContent extends AMP.BaseElement {
placeholder.setAttribute('placeholder', '');
placeholder.appendChild(this.createBySideLoader_());

this.applyFillContent(placeholder);
applyFillContent(placeholder);

return placeholder;
}
Expand All @@ -197,7 +197,7 @@ export class AmpBysideContent extends AMP.BaseElement {
});

this.element.appendChild(this.getOverflowElement_());
this.applyFillContent(iframe);
applyFillContent(iframe);

return this.composeSrcUrl_()
.then((src) => {
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-connatix-player/0.1/amp-connatix-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {Deferred} from '#core/data-structures/promise';
import {PauseHelper} from '#core/dom/video/pause-helper';
import {Services} from '#service';
import {addParamsToUrl} from '../../../src/url';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {dict} from '#core/types/object';
import {
getConsentMetadata,
Expand All @@ -30,7 +31,6 @@ import {
getConsentPolicyState,
} from '../../../src/consent';
import {getData} from '../../../src/event-helper';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {
observeContentSize,
unobserveContentSize,
Expand Down Expand Up @@ -292,7 +292,7 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
iframe.src = src;

// applyFillContent so that frame covers the entire component.
this.applyFillContent(iframe, /* replacedContent */ true);
applyFillContent(iframe, /* replacedContent */ true);

// append child iframe for element
element.appendChild(iframe);
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-delight-player/0.1/amp-delight-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {Deferred} from '#core/data-structures/promise';
import {PauseHelper} from '#core/dom/video/pause-helper';
import {Services} from '#service';
import {VideoAttributes, VideoEvents} from '../../../src/video-interface';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {
createFrameFor,
objOrParseJson,
Expand All @@ -35,7 +36,6 @@ import {
import {getData, listen, listenOncePromise} from '../../../src/event-helper';
import {htmlFor} from '#core/dom/static-template';
import {installVideoManagerForDoc} from '#service/video-manager-impl';
import {isLayoutSizeDefined} from '#core/dom/layout';
import {
observeWithSharedInOb,
unobserveWithSharedInOb,
Expand Down Expand Up @@ -238,7 +238,7 @@ class AmpDelightPlayer extends AMP.BaseElement {
<img placeholder referrerpolicy="origin" loading="lazy" />
`;

this.applyFillContent(placeholder);
applyFillContent(placeholder);

const src = `${this.baseURL_}/poster/${this.contentID_}`;
placeholder.setAttribute('src', src);
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-embedly-card/0.1/amp-embedly-card-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {TAG as KEY_TAG} from './amp-embedly-key';
import {Layout} from '#core/dom/layout';
import {Layout, applyFillContent} from '#core/dom/layout';
import {Services} from '#service';
import {getIframe} from '../../../src/3p-frame';
import {listenFor} from '../../../src/iframe-helper';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class AmpEmbedlyCard extends AMP.BaseElement {
opt_is3P
);

this.applyFillContent(iframe);
applyFillContent(iframe);
this.getVsync().mutate(() => {
this.element.appendChild(iframe);
});
Expand Down
Loading