Skip to content Skip to sidebar Skip to footer

How To Enable Touch Events On Pjax Library?

I am developing a site where I use Pjax library (a port of jquery pjax). However the touch events don't go through. I am using Pjax like so: var pjax = new Pjax({ selectors: ['head

Solution 1:

I found the solution, it works by redirecting touch event to click event like this:

if (is_touch_device()) {
  var all_links = document.querySelectorAll('a[href]')
  var event = new Event('click');

  for (var index = 0 ; index < all_links.length ; ++index) {
    all_links[index].addEventListener("touchend", function() {
      all_links[index].dispatchEvent(event)
    });
  }
}

function is_touch_device() {
  return 'ontouchstart' in window        // works on most browsers 
      || navigator.maxTouchPoints;       // works on IE10/11 and Surface
}

Post a Comment for "How To Enable Touch Events On Pjax Library?"