Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On chrome, a long press opens the context menu. Prevent that. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/hoverontouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// [ ] mouse click triggered on ios / android works -> ios bug?
// [ ] Android no redraw on scroll

window.oncontextmenu = function() { return false; } // https://stackoverflow.com/questions/41060472/how-to-disable-the-context-menu-on-long-press-when-using-device-mode-in-chrome


function HoverOnTouch() {
this.init();
Expand Down Expand Up @@ -176,13 +178,18 @@ HoverOnTouch.prototype.touchendHoverontouch = function (e) {
if (!this.longpress && this.multiTouchGesture === false && this.multipleTouchAmount === 0) {
//this is a click, so go to the data-link, but only if data link exists and not more scrolling than 10px
// calculate Distance
var XOriginal = this.scrollStartX;
var XEnd = e.changedTouches[0].pageX;
var distanceX = Math.abs(XOriginal - XEnd);

var YEnd = e.changedTouches[0].pageY;
var YOriginal = this.scrollStartY;
var distanceY = Math.abs(YOriginal - YEnd);
var distanceX = 0;
var distanceY = 0;
if (! e.changedTouches.length === 0) {
// if there are no changed touches, just show the link
var XOriginal = this.scrollStartX;
var XEnd = e.changedTouches[0].pageX;
distanceX = Math.abs(XOriginal - XEnd);

var YEnd = e.changedTouches[0].pageY;
var YOriginal = this.scrollStartY;
distanceY = Math.abs(YOriginal - YEnd);
}

if (object.getAttribute('data-link') && distanceY <= 5 && distanceX <= 5) {
var location = object.getAttribute('data-link');
Expand Down Expand Up @@ -295,4 +302,4 @@ HoverOnTouch.prototype.getClosest = function (elem, selector) {
};


// jshint ignore: end
// jshint ignore: end