Skip to content

Commit

Permalink
Fix Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 22, 2018
1 parent e9c4c45 commit 5a3f663
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ui/handler/drag_pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DragPanHandler {
window.document.addEventListener('touchmove', this._onMove, {capture: true});
window.document.addEventListener('touchend', this._onUp);
} else {
if (e.ctrlKey || e.button !== 0) return;
if (e.ctrlKey || DOM.mouseButton((e: any)) !== 0) return;
window.document.addEventListener('mousemove', this._onMove, {capture: true});
window.document.addEventListener('mouseup', this._onUp);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ class DragPanHandler {
* @private
*/
_onUp(e: MouseEvent | TouchEvent | FocusEvent) {
if (e.type === 'mouseup' && e.button !== 0) return;
if (e.type === 'mouseup' && DOM.mouseButton((e: any)) !== 0) return;

window.document.removeEventListener('touchmove', this._onMove, {capture: true});
window.document.removeEventListener('touchend', this._onUp);
Expand Down
13 changes: 3 additions & 10 deletions src/ui/handler/drag_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,10 @@ class DragRotateHandler {
if (this.isActive()) return;

if (this._button === 'right') {
this._eventButton = e.button;
if (typeof window.InstallTrigger !== 'undefined' && e.button === 2 && e.ctrlKey &&
window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
// Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
// Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
// using Control + left click
this._eventButton = 0;
}
this._eventButton = DOM.mouseButton(e);
if (this._eventButton !== (e.ctrlKey ? 0 : 2)) return;
} else {
if (e.ctrlKey || e.button !== 0) return;
if (e.ctrlKey || DOM.mouseButton(e) !== 0) return;
this._eventButton = 0;
}

Expand Down Expand Up @@ -184,7 +177,7 @@ class DragRotateHandler {
}

_onUp(e: MouseEvent | FocusEvent) {
if (e.type === 'mouseup' && e.button !== this._eventButton) return;
if (e.type === 'mouseup' && DOM.mouseButton((e: any)) !== this._eventButton) return;

window.document.removeEventListener('mousemove', this._onMove, {capture: true});
window.document.removeEventListener('mouseup', this._onUp);
Expand Down
13 changes: 13 additions & 0 deletions src/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Point = require('@mapbox/point-geometry');
const window = require('./window');
const assert = require('assert');

exports.create = function (tagName: *, className?: string, container?: HTMLElement) {
const el = window.document.createElement(tagName);
Expand Down Expand Up @@ -81,6 +82,18 @@ exports.touchPos = function (el: HTMLElement, e: any) {
return points;
};

exports.mouseButton = function (e: MouseEvent) {
assert(e.type === 'mousedown' || e.type === 'mouseup');
if (typeof window.InstallTrigger !== 'undefined' && e.button === 2 && e.ctrlKey &&
window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
// Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
// Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
// using Control + left click
return 0;
}
return e.button;
};

exports.remove = function(node: HTMLElement) {
if (node.parentNode) {
node.parentNode.removeChild(node);
Expand Down

0 comments on commit 5a3f663

Please sign in to comment.