Skip to content

Commit

Permalink
take into account right clicks
Browse files Browse the repository at this point in the history
right click is a shortcut for hold
  • Loading branch information
Stephen von Takach committed Oct 14, 2013
1 parent 051792e commit d10081e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
4 changes: 4 additions & 0 deletions ngGesture/directive/ngClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

switch (ev.eventType) {
case $gesture.utils.EVENT_START:
if (ev.srcEvent.button !== 0) {
inst.stopDetect();
break;
}
this.valid = true;
break;
case $gesture.utils.EVENT_MOVE:
Expand Down
4 changes: 4 additions & 0 deletions ngGesture/directive/ngDrag.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

switch (ev.eventType) {
case $gesture.utils.EVENT_START:
if (ev.srcEvent.button !== 0) {
inst.stopDetect();
break;
}
this.triggered = false;
break;

Expand Down
49 changes: 14 additions & 35 deletions ngGesture/directive/ngHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,30 @@
holdMaxPointers : 1,
holdDuration : 751, // 750ms, or less, is a tap
holdMoveTolerance : 10, // Doesn't overlap with drags move tolerance and is equal to click
holdAcceptRightClick: true, // Allow users with mice to right click instead of holding
touchActiveClass : 'ng-click-active',
touchAction : 'auto' // don't prevent scrolling
holdAcceptRightClick: true, // Allow users with mice to right click instead of holding
touchActiveClass : 'ng-click-active'
},
setup: function(el, inst) {
// Use the setup function to bind to clicks
// right clicks are ignored by $gesture
// Use the setup function to prevent context menus
if (inst.options.holdAcceptRightClick) {
if ($window.document.addEventListener) {
el.bind('click contextmenu', function(event) {
event = event.originalEvent || event;
// mouse events use which, pointer events use button
if (event.which === 3 || event.button === 2) {
inst.trigger('hold', event);
event.preventDefault(); // Prevent the context menu
}
});
} else { // IE 8 or lower
var button, allow_event = false;
el.bind('mouseup', function(event) { // IE doesn't have button values on mouse up
event = event.originalEvent || event;
button = event.button;
allow_event = $window.setTimeout(function() {
allow_event = false;
}, 0);
});
el.bind('click contextmenu', function(event) { // Check the last button value
event = event.originalEvent || event;
if (button === 2 && allow_event !== false) {
$window.clearTimeout(allow_event); // make sure only one right click is approved
allow_event = false;

inst.trigger('hold', event);
event.returnValue = false; // Prevent the context menu
}
});
}
el.bind('contextmenu', function(event) {
event = event.originalEvent || event;
// mouse events use which, pointer events use button
if (event.button === 2) {
event.preventDefault(); // Prevent the context menu
}
});
}
},
handler: function(ev, inst) {
var self = this;

switch (ev.eventType) {
case $gesture.utils.EVENT_START:
if (ev.touches.length <= inst.options.holdMaxPointers) {
if (inst.options.holdAcceptRightClick === true && ev.srcEvent.button === 2) {
inst.current.name = self.name; // Trigger on right click
inst.trigger(self.name, ev);
} else if (ev.touches.length <= inst.options.holdMaxPointers) {
self.valid = $timeout(function() {
inst.current.name = self.name; // Set the event and trigger if
inst.trigger(self.name, ev); // we have been holding long
Expand Down
4 changes: 4 additions & 0 deletions ngGesture/directive/ngSwipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

switch (ev.eventType) {
case $gesture.utils.EVENT_START:
if (ev.srcEvent.button !== 0) {
inst.stopDetect();
break;
}
this.valid = true;
break;
case $gesture.utils.EVENT_MOVE:
Expand Down
5 changes: 5 additions & 0 deletions ngGesture/directive/ngTouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
touchActiveClass: 'ng-click-active'
},
handler: function(ev, inst) {
if (ev.srcEvent.button !== 0) {
inst.stopDetect();
return;
}

if (inst.options.touchPreventDefault) {
ev.preventDefault();
}
Expand Down

0 comments on commit d10081e

Please sign in to comment.