|
1 | | -/* |
2 | | - Leaflet.contextmenu, a context menu for Leaflet. |
3 | | - (c) 2013, Adam Ratcliffe, GeoSmart Maps Limited |
4 | | -*/ |
5 | 1 | L.Map.mergeOptions({ |
6 | 2 | contextmenuItems: [] |
7 | 3 | }); |
@@ -167,7 +163,7 @@ L.Map.ContextMenu = L.Handler.extend({ |
167 | 163 | var itemCls = L.Map.ContextMenu.BASE_CLS + '-item', |
168 | 164 | cls = options.disabled ? (itemCls + ' ' + itemCls + '-disabled') : itemCls, |
169 | 165 | el = this._insertElementAt('a', cls, container, index), |
170 | | - callback = this._createEventHandler(el, options.callback, options.context), |
| 166 | + callback = this._createEventHandler(el, options.callback, options.context, options.hideOnSelect), |
171 | 167 | html = ''; |
172 | 168 |
|
173 | 169 | if (options.icon) { |
@@ -232,18 +228,24 @@ L.Map.ContextMenu = L.Handler.extend({ |
232 | 228 | }; |
233 | 229 | }, |
234 | 230 |
|
235 | | - _createEventHandler: function (el, func, context) { |
| 231 | + _createEventHandler: function (el, func, context, hideOnSelect) { |
236 | 232 | var me = this, |
237 | 233 | map = this._map, |
238 | | - disabledCls = L.Map.ContextMenu.BASE_CLS + '-item-disabled'; |
| 234 | + disabledCls = L.Map.ContextMenu.BASE_CLS + '-item-disabled', |
| 235 | + hideOnSelect = (hideOnSelect !== undefined) ? hideOnSelect : true; |
239 | 236 |
|
240 | 237 | return function (e) { |
241 | 238 | if (L.DomUtil.hasClass(el, disabledCls)) { |
242 | 239 | return; |
243 | 240 | } |
| 241 | + |
| 242 | + if (hideOnSelect) { |
| 243 | + me._hide(); |
| 244 | + } |
244 | 245 |
|
245 | | - me._hide(); |
246 | | - func.call(context || map, me._showLocation); |
| 246 | + if (func) { |
| 247 | + func.call(context || map, me._showLocation); |
| 248 | + } |
247 | 249 |
|
248 | 250 | me._map.fire('contextmenu:select', { |
249 | 251 | contextmenu: me, |
|
0 commit comments