]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.sidebar-pane.js
Inverted onAdd() method of sidebar panes
[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>")
24       .attr("class", "sidebar_heading")
25       .appendTo($ui)
26       .append(
27         $("<button type='button' class='btn-close float-end mt-1'>")
28           .attr("aria-label", I18n.t("javascripts.close"))
29           .bind("click", toggle))
30       .append(
31         $("<h4>")
32           .text(I18n.t(paneTitle)));
33
34     options.sidebar.addPane($ui);
35
36     this.onAddPane(map, button, $ui, toggle);
37
38     function toggle(e) {
39       e.stopPropagation();
40       e.preventDefault();
41       if (!button.hasClass("disabled")) {
42         options.sidebar.togglePane($ui, button);
43       }
44       $(".leaflet-control .control-button").tooltip("hide");
45     }
46
47     return $container[0];
48   }
49
50   // control.onAddPane = function (map, button, $ui, toggle) {
51   // }
52
53   return control;
54 };