Skip to content

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

Merged
lannka merged 1 commit intoampproject:masterfrom
tlong2:amp-auto-ads-margins
Jan 26, 2017
Merged

Adding margin support to placement.js for <amp-auto-ads>#7153
lannka merged 1 commit intoampproject:masterfrom
tlong2:amp-auto-ads-margins

Conversation

@tlong2
Copy link
Copy Markdown
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
Copy Markdown
Contributor

/to @lannka

margins = {top: marginTop};
}
if (marginBottom) {
(margins = margins || {}).bottom = marginBottom;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

* @param {!Window} win
* @param {!Element} anchorElement
* @param {!function(!Element, !Element)} injector
* @param {!../../../src/layout-rect.LayoutMarginsChangeDef|undefined} margins
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

* @param {!../../../src/layout-rect.LayoutMarginsChangeDef|undefined} margins
*/
constructor(win, anchorElement, injector) {
constructor(win, anchorElement, injector, margins) {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

3 participants