Skip to content

Collapse empty ads#1265

Merged
camelburrito merged 1 commit intoampproject:masterfrom
camelburrito:collapse_ad
Jan 6, 2016
Merged

Collapse empty ads#1265
camelburrito merged 1 commit intoampproject:masterfrom
camelburrito:collapse_ad

Conversation

@camelburrito
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

display: none please.

It should only do this when resizing is allowed. @dvoytenko can point you at the relevant code.

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.

  1. Yes, I don't see why we shouldn't do display:none.
  2. Malte is correct, all DOM mutations here should go via this.deferMutate(callback). It ensures that (a) the changes are done in the mutate phase and (b) they don't interfere with scrolling.
  3. toggleFallback(true) combined with display = none or height = 0 makes no sense.

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.

Let's clear up this issues. Another problem is that just setting display to none (or height to 0) directly won't be able to adjust scroll position. If that's desirable, we'd need to do a bit more work here.

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.

Made it display:none

also the noContentHandler_ method is called with defer mutate so i dont think ill have to do it here again.

this.deferMutate(this.noContentHandler_.bind(this));

@dvoytenko any tips on how to adjust scroll position?

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.

Thinking this through again. The only way to adjust scroll position is to go back to, initially, setting height to 0. Not directly, but rather via this.changeHeight API. What we need to do is schedule display:none via deferMutate right after changeHeight has completed. We currently don't have that option - so we need to add it. E.g. we need to add an optional callback to changeHeight API that will be called as soon as it has completed. So, it will look like this:

this.changeHeight(0, () => {
  this.deferMutate(() => display = 'none');
})

However, one more thing,

if (!this.placeholder_) {
    this.element.style.display = 'none';
} else {
    this.toggleFallback(true);
}

I still don't think that this is correct. Placeholder and fallback are not necessarily related. There's some confusion going on here. For instance, if there's no placeholder, but there's fallback, should we still hide the whole element?

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.

Nice co-incidence - i was just pinging you about this

we have a fallback and a placeholder implemented
the md file does not say anything about the fallback
but the fallback is the only thing that is displayed when there is no ad content

I am going to update the MD file to reflect usage for fallback

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.

@dvoytenko updated the code to have optional callbacks on change height - let me know if this is correct - ill update the tests and get this in.

@camelburrito camelburrito force-pushed the collapse_ad branch 2 times, most recently from 99fdbd1 to 565f479 Compare December 31, 2015 00:39
src/resources.js Outdated
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.

ChangeHeightRequestDef - see "Def" suffix.

@dvoytenko
Copy link
Copy Markdown
Contributor

All looks good. I left a couple of minor comments. The big thing, however, we need to confirm how we work with placeholder here. My sense is that fallback and placeholder are interoperable here and we need some basic priority mechanism for them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does the height and the display:none happen in the same instant?

Does this do nothing if resize is not allowed?

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.

Does the height and the display:none happen in the same instant?
No it does not -

Does this do nothing if resize is not allowed?
changed it to use requestChangeHeight , which only changes height if allowed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be important to do it in the same instant to reduce the number of style recalcs and layouts to 1. Setting display to none is a much cheaper op than setting height to 0, because the former doesn't require layouting the children.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ping on this.

@camelburrito camelburrito force-pushed the collapse_ad branch 2 times, most recently from bdf9405 to fd8210a Compare January 5, 2016 23:39
src/resources.js Outdated
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 - Where do i see "Def" suffix info?

@camelburrito camelburrito force-pushed the collapse_ad branch 4 times, most recently from ea23b34 to facc71b Compare January 6, 2016 01:16
@camelburrito
Copy link
Copy Markdown
Contributor Author

PTAL

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.

As Malte requested - he wanted to do it in the same mutate context. If so - let's do.

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

@dvoytenko
Copy link
Copy Markdown
Contributor

Couple more comments.

@camelburrito camelburrito force-pushed the collapse_ad branch 2 times, most recently from ca0a6a7 to b98882d Compare January 6, 2016 19:34
@dvoytenko
Copy link
Copy Markdown
Contributor

LGTM after issue with naming is resolved.

@dvoytenko dvoytenko added the LGTM label Jan 6, 2016
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a sentence:

The amp-ad tag will be collapsed (set to display: none) if the ad sends a message that the ad slot cannot be filled and AMP determines that this operation can be performed without affecting the user's scroll position.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add comment explaining what happens

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

@cramforce
Copy link
Copy Markdown
Member

LGTM

camelburrito pushed a commit that referenced this pull request Jan 6, 2016
Collapse empty ads (When possible)
@camelburrito camelburrito merged commit bdb2e5f into ampproject:master Jan 6, 2016
@camelburrito camelburrito deleted the collapse_ad branch January 6, 2016 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants