-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
✨ Render close button for lightbox ads in inabox #16886
Changes from 4 commits
3594afb
9918244
8024065
bdfefd8
469688e
ebf8fdf
5b57fcf
b5c9c86
dda67ac
632581d
4751fc3
46042a7
548a052
1bf4b53
9d8066c
55f894a
d2efb5b
f558081
a1000c4
badafa6
c339425
d08ef8e
08617b9
c1cac8d
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 |
---|---|---|
|
@@ -22,15 +22,18 @@ import {Gestures} from '../../../src/gesture'; | |
import {KeyCodes} from '../../../src/utils/key-codes'; | ||
import {Services} from '../../../src/services'; | ||
import {SwipeXYRecognizer} from '../../../src/gesture-recognizers'; | ||
import {computedStyle, setImportantStyles} from '../../../src/style'; | ||
import {createCustomEvent} from '../../../src/event-helper'; | ||
import {computedStyle, px, setImportantStyles} from '../../../src/style'; | ||
import {createCustomEvent, listenOnce} from '../../../src/event-helper'; | ||
import {debounce} from '../../../src/utils/rate-limit'; | ||
import {dev, user} from '../../../src/log'; | ||
import {dict, hasOwn} from '../../../src/utils/object'; | ||
import {getMode} from '../../../src/mode'; | ||
import {installStylesForDoc} from '../../../src/style-installer'; | ||
import {isInFie} from '../../../src/friendly-iframe-embed'; | ||
import {cssText as lightboxAdCss} from '../../../build/lightbox-ad.css.js'; | ||
import {removeElement, tryFocus} from '../../../src/dom'; | ||
import {renderCloseButtonHeader} from '../../../src/full-overlay-frame-helper'; | ||
import {toArray} from '../../../src/types'; | ||
import {tryFocus} from '../../../src/dom'; | ||
|
||
/** @const {string} */ | ||
const TAG = 'amp-lightbox'; | ||
|
@@ -277,6 +280,7 @@ class AmpLightbox extends AMP.BaseElement { | |
}); | ||
|
||
this.handleAutofocus_(); | ||
this.maybeRenderCloseButtonHeader_(); | ||
|
||
// TODO (jridgewell): expose an API accomodating this per PR #14676 | ||
this.mutateElement(() => { | ||
|
@@ -305,6 +309,40 @@ class AmpLightbox extends AMP.BaseElement { | |
this.active_ = true; | ||
} | ||
|
||
/** @private */ | ||
maybeRenderCloseButtonHeader_() { | ||
if (!this.isInabox_()) { | ||
return; | ||
} | ||
|
||
const header = renderCloseButtonHeader(this.element); | ||
|
||
listenOnce(header, 'click', () => { | ||
removeElement(header); | ||
this.close(); | ||
}); | ||
|
||
installStylesForDoc(this.getAmpDoc(), lightboxAdCss, () => { | ||
this.element.insertBefore(header, this.container_); | ||
|
||
// Done in callback in order to apply transition. | ||
header.classList.add('amp-ad-close-header'); | ||
|
||
let headerHeight; | ||
|
||
this.measureMutateElement(() => { | ||
headerHeight = header./*OK*/getBoundingClientRect().height; | ||
}, () => { | ||
setImportantStyles(dev().assertElement(this.container_), { | ||
'margin-top': px(headerHeight), | ||
'min-height': `calc(100vh - ${px(headerHeight)})`, | ||
}); | ||
}); | ||
}, | ||
/* opt_isRuntimeCss */ false, | ||
/* opt_ext */ 'amp-lightbox'); | ||
} | ||
|
||
/** | ||
* @private | ||
* @return {!AnimationPresetDef} | ||
|
@@ -343,22 +381,27 @@ class AmpLightbox extends AMP.BaseElement { | |
*/ | ||
finalizeClose_() { | ||
const {element} = this; | ||
|
||
st.setStyles(element, this.getAnimationPresetDef_().closedStyle); | ||
|
||
const event = ++this.eventCounter_; | ||
|
||
const collapseAndReschedule = () => { | ||
// Don't collapse on transitionend if there was a previous event. | ||
// Don't collapse on transitionend if there was a subsequent event. | ||
if (event != this.eventCounter_) { | ||
return; | ||
} | ||
this./*OK*/collapse(); | ||
this.boundReschedule_(); | ||
}; | ||
|
||
element.addEventListener('transitionend', collapseAndReschedule); | ||
element.addEventListener('animationend', collapseAndReschedule); | ||
// Disable transition for inabox since the frame gets immediately collapsed. | ||
if (this.isInabox_()) { | ||
st.resetStyles(element, ['transition']); | ||
collapseAndReschedule(); | ||
} else { | ||
element.addEventListener('transitionend', collapseAndReschedule); | ||
element.addEventListener('animationend', collapseAndReschedule); | ||
} | ||
|
||
st.setStyles(element, this.getAnimationPresetDef_().closedStyle); | ||
|
||
if (this.historyId_ != -1) { | ||
this.getHistory_().pop(this.historyId_); | ||
|
@@ -371,6 +414,14 @@ class AmpLightbox extends AMP.BaseElement { | |
this.triggerEvent_(LightboxEvents.CLOSE); | ||
} | ||
|
||
/** | ||
* @return {boolean} | ||
* @private | ||
*/ | ||
isInabox_() { | ||
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. what do you think we make the close button a feature generic to amp-lightbox in both FIE or regular AMP. The feature is enabled by having element attribute "close-button". We then let the A4A validator to ensure its existence in ads. 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. This is a great idea, and decreases complexity! Done. |
||
return getMode(this.win).runtime == 'inabox'; | ||
} | ||
|
||
/** | ||
* Handles scroll on the amp-lightbox. | ||
* The scroll throttling and visibility calculation is similar to | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,29 @@ function css() { | |
return compileCss(); | ||
} | ||
|
||
const cssEntryPoints = [ | ||
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. /cc @erwinmombay |
||
{ | ||
path: 'amp.css', | ||
outJs: 'css.js', | ||
outCss: 'v0.css', | ||
}, | ||
{ | ||
path: 'lightbox-ad.css', | ||
outJs: 'lightbox-ad.css.js', | ||
outCss: 'lightbox-ad.css', | ||
}, | ||
{ | ||
path: 'video-docking.css', | ||
outJs: 'video-docking.css.js', | ||
outCss: 'video-docking.css', | ||
}, | ||
{ | ||
path: 'video-autoplay.css', | ||
outJs: 'video-autoplay.css.js', | ||
outCss: 'video-autoplay.css', | ||
}, | ||
]; | ||
|
||
/** | ||
* Compile all the css and drop in the build folder | ||
* @param {boolean} watch | ||
|
@@ -432,34 +455,37 @@ function compileCss(watch, opt_compileAll) { | |
})); | ||
} | ||
|
||
/** | ||
* @param {string} path | ||
* @param {string} outJs | ||
* @param {string} outCss | ||
*/ | ||
function writeCssEntryPoint(path, outJs, outCss) { | ||
const startTime = Date.now(); | ||
|
||
return jsifyCssAsync(`css/${path}`) | ||
.then(css => writeCss(css, path, outJs, outCss)) | ||
.then(() => { | ||
endBuildStep('Recompiled CSS in', path, startTime); | ||
}); | ||
} | ||
|
||
// Used by `gulp test --local-changes` to map CSS files to JS files. | ||
fs.writeFileSync('EXTENSIONS_CSS_MAP', JSON.stringify(extensions)); | ||
|
||
const startTime = Date.now(); | ||
return jsifyCssAsync('css/amp.css') | ||
.then(css => writeCss(css, 'amp.css', 'css.js', 'v0.css')) | ||
.then(() => { | ||
endBuildStep('Recompiled CSS in', 'amp.css', startTime); | ||
}) | ||
.then(() => jsifyCssAsync('css/video-docking.css')) | ||
.then(css => writeCss(css, | ||
'video-docking.css', 'video-docking.css.js', 'video-docking.css')) | ||
.then(() => { | ||
endBuildStep('Recompiled CSS in', 'video-docking.css', startTime); | ||
}) | ||
.then(() => jsifyCssAsync('css/video-autoplay.css')) | ||
.then(css => writeCss(css, | ||
'video-autoplay.css', 'video-autoplay.css.js', 'video-autoplay.css')) | ||
.then(() => { | ||
endBuildStep('Recompiled CSS in', 'video-autoplay.css', startTime); | ||
}) | ||
.then(() => { | ||
return buildExtensions({ | ||
bundleOnlyIfListedInFiles: false, | ||
compileOnlyCss: true, | ||
compileAll: opt_compileAll, | ||
}); | ||
}); | ||
|
||
let promise = Promise.resolve(); | ||
|
||
cssEntryPoints.forEach(entryPoint => { | ||
const {path, outJs, outCss} = entryPoint; | ||
promise = promise.then(() => writeCssEntryPoint(path, outJs, outCss)); | ||
}); | ||
|
||
return promise.then(() => buildExtensions({ | ||
bundleOnlyIfListedInFiles: false, | ||
compileOnlyCss: true, | ||
compileAll: opt_compileAll, | ||
})); | ||
} | ||
|
||
/** | ||
|
@@ -468,12 +494,15 @@ function compileCss(watch, opt_compileAll) { | |
*/ | ||
function copyCss() { | ||
const startTime = Date.now(); | ||
fs.copySync('build/css/v0.css', 'dist/v0.css'); | ||
fs.copySync('build/css/video-docking.css', 'dist/video-docking.css'); | ||
|
||
cssEntryPoints.forEach(({outCss}) => { | ||
fs.copySync(`build/css/${outCss}`, `dist/${outCss}`); | ||
}); | ||
|
||
return toPromise(gulp.src('build/css/amp-*.css') | ||
.pipe(gulp.dest('dist/v0'))) | ||
.then(() => { | ||
endBuildStep('Copied', 'build/css/v0.css to dist/v0.css', startTime); | ||
endBuildStep('Copied', 'build/css/*.css to dist/*.css', startTime); | ||
}); | ||
} | ||
|
||
|
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.
revert?
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.
Done.