Custom directive to catch any gesture?


#1

Hi, I had found a custom directive for AngularJS that allow me to catch any “click” event on all the page, then change the default behaviour. I personnaly use it for redirection to another state.

However, when using app on a mobile device, any other gesture event (swipe, etc.) is not caugth.
How would you modify this directive to make it compatible with any gesture?

.directive('clickAnywhereButHere', function($document){
  return {
    restrict: 'A',
    link: function(scope, elem, attr, ctrl) {
      elem.bind('click', function(e) {
        // this part keeps it from firing the click on the document.
        e.stopPropagation();
      });
      $document.bind('click', function() {
        scope.$apply(attr.clickAnywhereButHere);
      })
    }
  }
})