UPDATE
I looked at allenhwkim's answer and he is really right that $event distribution can be easily stopped. I took it for granted (without checking) that attaching the ng-swipe-* directive to another element would start firing individual events. I was clearly wrong.
The violin is updated HERE .
Below is the answer, mostly garbage.
There is still one problem with stopPropagation - the mouse up event does not fire.
The most elegant solution would be to decorate the ng-swipe-* or $swipe directives, and then study their code, and I don't think it is possible.
Another option is to create your own directive, which will manually attach ng-swipe-* , take care of the compilation process and provide the desired functions. Of course, the bit is complicated.
What I came up with is a quick hack. The idea is to add an attribute to an element whose descendants should not run ng-swipe-* .
Js
myApp.value('shouldFire', function(element){ var update = true; // strange enough $event.fromElement is always null var current = element; while(current && current != document.body){ if(current.getAttribute('swipe')=='cancel'){ update = false; break; } current = current.parentElement; } return update; }) function MyCtrl($scope, shouldFire) { $scope.sidebar = false; $scope.updateSidebar = function($event, show){ var element = $event.toElement || $event.srcElement; shouldFire(element) && ($scope.sidebar = show); } }
HTML
<div class="cont" ng-swipe-right="updateSidebar($event, true)" ng-swipe-left="updateSidebar($event, false)"> ... <div class="pan-container" panhandler="" content-width="500px" swipe="cancel">
UPDATED DEMO
caution
- in android chrome.v.39 angular -panhandler does not work.
$event stores the correct touch event (android chrome) or custom event (desktop chrome); in the latter case, $event.fromElement always null .- The proposed solution is a quick hack - it is neither elegant nor general. However, it would theoretically be possible to support multi
ng-swipe-* setting different values ββin the swipe attribute.
source share