Skip to content

Commit

Permalink
Merge pull request #110 from jelhan/do-not-hide-on-movestart
Browse files Browse the repository at this point in the history
Better user experience on touch devices
  • Loading branch information
aratcliffe authored Feb 18, 2019
2 parents 2404757 + 3653808 commit 743cb7a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
26 changes: 16 additions & 10 deletions dist/leaflet.contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ L.Map.mergeOptions({

L.Map.ContextMenu = L.Handler.extend({
_touchstart: L.Browser.msPointer ? 'MSPointerDown' : L.Browser.pointer ? 'pointerdown' : 'touchstart',

statics: {
BASE_CLS: 'leaflet-contextmenu'
},

initialize: function (map) {
L.Handler.prototype.initialize.call(this, map);

this._items = [];
this._visible = false;

Expand Down Expand Up @@ -71,7 +71,6 @@ L.Map.ContextMenu = L.Handler.extend({
this._map.on({
contextmenu: this._show,
mousedown: this._hide,
movestart: this._hide,
zoomstart: this._hide
}, this);
},
Expand All @@ -90,7 +89,6 @@ L.Map.ContextMenu = L.Handler.extend({
this._map.off({
contextmenu: this._show,
mousedown: this._hide,
movestart: this._hide,
zoomstart: this._hide
}, this);
},
Expand Down Expand Up @@ -320,12 +318,24 @@ L.Map.ContextMenu = L.Handler.extend({
return;
}

var map = me._map,
containerPoint = me._showLocation.containerPoint,
layerPoint = map.containerPointToLayerPoint(containerPoint),
latlng = map.layerPointToLatLng(layerPoint),
relatedTarget = me._showLocation.relatedTarget,
data = {
containerPoint: containerPoint,
layerPoint: layerPoint,
latlng: latlng,
relatedTarget: relatedTarget
};

if (hideOnSelect) {
me._hide();
}

if (func) {
func.call(context || map, me._showLocation);
func.call(context || map, data);
}

me._map.fire('contextmenu.select', {
Expand Down Expand Up @@ -361,13 +371,9 @@ L.Map.ContextMenu = L.Handler.extend({
_showAtPoint: function (pt, data) {
if (this._items.length) {
var map = this._map,
layerPoint = map.containerPointToLayerPoint(pt),
latlng = map.layerPointToLatLng(layerPoint),
event = L.extend(data || {}, {contextmenu: this});

this._showLocation = {
latlng: latlng,
layerPoint: layerPoint,
containerPoint: pt
};

Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet.contextmenu.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 743cb7a

Please sign in to comment.