Skip to content

Commit

Permalink
Suppress click event following compass gesture (fixes #1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Mar 5, 2015
1 parent cd37a51 commit 3ae083f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions js/ui/control/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions js/util/browser/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 3ae083f

Please sign in to comment.