title: how can I add swipe detection to a javascript script that uses keydown
body: <p>I have a site that uses mediaboxAdv1.3.4b.js to display images. Keydown events are used to move through images and I would like to add the ability on a mobile device to use swipe left/right. In the MediaboxAdv code the relevant part seems to be that pasted below. I guess it should be straightforward to edit this to add swipe events using something like hammer.js but my experiments so far have failed. </p>
  
  <pre><code>    if (options.keyboard) document[fn]("keydown", keyDown);
  }
  
  function keyDown(event) {
          switch(event.code) {
              case 27:    // Esc
              case 88:    // 'x'
              case 67:    // 'c'
                  close();
                  break;
              case 37:    // Left arrow
              case 188:   // , &lt;
              case 80:    // 'p'
                  previous();
                  break;
              case 39:    // Right arrow
              case 190:   // . &gt;
              case 78:    // 'n'
                  next();
          } 
      }
      if (options.stopKey) { return false; };
  }
  
  function previous() {
      return changeImage(prevImage);
  }
  
  function next() {
      return changeImage(nextImage);
  </code></pre>