]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.sidebar-pane.js
Remove top margins from close buttons
[rails.git] / app / assets / javascripts / leaflet.sidebar-pane.js
index f087cbb4a5845b30123f9fb8706cfa522a63d9f1..ff6ee8d8b14ab896ab4b500c732b2ce00748d031 100644 (file)
@@ -1,23 +1,53 @@
-L.OSM.sidebarPane = function (options) {
+L.OSM.sidebarPane = function (options, uiClass, buttonTitle, paneTitle) {
   var control = L.control(options);
 
-  control.makeUI = function (uiClass, paneTitle, toggle) {
+  control.onAdd = function (map) {
+    var $container = $("<div>")
+      .attr("class", "control-" + uiClass);
+
+    var button = $("<a>")
+      .attr("class", "control-button")
+      .attr("href", "#")
+      .html("<span class=\"icon " + uiClass + "\"></span>")
+      .on("click", toggle);
+
+    if (buttonTitle) {
+      button.attr("title", I18n.t(buttonTitle));
+    }
+
+    button.appendTo($container);
+
     var $ui = $("<div>")
-      .attr("class", uiClass);
+      .attr("class", uiClass + "-ui");
 
-    $("<div>")
-      .attr("class", "sidebar_heading")
+    $("<div class='sidebar_heading d-flex'>")
       .appendTo($ui)
-      .append(
-        $("<button type='button' class='btn-close float-end mt-1'>")
+      .append($("<div class='flex-grow-1 text-break'>")
+        .append($("<h4>")
+          .text(I18n.t(paneTitle))))
+      .append($("<div>")
+        .append($("<button type='button' class='btn-close'>")
           .attr("aria-label", I18n.t("javascripts.close"))
-          .bind("click", toggle))
-      .append(
-        $("<h4>")
-          .text(I18n.t(paneTitle)));
+          .bind("click", toggle)));
 
-    return $ui;
+    options.sidebar.addPane($ui);
+
+    this.onAddPane(map, button, $ui, toggle);
+
+    function toggle(e) {
+      e.stopPropagation();
+      e.preventDefault();
+      if (!button.hasClass("disabled")) {
+        options.sidebar.togglePane($ui, button);
+      }
+      $(".leaflet-control .control-button").tooltip("hide");
+    }
+
+    return $container[0];
   };
 
+  // control.onAddPane = function (map, button, $ui, toggle) {
+  // }
+
   return control;
 };