]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.sidebar-pane.js
Merge remote-tracking branch 'upstream/pull/5778'
[rails.git] / app / assets / javascripts / leaflet.sidebar-pane.js
1 L.OSM.sidebarPane = function (options, uiClass, buttonTitle, paneTitle) {
2   const control = L.control(options);
3
4   control.onAdd = function (map) {
5     const $container = $("<div>")
6       .attr("class", "control-" + uiClass);
7
8     const button = $("<a>")
9       .attr("class", "control-button")
10       .attr("href", "#")
11       .html("<span class=\"icon " + uiClass + "\"></span>")
12       .on("click", toggle);
13
14     if (buttonTitle) {
15       button.attr("title", I18n.t(buttonTitle));
16     }
17
18     button.appendTo($container);
19
20     const $ui = $("<div>")
21       .attr("class", `${uiClass}-ui position-relative z-n1`);
22
23     $("<h2 class='p-3 pb-0 pe-5 text-break'>")
24       .text(I18n.t(paneTitle))
25       .appendTo($ui);
26
27     options.sidebar.addPane($ui);
28
29     this.onAddPane(map, button, $ui, toggle);
30
31     function toggle(e) {
32       e.stopPropagation();
33       e.preventDefault();
34       if (!button.hasClass("disabled")) {
35         options.sidebar.togglePane($ui, button);
36       }
37       $(".leaflet-control .control-button").tooltip("hide");
38     }
39
40     return $container[0];
41   };
42
43   // control.onAddPane = function (map, button, $ui, toggle) {
44   // }
45
46   return control;
47 };