]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.share.js
Prevent click propagation on ui panes
[rails.git] / app / assets / javascripts / leaflet.share.js
1 //= require templates/map/share
2
3 L.Control.Share = L.Control.extend({
4     options: {
5         position: 'topright',
6         title: 'Share',
7         url: function(map) {
8             return '';
9         }
10     },
11
12     onAdd: function (map) {
13         var className = 'leaflet-control-locate',
14             classNames = className + ' leaflet-control-zoom leaflet-bar leaflet-control',
15             container = L.DomUtil.create('div', classNames);
16
17         var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', container);
18         link.href = '#';
19         link.title = this.options.title;
20
21         this._uiPane = L.DomUtil.create('div', 'leaflet-map-ui', map._container);
22
23         L.DomEvent
24             .on(this._uiPane, 'click', L.DomEvent.stopPropagation)
25             .on(this._uiPane, 'click', L.DomEvent.preventDefault)
26             .on(this._uiPane, 'dblclick', L.DomEvent.preventDefault);
27
28         var h2 = L.DomUtil.create('h2', '', this._uiPane);
29         h2.innerHTML = I18n.t('javascripts.share.title');
30
31         this._linkInput = L.DomUtil.create('input', '', this._uiPane);
32
33         L.DomEvent
34             .on(link, 'click', L.DomEvent.stopPropagation)
35             .on(link, 'click', L.DomEvent.preventDefault)
36             .on(link, 'click', this._toggle, this)
37             .on(link, 'dblclick', L.DomEvent.stopPropagation);
38
39         map.on('moveend layeradd layerremove', this._update, this);
40
41         return container;
42     },
43
44     _update: function (e) {
45         var center = map.getCenter().wrap();
46         var layers = getMapLayers();
47         this._linkInput.value = this.options.getUrl(map);
48     },
49
50     _toggle: function() {
51         var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
52
53         if ($(this._uiPane).is(':visible')) {
54             $(this._uiPane).hide();
55             controlContainer.css({paddingRight: '0'});
56         } else {
57             $(this._uiPane).show();
58             controlContainer.css({paddingRight: '200px'});
59         }
60     }
61 });
62
63 L.control.share = function(options) {
64     return new L.Control.Share(options);
65 };