]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.sidebar-pane.js
Merge remote-tracking branch 'upstream/pull/4717'
[rails.git] / app / assets / javascripts / leaflet.sidebar-pane.js
1 L.OSM.sidebarPane = function (options, uiClass, buttonTitle, paneTitle) {
2   var control = L.control(options);
3
4   control.onAdd = function (map) {
5     var $container = $("<div>")
6       .attr("class", "control-" + uiClass);
7
8     var 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     var $ui = $("<div>")
21       .attr("class", uiClass + "-ui");
22
23     $("<div class='d-flex p-3 pb-0'>")
24       .appendTo($ui)
25       .append($("<h2 class='flex-grow-1 text-break'>")
26         .text(I18n.t(paneTitle)))
27       .append($("<div>")
28         .append($("<button type='button' class='btn-close'>")
29           .attr("aria-label", I18n.t("javascripts.close"))
30           .bind("click", toggle)));
31
32     options.sidebar.addPane($ui);
33
34     this.onAddPane(map, button, $ui, toggle);
35
36     function toggle(e) {
37       e.stopPropagation();
38       e.preventDefault();
39       if (!button.hasClass("disabled")) {
40         options.sidebar.togglePane($ui, button);
41       }
42       $(".leaflet-control .control-button").tooltip("hide");
43     }
44
45     return $container[0];
46   };
47
48   // control.onAddPane = function (map, button, $ui, toggle) {
49   // }
50
51   return control;
52 };