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
amp-sticky-ad: Force background-color alpha to be 1 #5819
Changes from 3 commits
43bd0cf
7d1073f
caabd2a
3cf0c96
07261fe
638a859
e3dd99d
fe85454
8b8aab5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,12 @@ import {dev,user} from '../../../src/log'; | |
import {removeElement} from '../../../src/dom'; | ||
import {toggle} from '../../../src/style'; | ||
import {listenOnce} from '../../../src/event-helper'; | ||
import {startsWith} from '../../../src/string'; | ||
import {setStyle} from '../../../src/style'; | ||
import {isExperimentOn} from '../../../src/experiments'; | ||
|
||
/** @private @const {string} */ | ||
const TAG = 'amp-sticky-ad-v1'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name this Also maybe a more descriptive experiment name? Also cleanup issue for the experiment with a comment pointing to issue # |
||
|
||
class AmpStickyAd extends AMP.BaseElement { | ||
/** @param {!AmpElement} element */ | ||
|
@@ -169,6 +174,7 @@ class AmpStickyAd extends AMP.BaseElement { | |
// Set sticky-ad to visible and change container style | ||
this.element.setAttribute('visible', ''); | ||
this.element.classList.add('amp-sticky-ad-loaded'); | ||
this.forceOpacity_(); | ||
}); | ||
}); | ||
} | ||
|
@@ -201,6 +207,28 @@ class AmpStickyAd extends AMP.BaseElement { | |
this.viewport_.updatePaddingBottom(0); | ||
}); | ||
} | ||
|
||
/** | ||
* To check for background-color alpha and force it to be 1. | ||
* Whoever call this needs to make sure it's in a vsync. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. *calls |
||
* @private | ||
*/ | ||
forceOpacity_() { | ||
if (!isExperimentOn(this.win, TAG)) { | ||
return; | ||
} | ||
const background = this.win.getComputedStyle(this.element) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed, force opacity here with a TODO to move it to CSS There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this logic to |
||
.getPropertyValue('background-color'); | ||
if (!startsWith(background, 'rgba')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is also |
||
return; | ||
} | ||
user().warn('AMP-STICKY-AD', 'Do not allow container to be transparent'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just having grba or hsla does not mean it is transparent, we need to check if alpha value is < 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that when rgba has an alpha value equal or greater than 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I thought about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: semitransparent would probably be more accurate than transparent |
||
const backgroundColor = background.substring( | ||
background.indexOf('(') + 1, | ||
background.lastIndexOf(',')); | ||
console.log('set styles'); | ||
setStyle(this.element, 'background-color', 'rgb(' + backgroundColor + ')'); | ||
} | ||
} | ||
|
||
AMP.registerElement('amp-sticky-ad', AmpStickyAd, CSS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed remove this