function initializePage(page) {
          var xStart = 0;
          var index = getIndex(page);

          //don't initiate goToIndex when dragging a page. Therefore check xStart agains x at the mouse up event.
          pages[i].addEventListener('mousedown', function(event) {
            xStart = event.clientX || 0;
          });

          pages[i].addEventListener('mouseup', function(event) {
            var diff = (event.clientX || 0) - xStart;
            diff = Math.abs(diff);

            //if the mouse has moved less than 10px goToIndex
            //also index has to be other than the current index
            if (diff < 10) {
              var nextIndex = index === currentIndex ? currentIndex - 1 : index;
              self.goToIndex(nextIndex);
            }
          });
        }
// I have to encapsulate the initialization in a function to not mess with scopes
I have to encapsulate the initialization in a function to not mess with scopes
I have to encapsulate the initialization in a function to not mess with scopes
function initializePage(page) {
          var xStart = 0;
          var index = getIndex(page);
          pages[i].addEventListener('mousedown', function(event) {
            xStart = event.clientX || 0;
          });
          pages[i].addEventListener('mouseup', function(event) {
            var diff = (event.clientX || 0) - xStart;
            diff = Math.abs(diff);
            if (diff < 10) {
              var nextIndex = index === currentIndex ? currentIndex - 1 : index;
              self.goToIndex(nextIndex);
            }
          });
        }
function initializePage ( page ) { var xStart = 0 ; var index = getIndex ( page ) ; pages [ i ] . addEventListener ( 'mousedown' , function ( event ) { xStart = event . clientX || 0 ; } ) ; pages [ i ] . addEventListener ( 'mouseup' , function ( event ) { var diff = ( event . clientX || 0 ) - xStart ; diff = Math . abs ( diff ) ; if ( diff < 10 ) { var nextIndex = index === currentIndex ? currentIndex - 1 : index ; self . goToIndex ( nextIndex ) ; } } ) ; }
I have to encapsulate the initialization in a function to not mess with scopes
I have to encapsulate the initialization in a function to not mess with scopes
//don't initiate goToIndex when dragging a page. Therefore check xStart agains x at the mouse up event. //if the mouse has moved less than 10px goToIndex //also index has to be other than the current index