From 3ae083f5cfcc558c5fa796a54af723d8d0373518 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 5 Mar 2015 12:17:53 -0800 Subject: [PATCH] Suppress click event following compass gesture (fixes #1055) --- js/ui/control/navigation.js | 6 ++++++ js/util/browser/dom.js | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/js/ui/control/navigation.js b/js/ui/control/navigation.js index 9ded33a22ae..13fce8c3399 100644 --- a/js/ui/control/navigation.js +++ b/js/ui/control/navigation.js @@ -59,6 +59,7 @@ Navigation.prototype = util.inherit(Control, { this._map.setBearing(this._map.getBearing() - d); this._prevX = e.screenX; + this._moved = true; e.preventDefault(); }, @@ -67,6 +68,11 @@ Navigation.prototype = util.inherit(Control, { document.removeEventListener('mousemove', this._onCompassMove); document.removeEventListener('mouseup', this._onCompassUp); DOM.enableDrag(); + + if (this._moved) { + this._moved = false; + DOM.suppressClick(); + } }, _createButton: function(className, fn) { diff --git a/js/util/browser/dom.js b/js/util/browser/dom.js index de5f43363ef..95a5ffe5ab4 100644 --- a/js/util/browser/dom.js +++ b/js/util/browser/dom.js @@ -35,3 +35,16 @@ var transformProp = testProp(['transform', 'WebkitTransform']); exports.setTransform = function(el, value) { el.style[transformProp] = value; }; + +// Suppress the next click, but only if it's immediate. +function suppressClick(e) { + e.preventDefault(); + e.stopPropagation(); + window.removeEventListener('click', suppressClick, true); +} +exports.suppressClick = function() { + window.addEventListener('click', suppressClick, true); + window.setTimeout(function() { + window.removeEventListener('click', suppressClick, true); + }, 0); +};