Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Micajuine Ho committed May 10, 2021
1 parent ff2d14b commit 2a03843
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 18 deletions.
9 changes: 7 additions & 2 deletions extensions/amp-lightbox-gallery/0.1/amp-lightbox-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {triggerAnalyticsEvent} from '../../../src/analytics';

/** @const */
const TAG = 'amp-lightbox-gallery';
const AMP_CAROUSEL_TAG = 'amp-carousel';
const DEFAULT_GALLERY_ID = 'amp-lightbox-gallery';
const SLIDE_ITEM_SELECTOR =
'.i-amphtml-slide-item, .i-amphtml-carousel-slotted';
Expand Down Expand Up @@ -370,17 +371,21 @@ export class AmpLightboxGallery extends AMP.BaseElement {
* @private
*/
buildCarousel_(lightboxGroupId) {
const carouselVersion = isExperimentOn(
const extensionVersion = this.getAmpDoc().getExtensionVersion(
AMP_CAROUSEL_TAG
);
const experimentVersion = isExperimentOn(
this.win,
'amp-lightbox-gallery-carousel-0-2'
)
? '0.2'
: '0.1';
const carouselVersion = extensionVersion ?? experimentVersion;

return Promise.all([
Services.extensionsFor(this.win).installExtensionForDoc(
this.getAmpDoc(),
'amp-carousel',
AMP_CAROUSEL_TAG,
carouselVersion
),
Services.extensionsFor(this.win).installExtensionForDoc(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const pageWidth = 800;
const pageHeight = 600;

describes.endtoend(
'AMP Lightbox Gallery with AMP Carousel 2.0',
{
fixture: 'amp-lightbox/amp-lightbox-with-carousel-0.2.amp.html',
initialRect: {width: pageWidth, height: pageHeight},
environments: ['single'],
},
async (env) => {
let controller;

function css(handle, name) {
return controller.getElementCssValue(handle, name);
}

function prop(el, name) {
return controller.getElementProperty(el, name);
}

beforeEach(async () => {
controller = env.controller;
});

it('should open/close lightbox', async () => {
// First open the gallery.
const firstAmpImg = await controller.findElement('amp-img');
await controller.click(firstAmpImg);

// Verify it opened.
const overlay = await controller.findElement('.i-amphtml-lbg-overlay');
const galleryButton = await controller.findElement(
'[data-action="gallery"]'
);
const closeButton = await controller.findElement('[data-action="close"]');
await expect(css(overlay, 'opacity')).to.equal('1');
await expect(css(galleryButton, 'opacity')).to.equal('1');
await expect(css(closeButton, 'opacity')).to.equal('1');

// Wait for the first slide's image to load
const firstSlideImg = await controller.findElement(
'amp-lightbox-gallery img'
);
await expect(prop(firstSlideImg, 'naturalWidth')).to.be.gt(0);
});
}
);

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const pageHeight = 600;
describes.endtoend(
'AMP Lightbox Gallery Open/Close',
{
fixture: 'amp-lightbox-gallery-launch.amp.html',
fixture: 'amp-lightbox/amp-lightbox-gallery-launch.amp.html',
initialRect: {width: pageWidth, height: pageHeight},
// TODO(sparhami) Get this working in other environments.
environments: ['single'],
Expand Down
27 changes: 12 additions & 15 deletions test/fixtures/e2e/amp-lightbox/amp-lightbox-gallery-launch.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
<script async custom-element="amp-lightbox-gallery" src="https://cdn.ampproject.org/v0/amp-lightbox-gallery-0.1.js"></script>
<!-- Optionally import the amp-carousel component in the header if you are using lightbox with carousel. -->
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>

<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
Expand Down Expand Up @@ -64,11 +61,11 @@
This is a basic example that demonstrates lightboxed `<amp-img>`s. You have one or more `<amp-img>` elements on the page. Just add the "lightbox" attribute to each image that you wish to view in a lightbox.
-->
<div class="container">
<amp-img lightbox src="./img/bluegradient.png" width="300" height="200" layout="responsive"></amp-img>
<amp-img lightbox src="../../../manual/img/bluegradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<amp-img lightbox src="./img/redgradient.png" width="300" height="200" layout="responsive"></amp-img>
<amp-img lightbox src="../../../manual/img/redgradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<amp-img lightbox src="./img/lemonyellowgradient.png" width="300" height="200" layout="responsive"></amp-img>
<amp-img lightbox src="../../../manual/img/lemonyellowgradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

Expand All @@ -78,9 +75,9 @@
-->
<div>
<amp-carousel lightbox width="400" height="300" layout="responsive" type="slides">
<amp-img src="./img/lilacgradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="./img/tealgradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="./img/orangegradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="../../../manual/img/lilacgradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="../../../manual/img/tealgradient.png" width="400" height="300" layout="responsive"></amp-img>
<amp-img src="../../../manual/img/orangegradient.png" width="400" height="300" layout="responsive"></amp-img>
</amp-carousel>
</div>

Expand All @@ -89,20 +86,20 @@

<div>
<amp-img lightbox="hero"
src="./img/lilacgradient.png"
src="../../../manual/img/lilacgradient.png"
width="400"
height="300"
layout="responsive">
<span class="overlay-text">See photo gallery</span>
</amp-img>
<div hidden>
<amp-img lightbox="hero"
src="./img/orangegradient.png"
src="../../../manual/img/orangegradient.png"
layout="responsive"
width="400"
height="300"></amp-img>
<amp-img lightbox="hero"
src="./img/tealgradient.png"
src="../../../manual/img/tealgradient.png"
width="400"
height="300"
layout="responsive" ></amp-img>
Expand All @@ -120,7 +117,7 @@

<amp-img
lightbox="caption"
src="./img/lemonyellowgradient.png"
src="../../../manual/img/lemonyellowgradient.png"
width="300"
height="200"
layout="responsive"></amp-img>
Expand All @@ -129,7 +126,7 @@
<figure>
<amp-img
lightbox="caption"
src="./img/redgradient.png"
src="../../../manual/img/redgradient.png"
width="300"
height="200"
layout="responsive"></amp-img>
Expand All @@ -141,7 +138,7 @@

<amp-img
lightbox="caption"
src="./img/greengradient.png"
src="../../../manual/img/greengradient.png"
layout="responsive"
width="300"
height="200"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="/components/amp-lightbox-gallery/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>amp-lightbox-gallery with amp-carousel 0.2</title>
<script async custom-element="amp-lightbox-gallery" src="https://cdn.ampproject.org/v0/amp-lightbox-gallery-0.1.js"></script>
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.2.js"></script>

<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
.overlay-text {
position: absolute;
bottom: 16px;
left: 16px;
z-index: 1;
pointer-events: none;
background-color: #494A4D;
color: white;
padding: 2px 6px 2px 6px;
border-radius: 2px;
opacity: 0.7;
font-family: Roboto, sans-serif;
font-size: 1em;
}

figure {
margin: 0;
}

amp-img[lightbox] {
cursor: pointer;
}

.container {
margin: 0 6% 0 6%;
}

.paragraph {
padding: 10px 0 10px 0;
}

</style>
</head>
<body>
<div class="container">
<amp-img lightbox src="../../../manual/img/bluegradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<amp-img lightbox src="../../../manual/img/redgradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<amp-img lightbox src="../../../manual/img/lemonyellowgradient.png" width="300" height="200" layout="responsive"></amp-img>
<p class="paragraph">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</body>
</html>

0 comments on commit 2a03843

Please sign in to comment.