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

Go to target slide in gallary view in lightbox 2.0 #9731

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions extensions/amp-carousel/0.1/slidescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class AmpSlideScroll extends BaseSlides {
this.registerAction('goToSlide', invocation => {
const args = invocation.args;
if (args) {
this.showSlideWhenReady_(args['index']);
this.showSlideWhenReady(args['index']);
}
});
}
Expand All @@ -222,7 +222,7 @@ export class AmpSlideScroll extends BaseSlides {
mutatedAttributesCallback(mutations) {
const slide = mutations['slide'];
if (slide !== undefined) {
this.showSlideWhenReady_(slide);
this.showSlideWhenReady(slide);
}
}

Expand Down Expand Up @@ -493,9 +493,8 @@ export class AmpSlideScroll extends BaseSlides {
* Parses given value as integer and shows the slide with that index value
* when element has been laid out.
* @param {*} value
* @private
*/
showSlideWhenReady_(value) {
showSlideWhenReady(value) {
const index = parseInt(value, 10);
if (isFinite(index) && index >= 0 && index < this.noOfSlides_) {
// If we haven't been laid out yet, set `initialSlideIndex_` instead.
Expand Down
9 changes: 6 additions & 3 deletions extensions/amp-lightbox-viewer/0.1/amp-lightbox-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ export class AmpLightboxViewer extends AMP.BaseElement {
this.updateInViewport(this.container_, true);
this.scheduleLayout(this.container_);

this.carousel_.implementation_.showSlideWhenReady_(element.lightboxItemId);
this.currentElementId_ = element.lightboxItemId;
this.carousel_.implementation_.showSlideWhenReady(this.currentElementId_);

this.win.document.documentElement.addEventListener(
'keydown', this.boundHandleKeyboardEvents_);
Expand Down Expand Up @@ -412,11 +412,14 @@ export class AmpLightboxViewer extends AMP.BaseElement {
imgElement.classList.add('i-amphtml-lbv-gallery-thumbnail-img');
imgElement.setAttribute('src', thumbnailObj.url);
element.appendChild(imgElement);
const redirect = event => {
const closeGallaryAndShowTargetSlide = event => {
this.closeGallery_();
this.currentElementId_ = thumbnailObj.element.lightboxItemId;
this.updateDescriptionBox_();
this.carousel_.implementation_.showSlideWhenReady(this.currentElementId_);
event.stopPropagation();
};
element.addEventListener('click', redirect);
element.addEventListener('click', closeGallaryAndShowTargetSlide);
return element;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ describe('amp-lightbox-viewer', () => {
return impl.activate({source: item1}).then(() => {
impl.openGallery_();
const container = viewer.querySelector('.i-amphtml-lbv');
expect(container.getAttribute('gallery-view')).to.equal('');
expect(container.hasAttribute('gallery-view')).to.be.true;
const gallery = viewer.querySelector('.i-amphtml-lbv-gallery');
expect(gallery.childNodes).to.have.length(3);
gallery.childNodes[1].dispatchEvent(new Event('click'));
expect(container.getAttribute('gallery-view')).to.be.null;
expect(container.hasAttribute('gallery-view')).to.be.false;
});
});
});
Expand Down