Kris-B / nanoGALLERY

image gallery simplified - jQuery plugin. Touch enabled, responsive, justified/cascading/grid layout and it supports pulling in Flickr, Google Photos and self hosted images.
https://nanogallery2.nanostudio.org/
439 stars 101 forks source link

Gallery stops working on mobile devices #110

Closed jimihay closed 8 years ago

jimihay commented 8 years ago

The gallery stops working on mobile devices if you do the following:

  1. Setup a gallery with pagination and more than 1 page of images
  2. Tap thumbnail to open image
  3. Close enlarged image
  4. Swipe right to show next page
  5. Attempt to tap another thumbnail and nothing happens

The issue seems to be that the event listeners assigned to the viewer are not getting removed when the viewer is closed. Then when attempting to tap on a thumbnail, the viewer event listeners are flipping g_containerViewerDisplayed to true, which in turn is causing the thumbnails' event handlers to return early.

My fix for this is to add the following at line 6874 right above g_viewerSwipe=null;

      if (window.navigator.msPointerEnabled) {
        // Remove Pointer Event Listeners
        document.removeEventListener('MSPointerMove', g_viewerSwipe.handleGestureMove, true);
        document.removeEventListener('MSPointerUp', g_viewerSwipe.handleGestureEnd, true);
      } else {
        // Remove Touch Listeners
        document.removeEventListener('touchmove', g_viewerSwipe.handleGestureMove, true);
        document.removeEventListener('touchend', g_viewerSwipe.handleGestureEnd, true);
        document.removeEventListener('touchcancel', g_viewerSwipe.handleGestureEnd, true);

        // Remove Mouse Listeners
        document.removeEventListener('mousemove', g_viewerSwipe.handleGestureMove, true);
        document.removeEventListener('mouseup', g_viewerSwipe.handleGestureEnd, true);
      }