Skip to content
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

Adding margin support to placement.js for <amp-auto-ads> #7153

Merged
merged 1 commit into from Jan 26, 2017
Merged

Adding margin support to placement.js for <amp-auto-ads> #7153

merged 1 commit into from Jan 26, 2017

Conversation

tlong2
Copy link
Contributor

@tlong2 tlong2 commented Jan 23, 2017

Margins are specified in the placement object within the JSON config using:

style: {
  top_m: 4,
  bot_m: 5
}

@jridgewell
Copy link
Contributor

/to @lannka

margins = {top: marginTop};
}
if (marginBottom) {
(margins = margins || {}).bottom = marginBottom;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid this, can we just default margins to { top: 0, bottom: 0 }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set the margins to anything (including 0), then it means the attemptSizeChange logic has to read the existing margins using getComputedStyle (which is expensive), to figure out what the diff is. So if we're not setting any margins it's best to just provide undefined I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or:

if (marginTop || marginBottom) {
  margins = {
    top: marginTop,
    bottom: marginBottom
  };
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lannka lannka self-assigned this Jan 25, 2017
Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor comments

@@ -82,8 +82,9 @@ export class Placement {
* @param {!Window} win
* @param {!Element} anchorElement
* @param {!function(!Element, !Element)} injector
* @param {!../../../src/layout-rect.LayoutMarginsChangeDef|undefined} margins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{../../../src/layout-rect.LayoutMarginsChangeDef=}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
constructor(win, anchorElement, injector) {
constructor(win, anchorElement, injector, margins) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we follow naming convention for opt param: opt_margins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lannka
Copy link
Contributor

lannka commented Jan 26, 2017

@tlong2 seems Github lost Travis status pingback. It doesn't allow me to merge. The easiest way I know is to push an empty commit..

@tlong2
Copy link
Contributor Author

tlong2 commented Jan 26, 2017

@lannka Have pushed an empty commit

@lannka lannka merged commit 1c6cbe1 into ampproject:master Jan 26, 2017
jridgewell pushed a commit to jridgewell/amphtml that referenced this pull request Jan 31, 2017
mrjoro pushed a commit to mrjoro/amphtml that referenced this pull request Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants