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

✨ Implements variable substitution macro for html element opacity. #16479

Merged
merged 21 commits into from Aug 14, 2018

Conversation

joel-regus
Copy link
Contributor

This change creates a new variable substitution macro called "opacity" that returns a selected html element's level of transparency, the values range from 0 to 1.

This change also takes into account the element's location in the DOM tree. It is possible for an element to have its opacity set to 1 (fully visible), yet its parent can be set to 0 (fully invisible). The goal is to return the opacity value that is visible by a human. If we are unable to return an element's opacity then the default value returned is 1.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). 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 (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@joel-regus
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Jul 5, 2018
@@ -174,6 +174,27 @@ export class ViewportBindingInabox {
});
}

/** @override */
getElementOpacity(el) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To not blow the size of AMP runtime, we'd like this to be moved to amp-analytics extension.

So no change needed to resource.js, viewport-*.js.
You can probably introduce a new file opacity.js under amp-analytics/0.1/ and have all the logic there.

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 in general. Minor comments.

* @param {!Element|null} el
* @return {number} minimum opacity value
*/
export function getOpacity(el) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: pls put public functions at the top

* @param {!Element|null} el
* @return {number} minimum opacity value
*/
export function getOpacity(el) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we multiply all the opacity values together?
it min opacity is really what you want, let's rename the method.

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.

One more nit.

The next PR will be to expose this as a macro: a4a-variable-source.js



/**
* Returns the min opacity found amongst the element and its parents
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: parents -> ancestors

@joel-regus
Copy link
Contributor Author

@lannka thank you for the review! I have made the changes you requested.

@joel-regus
Copy link
Contributor Author

@lannka should we make the PR to expose this as a macro or will that be handled on your end?

@lannka
Copy link
Contributor

lannka commented Jul 27, 2018

@joel-regus thinking twice, let's not worry about that, as it's already exposed in the state object.

@joel-regus
Copy link
Contributor Author

@lannka is this ready to merge?

@nainar
Copy link
Contributor

nainar commented Aug 9, 2018

Pinging @lannka for next steps here.

@joel-regus
Copy link
Contributor Author

@lannka is there any guidance you can provide in regards to these failing unit tests? We are not sure as to how to proceed.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. 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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot
Copy link

CLAs look good, thanks!

@lannka lannka merged commit d0bf059 into ampproject:master Aug 14, 2018
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
…mpproject#16479)

* Create variable substitution macro that returns the opacity value of an element.

* fix typo

* Add Unit Tests

* Update unit tests

* rename variable to prevent linter errors

* move opacity to a new file

* removed opacity code from src

* remove dead code

* remove dead code

* Added license to opacity

* Added license to opacity test

* Moved public function to top of file

* Change getOpacity to getMinOpacity

* Change getRootOpacity to getRootMinOpacity

* Sort imports alphabetically

* change parents to ancestors in comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants