From 91aecd376bb652d9946a882fdf0ec2f8f97a2ebc Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 14 Nov 2012 14:07:59 +0200 Subject: [PATCH] add Marker contextmenu event --- src/layer/marker/Marker.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 7e8a4bdf..7a4dd59f 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -179,12 +179,13 @@ L.Marker = L.Class.extend({ }, _initInteraction: function () { - if (!this.options.clickable) { - return; - } + + if (!this.options.clickable) { return; } + + // TODO refactor into something shared with Map/Path/etc. to DRY it up var icon = this._icon, - events = ['dblclick', 'mousedown', 'mouseover', 'mouseout']; + events = ['dblclick', 'mousedown', 'mouseover', 'mouseout', 'contextmenu']; L.DomUtil.addClass(icon, 'leaflet-clickable'); L.DomEvent.on(icon, 'click', this._onMouseClick, this); @@ -204,20 +205,31 @@ L.Marker = L.Class.extend({ _onMouseClick: function (e) { var wasDragged = this.dragging && this.dragging.moved(); + if (this.hasEventListeners(e.type) || wasDragged) { L.DomEvent.stopPropagation(e); } + if (wasDragged) { return; } + if (this._map.dragging && this._map.dragging.moved()) { return; } + this.fire(e.type, { originalEvent: e }); }, _fireMouseEvent: function (e) { + this.fire(e.type, { originalEvent: e }); + + // TODO proper custom event propagation + // this line will always be called if marker is in a FeatureGroup + if (e.type === 'contextmenu' && this.hasEventListeners(e.type)) { + L.DomEvent.preventDefault(e); + } if (e.type !== 'mousedown') { L.DomEvent.stopPropagation(e); }