Skip to content

Commit

Permalink
Fix for menu item click handlers not being invoked on IE 11 under Lea…
Browse files Browse the repository at this point in the history
…flet 1.0
  • Loading branch information
aratcliffe committed Oct 2, 2016
1 parent a303808 commit 0b03bd3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
====================
A context menu for Leaflet. See the [demo](http://aratcliffe.github.io/Leaflet.contextmenu/examples/index.html).

Now supporting Leaflet 1.0

##Usage
The context menu is implemented as a map interaction handler. To use the plugin include the script and enable using the map `contextmenu` option.

Expand Down
55 changes: 45 additions & 10 deletions dist/leaflet.contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,41 @@ L.Map.ContextMenu = L.Handler.extend({
},

addHooks: function () {
var container = this._map.getContainer();

L.DomEvent
.on(document, (L.Browser.touch ? this._touchstart : 'mousedown'), this._onMouseDown, this)
.on(container, 'mouseleave', this._hide, this)
.on(document, 'keydown', this._onKeyDown, this);

if (L.Browser.touch) {
L.DomEvent.on(document, this._touchstart, this._hide, this);
}

this._map.on({
contextmenu: this._show,
mousedown: this._hide,
movestart: this._hide,
zoomstart: this._hide
}, this);

L.DomEvent.on(this._map.getContainer(), 'mouseleave', this._hide, this);
},

removeHooks: function () {
var container = this._map.getContainer();

L.DomEvent
.off(document, (L.Browser.touch ? this._touchstart : 'mousedown'), this._onMouseDown, this)
.off(container, 'mouseleave', this._hide, this)
.off(document, 'keydown', this._onKeyDown, this);

if (L.Browser.touch) {
L.DomEvent.off(document, this._touchstart, this._hide, this);
}

this._map.off({
contextmenu: this._show,
mousedown: this._hide,
movestart: this._hide,
zoomstart: this._hide
}, this);

L.DomEvent.off(this._map.getContainer(), 'mouseleave', this._hide, this);
},

showAt: function (point, data) {
Expand Down Expand Up @@ -232,6 +240,10 @@ L.Map.ContextMenu = L.Handler.extend({
.on(el, 'mousedown', L.DomEvent.stopPropagation)
.on(el, 'click', callback);

if (L.Browser.touch) {
L.DomEvent.on(el, this._touchstart, L.DomEvent.stopPropagation);
}

return {
id: L.Util.stamp(el),
el: el,
Expand All @@ -257,6 +269,10 @@ L.Map.ContextMenu = L.Handler.extend({
.off(el, 'mouseover', this._onItemMouseOut, this)
.off(el, 'mousedown', L.DomEvent.stopPropagation)
.off(el, 'click', callback);

if (L.Browser.touch) {
L.DomEvent.off(el, this._touchstart, L.DomEvent.stopPropagation);
}
}

this._container.removeChild(el);
Expand Down Expand Up @@ -417,10 +433,6 @@ L.Map.ContextMenu = L.Handler.extend({
return size;
},

_onMouseDown: function (e) {
this._hide();
},

_onKeyDown: function (e) {
var key = e.keyCode;

Expand Down Expand Up @@ -455,6 +467,29 @@ L.Mixin.ContextMenu = {
return this;
},

addContextMenuItem: function (item) {
this.options.contextmenuItems.push(item);
},

removeContextMenuItemWithIndex: function (index) {
var items = [];
for (var i = 0; i < this.options.contextmenuItems.length; i++) {
if(this.options.contextmenuItems[i].index == index){
items.push(i);
}
}
var elem = items.pop();
while (elem !== undefined) {
this.options.contextmenuItems.splice(elem,1);
elem = items.pop();
}
},

replaceConextMenuItem: function (item) {
this.removeContextMenuItemWithIndex(item.index);
this.addContextMenuItem(item);
},

_initContextMenu: function () {
this._items = [];

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 0b03bd3

Please sign in to comment.