Skip to content

Commit

Permalink
fix(swiper): add safe-guards when user tries to zoom a slide without …
Browse files Browse the repository at this point in the history
…an image (#12931)

Fixes #12861
  • Loading branch information
kensodemann authored Sep 29, 2017
1 parent dac8870 commit e0c8309
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/slides/swiper/swiper-zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ function onGestureStart(s: Slides, _plt: Platform, ev: TouchEvent) {
}

z.gesture.image = <HTMLElement>z.gesture.slide.querySelector('img, svg, canvas, ion-img');
z.gesture.imageWrap = <HTMLElement>z.gesture.image.closest('.' + CLS.zoomContainer);
if (z.gesture.image) {
z.gesture.imageWrap = <HTMLElement>z.gesture.image.closest('.' + CLS.zoomContainer);

if (!z.gesture.imageWrap) {
z.gesture.image = undefined;
return;
}
if (!z.gesture.imageWrap) {
z.gesture.image = undefined;
return;
}

z.gesture.zoomMax = parseInt(z.gesture.imageWrap.getAttribute('data-swiper-zoom') || <any>s.zoomMax, 10);
z.gesture.zoomMax = parseInt(z.gesture.imageWrap.getAttribute('data-swiper-zoom') || <any>s.zoomMax, 10);
}
}

transition(z.gesture.image, 0);
Expand Down Expand Up @@ -349,10 +351,10 @@ function toggleZoom(s: Slides, plt: Platform) {
if (!z.gesture.slide) {
z.gesture.slide = s.clickedSlide ? s.clickedSlide : s._slides[s._activeIndex];
z.gesture.image = <HTMLElement>z.gesture.slide.querySelector('img, svg, canvas, ion-img');
z.gesture.imageWrap = <HTMLElement>z.gesture.image.closest('.' + CLS.zoomContainer);
z.gesture.imageWrap = z.gesture.image && <HTMLElement>z.gesture.image.closest('.' + CLS.zoomContainer);
}

if (!z.gesture.image) return;
if (!z.gesture.imageWrap) return;

var touchX: number;
var touchY: number;
Expand Down

0 comments on commit e0c8309

Please sign in to comment.