]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.sidebar-pane.js
Make close buttons stick to the top of scrolled areas
[rails.git] / app / assets / javascripts / leaflet.sidebar-pane.js
index fff0b40631931b93f023f162a04e4b2548c2c17e..7408585f26adbd19dfd1f57d3d87fd49c16fab6e 100644 (file)
@@ -1,37 +1,47 @@
-L.OSM.sidebarPane = function (options) {
-  var control = L.control(options);
+L.OSM.sidebarPane = function (options, uiClass, buttonTitle, paneTitle) {
+  const control = L.control(options);
 
-  control.makeButton = function (buttonClass, buttonTitle, toggle) {
-    var button =  $("<a>")
+  control.onAdd = function (map) {
+    const $container = $("<div>")
+      .attr("class", "control-" + uiClass);
+
+    const button = $("<a>")
       .attr("class", "control-button")
       .attr("href", "#")
-      .html("<span class=\"icon " + buttonClass + "\"></span>")
+      .html("<span class=\"icon " + uiClass + "\"></span>")
       .on("click", toggle);
-    
+
     if (buttonTitle) {
-      button.attr("title", I18n.t(buttonTitle))
+      button.attr("title", I18n.t(buttonTitle));
     }
 
-    return button;
-  };
+    button.appendTo($container);
+
+    const $ui = $("<div>")
+      .attr("class", `${uiClass}-ui position-relative z-n1`);
+
+    $("<h2 class='p-3 pb-0 pe-5 text-break'>")
+      .text(I18n.t(paneTitle))
+      .appendTo($ui);
 
-  control.makeUI = function (uiClass, paneTitle, toggle) {
-    var $ui = $("<div>")
-      .attr("class", uiClass);
-
-    $("<div>")
-      .attr("class", "sidebar_heading")
-      .appendTo($ui)
-      .append(
-        $("<button type='button' class='btn-close float-end mt-1'>")
-          .attr("aria-label", I18n.t("javascripts.close"))
-          .bind("click", toggle))
-      .append(
-        $("<h4>")
-          .text(I18n.t(paneTitle)));
-
-    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;
 };