leaflet-contextmenu
Advanced tools
Comparing version
@@ -5,8 +5,3 @@ { | ||
"description": "A context menu for Leaflet", | ||
"main": [ | ||
"dist/leaflet.contextmenu.js", | ||
"dist/leaflet.contextmenu.min.js", | ||
"dist/leaflet.contextmenu.css", | ||
"dist/leaflet.contextmenu.min.css" | ||
], | ||
"main": "dist/leaflet.contextmenu.js", | ||
"keywords": [ | ||
@@ -17,9 +12,15 @@ "gis" | ||
"ignore": [ | ||
"**/.*", | ||
"src", | ||
"examples" | ||
"examples", | ||
"package.json", | ||
"bower.json", | ||
".DS_Store", | ||
".git", | ||
".gitingore", | ||
".editorconfig", | ||
"README.md" | ||
], | ||
"dependencies": { | ||
"leaflet": "0.7.x" | ||
"leaflet": "1.x" | ||
} | ||
} |
@@ -62,6 +62,12 @@ /* | ||
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({ | ||
@@ -73,11 +79,15 @@ contextmenu: this._show, | ||
}, 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({ | ||
@@ -89,4 +99,2 @@ contextmenu: this._show, | ||
}, this); | ||
L.DomEvent.off(this._map.getContainer(), 'mouseleave', this._hide, this); | ||
}, | ||
@@ -238,2 +246,6 @@ | ||
if (L.Browser.touch) { | ||
L.DomEvent.on(el, this._touchstart, L.DomEvent.stopPropagation); | ||
} | ||
return { | ||
@@ -264,2 +276,6 @@ id: L.Util.stamp(el), | ||
.off(el, 'click', callback); | ||
if (L.Browser.touch) { | ||
L.DomEvent.off(el, this._touchstart, L.DomEvent.stopPropagation); | ||
} | ||
} | ||
@@ -425,6 +441,2 @@ | ||
_onMouseDown: function (e) { | ||
this._hide(); | ||
}, | ||
_onKeyDown: function (e) { | ||
@@ -464,2 +476,25 @@ var key = e.keyCode; | ||
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 () { | ||
@@ -466,0 +501,0 @@ this._items = []; |
@@ -7,2 +7,2 @@ /* | ||
*/ | ||
(function(t){var e;if(typeof define==="function"&&define.amd){define(["leaflet"],t)}else if(typeof module!=="undefined"){e=require("leaflet");module.exports=t(e)}else{if(typeof window.L==="undefined"){throw new Error("Leaflet must be loaded first")}t(window.L)}})(function(t){t.Map.mergeOptions({contextmenuItems:[]});t.Map.ContextMenu=t.Handler.extend({_touchstart:t.Browser.msPointer?"MSPointerDown":t.Browser.pointer?"pointerdown":"touchstart",statics:{BASE_CLS:"leaflet-contextmenu"},initialize:function(e){t.Handler.prototype.initialize.call(this,e);this._items=[];this._visible=false;var n=this._container=t.DomUtil.create("div",t.Map.ContextMenu.BASE_CLS,e._container);n.style.zIndex=1e4;n.style.position="absolute";if(e.options.contextmenuWidth){n.style.width=e.options.contextmenuWidth+"px"}this._createItems();t.DomEvent.on(n,"click",t.DomEvent.stop).on(n,"mousedown",t.DomEvent.stop).on(n,"dblclick",t.DomEvent.stop).on(n,"contextmenu",t.DomEvent.stop)},addHooks:function(){t.DomEvent.on(document,t.Browser.touch?this._touchstart:"mousedown",this._onMouseDown,this).on(document,"keydown",this._onKeyDown,this);this._map.on({contextmenu:this._show,mousedown:this._hide,movestart:this._hide,zoomstart:this._hide},this);t.DomEvent.on(this._map.getContainer(),"mouseleave",this._hide,this)},removeHooks:function(){t.DomEvent.off(document,t.Browser.touch?this._touchstart:"mousedown",this._onMouseDown,this).off(document,"keydown",this._onKeyDown,this);this._map.off({contextmenu:this._show,mousedown:this._hide,movestart:this._hide,zoomstart:this._hide},this);t.DomEvent.off(this._map.getContainer(),"mouseleave",this._hide,this)},showAt:function(e,n){if(e instanceof t.LatLng){e=this._map.latLngToContainerPoint(e)}this._showAtPoint(e,n)},hide:function(){this._hide()},addItem:function(t){return this.insertItem(t)},insertItem:function(t,e){e=e!==undefined?e:this._items.length;var n=this._createItem(this._container,t,e);this._items.push(n);this._sizeChanged=true;this._map.fire("contextmenu.additem",{contextmenu:this,el:n.el,index:e});return n.el},removeItem:function(e){var n=this._container;if(!isNaN(e)){e=n.children[e]}if(e){this._removeItem(t.Util.stamp(e));this._sizeChanged=true;this._map.fire("contextmenu.removeitem",{contextmenu:this,el:e})}},removeAllItems:function(){var e;while(this._container.children.length){e=this._container.children[0];this._removeItem(t.Util.stamp(e))}},hideAllItems:function(){var t,e,n;for(e=0,n=this._items.length;e<n;e++){t=this._items[e];t.el.style.display="none"}},showAllItems:function(){var t,e,n;for(e=0,n=this._items.length;e<n;e++){t=this._items[e];t.el.style.display=""}},setDisabled:function(e,n){var i=this._container,o=t.Map.ContextMenu.BASE_CLS+"-item";if(!isNaN(e)){e=i.children[e]}if(e&&t.DomUtil.hasClass(e,o)){if(n){t.DomUtil.addClass(e,o+"-disabled");this._map.fire("contextmenu.disableitem",{contextmenu:this,el:e})}else{t.DomUtil.removeClass(e,o+"-disabled");this._map.fire("contextmenu.enableitem",{contextmenu:this,el:e})}}},isVisible:function(){return this._visible},_createItems:function(){var t=this._map.options.contextmenuItems,e,n,i;for(n=0,i=t.length;n<i;n++){this._items.push(this._createItem(this._container,t[n]))}},_createItem:function(e,n,i){if(n.separator||n==="-"){return this._createSeparator(e,i)}var o=t.Map.ContextMenu.BASE_CLS+"-item",s=n.disabled?o+" "+o+"-disabled":o,h=this._insertElementAt("a",s,e,i),a=this._createEventHandler(h,n.callback,n.context,n.hideOnSelect),r="";if(n.icon){r='<img class="'+t.Map.ContextMenu.BASE_CLS+'-icon" src="'+n.icon+'"/>'}else if(n.iconCls){r='<span class="'+t.Map.ContextMenu.BASE_CLS+"-icon "+n.iconCls+'"></span>'}h.innerHTML=r+n.text;h.href="#";t.DomEvent.on(h,"mouseover",this._onItemMouseOver,this).on(h,"mouseout",this._onItemMouseOut,this).on(h,"mousedown",t.DomEvent.stopPropagation).on(h,"click",a);return{id:t.Util.stamp(h),el:h,callback:a}},_removeItem:function(e){var n,i,o,s,h;for(o=0,s=this._items.length;o<s;o++){n=this._items[o];if(n.id===e){i=n.el;h=n.callback;if(h){t.DomEvent.off(i,"mouseover",this._onItemMouseOver,this).off(i,"mouseover",this._onItemMouseOut,this).off(i,"mousedown",t.DomEvent.stopPropagation).off(i,"click",h)}this._container.removeChild(i);this._items.splice(o,1);return n}}return null},_createSeparator:function(e,n){var i=this._insertElementAt("div",t.Map.ContextMenu.BASE_CLS+"-separator",e,n);return{id:t.Util.stamp(i),el:i}},_createEventHandler:function(e,n,i,o){var s=this,h=this._map,a=t.Map.ContextMenu.BASE_CLS+"-item-disabled",o=o!==undefined?o:true;return function(r){if(t.DomUtil.hasClass(e,a)){return}if(o){s._hide()}if(n){n.call(i||h,s._showLocation)}s._map.fire("contextmenu:select",{contextmenu:s,el:e})}},_insertElementAt:function(t,e,n,i){var o,s=document.createElement(t);s.className=e;if(i!==undefined){o=n.children[i]}if(o){n.insertBefore(s,o)}else{n.appendChild(s)}return s},_show:function(t){this._showAtPoint(t.containerPoint,t)},_showAtPoint:function(e,n){if(this._items.length){var i=this._map,o=i.containerPointToLayerPoint(e),s=i.layerPointToLatLng(o),h=t.extend(n||{},{contextmenu:this});this._showLocation={latlng:s,layerPoint:o,containerPoint:e};if(n&&n.relatedTarget){this._showLocation.relatedTarget=n.relatedTarget}this._setPosition(e);if(!this._visible){this._container.style.display="block";this._visible=true}else{this._setPosition(e)}this._map.fire("contextmenu.show",h)}},_hide:function(){if(this._visible){this._visible=false;this._container.style.display="none";this._map.fire("contextmenu.hide",{contextmenu:this})}},_setPosition:function(e){var n=this._map.getSize(),i=this._container,o=this._getElementSize(i),s;if(this._map.options.contextmenuAnchor){s=t.point(this._map.options.contextmenuAnchor);e=e.add(s)}i._leaflet_pos=e;if(e.x+o.x>n.x){i.style.left="auto";i.style.right=Math.max(n.x-e.x,0)+"px"}else{i.style.left=Math.max(e.x,0)+"px";i.style.right="auto"}if(e.y+o.y>n.y){i.style.top="auto";i.style.bottom=Math.max(n.y-e.y,0)+"px"}else{i.style.top=Math.max(e.y,0)+"px";i.style.bottom="auto"}},_getElementSize:function(t){var e=this._size,n=t.style.display;if(!e||this._sizeChanged){e={};t.style.left="-999999px";t.style.right="auto";t.style.display="block";e.x=t.offsetWidth;e.y=t.offsetHeight;t.style.left="auto";t.style.display=n;this._sizeChanged=false}return e},_onMouseDown:function(t){this._hide()},_onKeyDown:function(t){var e=t.keyCode;if(e===27){this._hide()}},_onItemMouseOver:function(e){t.DomUtil.addClass(e.target||e.srcElement,"over")},_onItemMouseOut:function(e){t.DomUtil.removeClass(e.target||e.srcElement,"over")}});t.Map.addInitHook("addHandler","contextmenu",t.Map.ContextMenu);t.Mixin.ContextMenu={bindContextMenu:function(e){t.setOptions(this,e);this._initContextMenu();return this},unbindContextMenu:function(){this.off("contextmenu",this._showContextMenu,this);return this},_initContextMenu:function(){this._items=[];this.on("contextmenu",this._showContextMenu,this)},_showContextMenu:function(e){var n,i,o,s,h;if(this._map.contextmenu){i=t.extend({relatedTarget:this},e);o=this._map.mouseEventToContainerPoint(e.originalEvent);if(!this.options.contextmenuInheritItems){this._map.contextmenu.hideAllItems()}for(s=0,h=this.options.contextmenuItems.length;s<h;s++){n=this.options.contextmenuItems[s];this._items.push(this._map.contextmenu.insertItem(n,n.index))}this._map.once("contextmenu.hide",this._hideContextMenu,this);this._map.contextmenu.showAt(o,i)}},_hideContextMenu:function(){var t,e;for(t=0,e=this._items.length;t<e;t++){this._map.contextmenu.removeItem(this._items[t])}this._items.length=0;if(!this.options.contextmenuInheritItems){this._map.contextmenu.showAllItems()}}};var e=[t.Marker,t.Path],n={contextmenu:false,contextmenuItems:[],contextmenuInheritItems:true},i,o,s;for(o=0,s=e.length;o<s;o++){i=e[o];if(!i.prototype.options){i.prototype.options=n}else{i.mergeOptions(n)}i.addInitHook(function(){if(this.options.contextmenu){this._initContextMenu()}});i.include(t.Mixin.ContextMenu)}return t.Map.ContextMenu}); | ||
(function(t){var e;if(typeof define==="function"&&define.amd){define(["leaflet"],t)}else if(typeof module!=="undefined"){e=require("leaflet");module.exports=t(e)}else{if(typeof window.L==="undefined"){throw new Error("Leaflet must be loaded first")}t(window.L)}})(function(t){t.Map.mergeOptions({contextmenuItems:[]});t.Map.ContextMenu=t.Handler.extend({_touchstart:t.Browser.msPointer?"MSPointerDown":t.Browser.pointer?"pointerdown":"touchstart",statics:{BASE_CLS:"leaflet-contextmenu"},initialize:function(e){t.Handler.prototype.initialize.call(this,e);this._items=[];this._visible=false;var n=this._container=t.DomUtil.create("div",t.Map.ContextMenu.BASE_CLS,e._container);n.style.zIndex=1e4;n.style.position="absolute";if(e.options.contextmenuWidth){n.style.width=e.options.contextmenuWidth+"px"}this._createItems();t.DomEvent.on(n,"click",t.DomEvent.stop).on(n,"mousedown",t.DomEvent.stop).on(n,"dblclick",t.DomEvent.stop).on(n,"contextmenu",t.DomEvent.stop)},addHooks:function(){var e=this._map.getContainer();t.DomEvent.on(e,"mouseleave",this._hide,this).on(document,"keydown",this._onKeyDown,this);if(t.Browser.touch){t.DomEvent.on(document,this._touchstart,this._hide,this)}this._map.on({contextmenu:this._show,mousedown:this._hide,movestart:this._hide,zoomstart:this._hide},this)},removeHooks:function(){var e=this._map.getContainer();t.DomEvent.off(e,"mouseleave",this._hide,this).off(document,"keydown",this._onKeyDown,this);if(t.Browser.touch){t.DomEvent.off(document,this._touchstart,this._hide,this)}this._map.off({contextmenu:this._show,mousedown:this._hide,movestart:this._hide,zoomstart:this._hide},this)},showAt:function(e,n){if(e instanceof t.LatLng){e=this._map.latLngToContainerPoint(e)}this._showAtPoint(e,n)},hide:function(){this._hide()},addItem:function(t){return this.insertItem(t)},insertItem:function(t,e){e=e!==undefined?e:this._items.length;var n=this._createItem(this._container,t,e);this._items.push(n);this._sizeChanged=true;this._map.fire("contextmenu.additem",{contextmenu:this,el:n.el,index:e});return n.el},removeItem:function(e){var n=this._container;if(!isNaN(e)){e=n.children[e]}if(e){this._removeItem(t.Util.stamp(e));this._sizeChanged=true;this._map.fire("contextmenu.removeitem",{contextmenu:this,el:e})}},removeAllItems:function(){var e;while(this._container.children.length){e=this._container.children[0];this._removeItem(t.Util.stamp(e))}},hideAllItems:function(){var t,e,n;for(e=0,n=this._items.length;e<n;e++){t=this._items[e];t.el.style.display="none"}},showAllItems:function(){var t,e,n;for(e=0,n=this._items.length;e<n;e++){t=this._items[e];t.el.style.display=""}},setDisabled:function(e,n){var i=this._container,o=t.Map.ContextMenu.BASE_CLS+"-item";if(!isNaN(e)){e=i.children[e]}if(e&&t.DomUtil.hasClass(e,o)){if(n){t.DomUtil.addClass(e,o+"-disabled");this._map.fire("contextmenu.disableitem",{contextmenu:this,el:e})}else{t.DomUtil.removeClass(e,o+"-disabled");this._map.fire("contextmenu.enableitem",{contextmenu:this,el:e})}}},isVisible:function(){return this._visible},_createItems:function(){var t=this._map.options.contextmenuItems,e,n,i;for(n=0,i=t.length;n<i;n++){this._items.push(this._createItem(this._container,t[n]))}},_createItem:function(e,n,i){if(n.separator||n==="-"){return this._createSeparator(e,i)}var o=t.Map.ContextMenu.BASE_CLS+"-item",s=n.disabled?o+" "+o+"-disabled":o,h=this._insertElementAt("a",s,e,i),a=this._createEventHandler(h,n.callback,n.context,n.hideOnSelect),r="";if(n.icon){r='<img class="'+t.Map.ContextMenu.BASE_CLS+'-icon" src="'+n.icon+'"/>'}else if(n.iconCls){r='<span class="'+t.Map.ContextMenu.BASE_CLS+"-icon "+n.iconCls+'"></span>'}h.innerHTML=r+n.text;h.href="#";t.DomEvent.on(h,"mouseover",this._onItemMouseOver,this).on(h,"mouseout",this._onItemMouseOut,this).on(h,"mousedown",t.DomEvent.stopPropagation).on(h,"click",a);if(t.Browser.touch){t.DomEvent.on(h,this._touchstart,t.DomEvent.stopPropagation)}return{id:t.Util.stamp(h),el:h,callback:a}},_removeItem:function(e){var n,i,o,s,h;for(o=0,s=this._items.length;o<s;o++){n=this._items[o];if(n.id===e){i=n.el;h=n.callback;if(h){t.DomEvent.off(i,"mouseover",this._onItemMouseOver,this).off(i,"mouseover",this._onItemMouseOut,this).off(i,"mousedown",t.DomEvent.stopPropagation).off(i,"click",h);if(t.Browser.touch){t.DomEvent.off(i,this._touchstart,t.DomEvent.stopPropagation)}}this._container.removeChild(i);this._items.splice(o,1);return n}}return null},_createSeparator:function(e,n){var i=this._insertElementAt("div",t.Map.ContextMenu.BASE_CLS+"-separator",e,n);return{id:t.Util.stamp(i),el:i}},_createEventHandler:function(e,n,i,o){var s=this,h=this._map,a=t.Map.ContextMenu.BASE_CLS+"-item-disabled",o=o!==undefined?o:true;return function(r){if(t.DomUtil.hasClass(e,a)){return}if(o){s._hide()}if(n){n.call(i||h,s._showLocation)}s._map.fire("contextmenu:select",{contextmenu:s,el:e})}},_insertElementAt:function(t,e,n,i){var o,s=document.createElement(t);s.className=e;if(i!==undefined){o=n.children[i]}if(o){n.insertBefore(s,o)}else{n.appendChild(s)}return s},_show:function(t){this._showAtPoint(t.containerPoint,t)},_showAtPoint:function(e,n){if(this._items.length){var i=this._map,o=i.containerPointToLayerPoint(e),s=i.layerPointToLatLng(o),h=t.extend(n||{},{contextmenu:this});this._showLocation={latlng:s,layerPoint:o,containerPoint:e};if(n&&n.relatedTarget){this._showLocation.relatedTarget=n.relatedTarget}this._setPosition(e);if(!this._visible){this._container.style.display="block";this._visible=true}else{this._setPosition(e)}this._map.fire("contextmenu.show",h)}},_hide:function(){if(this._visible){this._visible=false;this._container.style.display="none";this._map.fire("contextmenu.hide",{contextmenu:this})}},_setPosition:function(e){var n=this._map.getSize(),i=this._container,o=this._getElementSize(i),s;if(this._map.options.contextmenuAnchor){s=t.point(this._map.options.contextmenuAnchor);e=e.add(s)}i._leaflet_pos=e;if(e.x+o.x>n.x){i.style.left="auto";i.style.right=Math.max(n.x-e.x,0)+"px"}else{i.style.left=Math.max(e.x,0)+"px";i.style.right="auto"}if(e.y+o.y>n.y){i.style.top="auto";i.style.bottom=Math.max(n.y-e.y,0)+"px"}else{i.style.top=Math.max(e.y,0)+"px";i.style.bottom="auto"}},_getElementSize:function(t){var e=this._size,n=t.style.display;if(!e||this._sizeChanged){e={};t.style.left="-999999px";t.style.right="auto";t.style.display="block";e.x=t.offsetWidth;e.y=t.offsetHeight;t.style.left="auto";t.style.display=n;this._sizeChanged=false}return e},_onKeyDown:function(t){var e=t.keyCode;if(e===27){this._hide()}},_onItemMouseOver:function(e){t.DomUtil.addClass(e.target||e.srcElement,"over")},_onItemMouseOut:function(e){t.DomUtil.removeClass(e.target||e.srcElement,"over")}});t.Map.addInitHook("addHandler","contextmenu",t.Map.ContextMenu);t.Mixin.ContextMenu={bindContextMenu:function(e){t.setOptions(this,e);this._initContextMenu();return this},unbindContextMenu:function(){this.off("contextmenu",this._showContextMenu,this);return this},addContextMenuItem:function(t){this.options.contextmenuItems.push(t)},removeContextMenuItemWithIndex:function(t){var e=[];for(var n=0;n<this.options.contextmenuItems.length;n++){if(this.options.contextmenuItems[n].index==t){e.push(n)}}var i=e.pop();while(i!==undefined){this.options.contextmenuItems.splice(i,1);i=e.pop()}},replaceConextMenuItem:function(t){this.removeContextMenuItemWithIndex(t.index);this.addContextMenuItem(t)},_initContextMenu:function(){this._items=[];this.on("contextmenu",this._showContextMenu,this)},_showContextMenu:function(e){var n,i,o,s,h;if(this._map.contextmenu){i=t.extend({relatedTarget:this},e);o=this._map.mouseEventToContainerPoint(e.originalEvent);if(!this.options.contextmenuInheritItems){this._map.contextmenu.hideAllItems()}for(s=0,h=this.options.contextmenuItems.length;s<h;s++){n=this.options.contextmenuItems[s];this._items.push(this._map.contextmenu.insertItem(n,n.index))}this._map.once("contextmenu.hide",this._hideContextMenu,this);this._map.contextmenu.showAt(o,i)}},_hideContextMenu:function(){var t,e;for(t=0,e=this._items.length;t<e;t++){this._map.contextmenu.removeItem(this._items[t])}this._items.length=0;if(!this.options.contextmenuInheritItems){this._map.contextmenu.showAllItems()}}};var e=[t.Marker,t.Path],n={contextmenu:false,contextmenuItems:[],contextmenuInheritItems:true},i,o,s;for(o=0,s=e.length;o<s;o++){i=e[o];if(!i.prototype.options){i.prototype.options=n}else{i.mergeOptions(n)}i.addInitHook(function(){if(this.options.contextmenu){this._initContextMenu()}});i.include(t.Mixin.ContextMenu)}return t.Map.ContextMenu}); |
{ | ||
"name": "leaflet-contextmenu", | ||
"version": "1.1.0", | ||
"description": "A context menu for Leaflet", | ||
"main": "dist/leaflet.contextmenu.js", | ||
"directories": { | ||
"example": "examples" | ||
}, | ||
"scripts": { | ||
"concat": "cat src/copyright.js src/Map.ContextMenu.js src/Mixin.ContextMenu.js src/end.js > dist/leaflet.contextmenu.js", | ||
"compress": "uglifyjs dist/leaflet.contextmenu.js -m --comments -o dist/leaflet.contextmenu.min.js; uglifycss dist/leaflet.contextmenu.css > dist/leaflet.contextmenu.min.css", | ||
"build": "npm run concat && npm run compress" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aratcliffe/Leaflet.contextmenu.git" | ||
}, | ||
"keywords": [ | ||
"leaflet", | ||
"contextmenu", | ||
"mixin", | ||
"context", | ||
"menu" | ||
], | ||
"author": "Adam Ratcliffe", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/aratcliffe/Leaflet.contextmenu/issues" | ||
}, | ||
"homepage": "https://github.com/aratcliffe/Leaflet.contextmenu", | ||
"devDependencies": { | ||
"uglifyjs": "^2.3.6" | ||
} | ||
"name": "leaflet-contextmenu", | ||
"version": "1.1.1", | ||
"description": "A context menu for Leaflet", | ||
"main": "dist/leaflet.contextmenu.js", | ||
"directories": { | ||
"example": "examples" | ||
}, | ||
"scripts": { | ||
"concat": "cat src/copyright.js src/Map.ContextMenu.js src/Mixin.ContextMenu.js src/end.js > dist/leaflet.contextmenu.js", | ||
"compress": "uglifyjs dist/leaflet.contextmenu.js -m --comments -o dist/leaflet.contextmenu.min.js; uglifycss dist/leaflet.contextmenu.css > dist/leaflet.contextmenu.min.css", | ||
"build": "npm run concat && npm run compress" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aratcliffe/Leaflet.contextmenu.git" | ||
}, | ||
"keywords": [ | ||
"leaflet", | ||
"contextmenu", | ||
"mixin", | ||
"context", | ||
"menu" | ||
], | ||
"author": "Adam Ratcliffe", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/aratcliffe/Leaflet.contextmenu/issues" | ||
}, | ||
"homepage": "https://github.com/aratcliffe/Leaflet.contextmenu", | ||
"devDependencies": { | ||
"uglifyjs": "^2.3.6" | ||
} | ||
} |
@@ -5,2 +5,4 @@ #Leaflet.contextmenu | ||
Now supporting Leaflet 1.0 | ||
##Usage | ||
@@ -7,0 +9,0 @@ The context menu is implemented as a map interaction handler. To use the plugin include the script and enable using the map `contextmenu` option. |
/* | ||
Leaflet.contextmenu, a context menu for Leaflet. | ||
(c) 2015, Adam Ratcliffe, GeoSmart Maps Limited | ||
@preserve | ||
@@ -14,3 +14,3 @@ */ | ||
define(['leaflet'], factory); | ||
} else if (typeof module !== 'undefined') { | ||
} else if (typeof module === 'object' && typeof module.exports === 'object') { | ||
// Node/CommonJS | ||
@@ -17,0 +17,0 @@ L = require('leaflet'); |
@@ -37,6 +37,12 @@ L.Map.mergeOptions({ | ||
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({ | ||
@@ -48,11 +54,15 @@ contextmenu: this._show, | ||
}, 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({ | ||
@@ -64,4 +74,2 @@ contextmenu: this._show, | ||
}, this); | ||
L.DomEvent.off(this._map.getContainer(), 'mouseleave', this._hide, this); | ||
}, | ||
@@ -213,2 +221,6 @@ | ||
if (L.Browser.touch) { | ||
L.DomEvent.on(el, this._touchstart, L.DomEvent.stopPropagation); | ||
} | ||
return { | ||
@@ -239,2 +251,6 @@ id: L.Util.stamp(el), | ||
.off(el, 'click', callback); | ||
if (L.Browser.touch) { | ||
L.DomEvent.off(el, this._touchstart, L.DomEvent.stopPropagation); | ||
} | ||
} | ||
@@ -400,6 +416,2 @@ | ||
_onMouseDown: function (e) { | ||
this._hide(); | ||
}, | ||
_onKeyDown: function (e) { | ||
@@ -406,0 +418,0 @@ var key = e.keyCode; |
@@ -16,2 +16,25 @@ L.Mixin.ContextMenu = { | ||
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(); | ||
} | ||
}, | ||
replaceContextMenuItem: function (item) { | ||
this.removeContextMenuItemWithIndex(item.index); | ||
this.addContextMenuItem(item); | ||
}, | ||
_initContextMenu: function () { | ||
@@ -18,0 +41,0 @@ this._items = []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
223
0.9%137642
-6.41%18
-5.26%1321
-21.32%