]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.sidebar-pane.js
Avoid highlighting multiple changesets in history sidebar
[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       .on("click", toggle);
12
13     $(L.SVG.create("svg"))
14       .append($(L.SVG.create("use")).attr("href", "#icon-" + uiClass))
15       .attr("class", "h-100 w-100")
16       .appendTo(button);
17
18     if (buttonTitle) {
19       button.attr("title", OSM.i18n.t(buttonTitle));
20     }
21
22     button.appendTo($container);
23
24     const $ui = $("<div>")
25       .attr("class", `${uiClass}-ui position-relative z-n1`);
26
27     $("<h2 class='p-3 pb-0 pe-5 text-break'>")
28       .text(OSM.i18n.t(paneTitle))
29       .appendTo($ui);
30
31     options.sidebar.addPane($ui);
32
33     this.onAddPane(map, button, $ui, toggle);
34
35     function toggle(e) {
36       e.stopPropagation();
37       e.preventDefault();
38       if (!button.hasClass("disabled")) {
39         options.sidebar.togglePane($ui, button);
40       }
41       $(".leaflet-control .control-button").tooltip("hide");
42     }
43
44     return $container[0];
45   };
46
47   // control.onAddPane = function (map, button, $ui, toggle) {
48   // }
49
50   return control;
51 };