]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.sidebar.js
Merge remote-tracking branch 'upstream/pull/4705'
[rails.git] / app / assets / javascripts / leaflet.sidebar.js
1 L.OSM.sidebar = function (selector) {
2   var control = {},
3       sidebar = $(selector),
4       current = $(),
5       currentButton = $(),
6       map;
7
8   control.addTo = function (_) {
9     map = _;
10     return control;
11   };
12
13   control.addPane = function (pane) {
14     pane
15       .hide()
16       .appendTo(sidebar);
17   };
18
19   control.togglePane = function (pane, button) {
20     var paneWidth = 250;
21
22     current
23       .hide()
24       .trigger("hide");
25
26     currentButton
27       .removeClass("active");
28
29     if (current === pane) {
30       if ($("html").attr("dir") === "rtl") {
31         map.panBy([-paneWidth, 0], { animate: false });
32       }
33       $(sidebar).hide();
34       current = currentButton = $();
35     } else {
36       $(sidebar).show();
37       current = pane;
38       currentButton = button || $();
39       if ($("html").attr("dir") === "rtl") {
40         map.panBy([paneWidth, 0], { animate: false });
41       }
42     }
43
44     map.invalidateSize({ pan: false, animate: false });
45
46     current
47       .show()
48       .trigger("show");
49
50     currentButton
51       .addClass("active");
52   };
53
54   return control;
55 };