Skip to content

Implementing amp-playbuzz extension (#6106)#6351

Merged
dvoytenko merged 14 commits intoampproject:masterfrom
playbuzz:extensions/amp-playbuzz
Dec 12, 2016
Merged

Implementing amp-playbuzz extension (#6106)#6351
dvoytenko merged 14 commits intoampproject:masterfrom
playbuzz:extensions/amp-playbuzz

Conversation

@buzzdan
Copy link
Copy Markdown

@buzzdan buzzdan commented Nov 27, 2016

Hi everyone,
This is our initial implementation of extension as discussed in #6106
Any feedback would be appreciated

Thanks a lot,
Dan Mordechay
Playbuzz

@googlebot
Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@buzzdan
Copy link
Copy Markdown
Author

buzzdan commented Nov 28, 2016

I signed it!

@jridgewell
Copy link
Copy Markdown
Contributor

/to @dvoytenko, feel free to reassign.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

*/

.pb_feed_loading {
height: 320px;
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.

Please use 2sp for indent.

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.

Hmm. Not seeing the changes. Did you push the latest commit?

* limitations under the License.
*/

.pb_feed_loading {
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 confirm: are these styles meant to be customized by clients? Or are they strictly internal?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

internal. it's the loader's styles

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.

Ok. It's our convention to name internal classes with - prefix. But it's up to you.

}

.pb_top_content_container {
opacity: 1;
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.

The style above conflicts with this one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Whoops, my bad

}

.pb_feed_placeholder_container {
position: absolute;
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.

Placeholders (attribute placeholder) are automatically sized 100% of the container. Or is this for some other placeholder functionality?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

that's taking care of the internal arrangement of the placeholder + loading indicator

box-sizing: border-box;
}

.pb_ie_fixer {
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.

Please add a comment up top of what specifically is fixed in IE with this style.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

actually i tried using css animation before i noticed AMP doesnt allow it
this was a fix for that in IE but since it's no longer relevant i'll remove it

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.

AMP generally allows CSS animations and we can allow it here as well. Let's come back to it in a follow up PR.

}
}
catch (e) {
dev().log(err, e);
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.

There's no log() method. Can you please double check? Also, generally, it's easier to just use rethrowAsync.

return {};
}

dev().log(err, data);
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.

Ditto: there's no log method. Also, most of methods take tag name as the first argument. E.g. amp-playbuzz.

generateEmbedSourceUrl_() {
const params = {};
params.itemUrl = this.item_.replace('https://', '//').replace('http://', '//').split('#')[0];
params.relativeUrl = params.itemUrl.split('.playbuzz.com')[1];
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.

Please use url.js APIs for this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i was looking for something like this! nice!

`Enable ${EXPERIMENT} experiment`);

const e = this.element;
this.item_ = user().assert(
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.

What are requirements for this URL? Should it be https? Please use assertHttpsUrl in that case.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

no requirement for https, i just need it to be a valid playbuzz url.
a publisher can just copy his item url (http/https) and pase it into the amp-playbuzz src field and it should work.
that's the reason i'm dropping the scheme and use double slashes // for the beginning (to avoid cors issues)

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.

sg

const embedUrl = options.itemUrl +
'?feed=true' +
'&implementation=amp' +
'&src=' + options.itemUrl +
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.

Looks like you need encodeURIComponent here. Generally, you can just use serializeQueryString API from url.js to do this for you. There are a couple of places below with the same issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

very nice util ! thanks!

@dvoytenko
Copy link
Copy Markdown
Contributor

@buzzdan This looks great! I left a few comments. PTAL.

@buzzdan
Copy link
Copy Markdown
Author

buzzdan commented Dec 1, 2016

@dvoytenko Thanks for the detailed review!
see my fixes + replies


this.applyFillContent(iframe);
this.element.appendChild(iframe);
setStyles(this.element, {'height': '300px'});
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.

Please remove


setStyles(iframe, {
'opacity': 0,
'min-height': '300px',
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.

Please remove all height designators.

'min-height': '300px',
'height': '300px',
});
setStyles(this.element, {'height': '300px', 'min-height': '300px'});
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.

It shouldn't be getting 100%, but possible if you CSS somewhere resizes it this way. For now, let's focus on user-specified height and let it do the work. We can look if we can/need do default later. In the example above, the responsive layout will automatically resize you embed to take all available width and then will set the height proportional to the width. In that particular case, given layout=responsive width=300 height=300, the height will be equal to the width. If that's not the case, please check your CSS and if you don't see the reason - let me know and I'll check it on my end.

@dvoytenko
Copy link
Copy Markdown
Contributor

@buzzdan Ok, looks good. I think in major things, only height questions are outstanding and scrolling.

@googlebot
Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@dvoytenko
Copy link
Copy Markdown
Contributor

@buzzdan Hi! Saw a big push. Ready for re-review?

@buzzdan
Copy link
Copy Markdown
Author

buzzdan commented Dec 6, 2016

@dvoytenko so far i've dealt mostly with the height issue therefore added an overflow element (i needed to, right?), so we can review that part.

about the scroll events, they are crucial for our items as it ties in directly with the UX we are trying to provide.
by removing it we'll be providing a broken experience for our partners, which something we'd really like to avoid.
we'd be happy to present in-person the different use-cases and further discuss how we can solve this issue.

Copy link
Copy Markdown
Member

@Gregable Gregable left a comment

Choose a reason for hiding this comment

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

My review is for the validator rules only.

html_format: AMP
html_format: AMP4ADS
tag_name: "SCRIPT"
spec_name: "amp-playbuzz extension .js script"
Copy link
Copy Markdown
Member

@Gregable Gregable Dec 6, 2016

Choose a reason for hiding this comment

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

For new tags, we want to add a requirement that if the .js file is present, a corresponding tag is also present, to avoid javascript being loaded which isn't used, a performance anti-pattern. This is fairly new, so most tags don't have it, but an example would be https://github.com/ampproject/amphtml/blob/master/extensions/amp-reddit/0.1/validator-amp-reddit.protoascii

Can you add here:

also_requires_tag: "amp-playbuzz"

tag_name: "AMP-PLAYBUZZ"
also_requires_tag: "amp-playbuzz extension .js script"
attrs: {
name: "src"
Copy link
Copy Markdown
Member

@Gregable Gregable Dec 6, 2016

Choose a reason for hiding this comment

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

all optional:

Do you want any constraints on this src attribute value to help folks spot errors? Specifically, you could enforce that this is a URL (see https://github.com/ampproject/amphtml/blob/master/extensions/amp-list/0.1/validator-amp-list.protoascii for an example).

Similarly, do you want to require any of the data- attributes shown in your examples? All data- attributes are allowed by default, but this means that small typos don't typically generate errors and can be subtle to catch. You can require a set here if that is your preference.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@Gregable thanks a lot! I'll look into it

@dvoytenko
Copy link
Copy Markdown
Contributor

i've dealt mostly with the height issue therefore added an overflow element (i needed to, right?), so we can review that part.

Overflow element (at least initially) is desirable - yes. In the follow up PRs we can look into this in a bit more detail.

about the scroll events, they are crucial for our items as it ties in directly with the UX we are trying to provide.

Yes, I'd definitely like to see this. Feel free to ping me on Slack with times. In particular, I have Thur and Fri this week fairly open. My suggestion for now was to merely delay this feature for the first pull request. There are still some steps we need to take to deploy the extension and update validators, so I'm eager to get the initial merge as soon as practical; while other details can worked out next. If you really want to get scroll events on the first merge - then, yes, let's get together at the earliest convenience and take a look if we can speed their inclusion up.

import {Layout, isLayoutSizeDefined} from '../../../src/layout';
import {removeElement} from '../../../src/dom';
import {isExperimentOn} from '../../../src/experiments';
// import {setStyles} from '../../../src/style';
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.

Please remove.


/** @override */
unlayoutCallback() {
this.unlisteners_.forEach(unlisten => unlisten());
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.

Also add this.unlisteners_.length = 0;

@dvoytenko
Copy link
Copy Markdown
Contributor

@buzzdan Otherwise, it looks like we are ready pending scroll events. I added couple more comments. PTAL.


/** @override */
isLayoutSupported(layout) {
return layout === Layout.RESPONSIVE;
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.

Ping on this question. I'm pretty sure you just need isLayoutSizeDefined and it should be ok with default rules.


return this.iframePromise_ = this.loadPromise(iframe).then(() => {

this.attemptChangeHeight(this.itemHeight_).catch(() => {/* die */});
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.

There's no a lot of reason to call attemptChangeHeight here. Normally you only need to update height when your embed sends you a request to do so.

Are you just trying to make sure you have some minimal height here? (300px?) If yes - this code can actually reduce the size of your element in this case.

@dvoytenko
Copy link
Copy Markdown
Contributor

@buzzdan Just a couple more comments here, mainly on the initial height. We'll chat tomorrow about scroll events. We can touch base on the height as well. Generally (pending scroll discussion), I can already merge this code and we can clear up additional questions as a follow up.

event: 'scroll',
windowHeight: changeEvent.height,
scroll: changeEvent.top,
offsetTop: viewport.getLayoutRect(this.element).top,
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.

Please use this.getLayoutBox().top for offsetTop.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

about the layout:
from my tests responsive & fixed-height layouts work as expected and we can support it starting now.

fixed layout would just be broken since the item cant be displayed fully

for some reason fill layout floats over the rest of the elements with position:absolute
(from the docs it seems that its supposed to catch its partent height and width)

flex-item might work with some extra adjusments but for now placeholder seems to be broken with it and the item wouldnt load. i need to look deeper into it.

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.

@buzzdan

fixed layout would just be broken since the item cant be displayed fully

Can't displayed fully horizontally you mean? Because you set your own height vertically...

for some reason fill layout floats over the rest of the elements with position:absolute
(from the docs it seems that its supposed to catch its partent height and width)

It takes the height/width of its offset parent, i.e. a parent with position:relative or position:absolute.

flex-item might work with some extra adjusments but for now placeholder seems to be broken with it and the item wouldnt load. i need to look deeper into it.

Flex-item should work - it's a convenient mechanism of authors who like to use flexbox for layout.

const scrollingData = {
event: 'scroll',
windowHeight: changeEvent.height,
scroll: changeEvent.top,
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.

So, to repeat question here. The intersection observer use is mostly equivalent if this code was:

{
  scroll: scrollTop - offsetTop,
  offsetTop: 0,
}

The nuance here is that you don't know the exact top scroll position of the parent document and your position within it. But you DO know exactly which part of your embed is visible. Basically this emulates a situation where your embed is always at the very top of the page (offsetTop = 0).

Can you please comment on this? I'd like to get an idea if this is sufficient information for you or if you need more?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the detailed comment, this technology is very interesting.
let me get back to you soon as we're looking into it on our side

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey Dima, we need the scrolling events to understand where our iframe's content is relative to the top of the page, and we need this information to be up-to-date. So, understanding that sending a postMessage to the iframe on every scroll is too much, we're sending this postMessage using debounce.
Using intersection observer seems like a really cool idea, since we're getting all the data we need in the callback (and therefore don't have to query for the iframe's offset, for example), but in order to receive this event as often as we need it, we will have to provide the observer with a pretty long threshold array. In this scenario, won't it be a little inefficient?

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.

Ok. Understood. We'll look into continuous intersection observer idea. In the meantime, I'm approving an exception to use scroll events here.


/** @override */
isLayoutSupported(layout) {
return layout === Layout.RESPONSIVE;
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.

This is still outstanding. I believe you should use isLayoutSizedDefined here since you update height later anyway.

@googlebot
Copy link
Copy Markdown

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@dvoytenko
Copy link
Copy Markdown
Contributor

@buzzdan @luoruize Couple small items outstanding with layout. But I'm going to go ahead and merge in the meantime. Thanks a lot for walking me through the use cases, this has been very helpful!

@dvoytenko dvoytenko merged commit accd6eb into ampproject:master Dec 12, 2016
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* Implementing amp-playbuzz extension (ampproject#6106)

* Improved current implementation of amp-playbuzz

* Fixed height issue

* Fixed CR issues for amp-playbuzz

* Change amp-playbuzz height + homemade overflow button (ampproject#6106)

* Fixed origin issue

* Fixed Height bug + Origin Check

* Updated validation files + unlisteners array

* Fixed scrolling events before overflow bug

* Fixed placeholder strech height bug

* Fixed scroll data + layout support + slow preconnect

* Removed debouncing from OnChange to receive all events
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* Implementing amp-playbuzz extension (ampproject#6106)

* Improved current implementation of amp-playbuzz

* Fixed height issue

* Fixed CR issues for amp-playbuzz

* Change amp-playbuzz height + homemade overflow button (ampproject#6106)

* Fixed origin issue

* Fixed Height bug + Origin Check

* Updated validation files + unlisteners array

* Fixed scrolling events before overflow bug

* Fixed placeholder strech height bug

* Fixed scroll data + layout support + slow preconnect

* Removed debouncing from OnChange to receive all events
alanorozco added a commit to alanorozco/amphtml that referenced this pull request Dec 4, 2020
alanorozco added a commit to alanorozco/amphtml that referenced this pull request Dec 4, 2020
alanorozco added a commit that referenced this pull request Dec 8, 2020
- (#17012) `amp-access-iframe` (cleanup issue #13287)
- (#25480) `amp-mega-menu`
- (#25516) `amp-nested-menu`
- (#6947) `amp-playbuzz` (cleanup issue #6351)
- (#25170) `amp-sidebar-swipe-to-dismiss`
- (#21058) `fixed-elements-in-lightbox`
- (#25512) `swg-gpay-native`
- (#26021) `swg-gpay-api`
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
- (ampproject#17012) `amp-access-iframe` (cleanup issue ampproject#13287)
- (ampproject#25480) `amp-mega-menu`
- (ampproject#25516) `amp-nested-menu`
- (ampproject#6947) `amp-playbuzz` (cleanup issue ampproject#6351)
- (ampproject#25170) `amp-sidebar-swipe-to-dismiss`
- (ampproject#21058) `fixed-elements-in-lightbox`
- (ampproject#25512) `swg-gpay-native`
- (ampproject#26021) `swg-gpay-api`
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.

7 participants