]> git.openstreetmap.org Git - rails.git/commitdiff
Create Leaflet sidebar pane control with header writer fn
authorAnton Khorev <tony29@yandex.ru>
Sat, 27 Aug 2022 17:33:44 +0000 (20:33 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 27 Aug 2022 17:33:44 +0000 (20:33 +0300)
app/assets/javascripts/index.js
app/assets/javascripts/leaflet.key.js
app/assets/javascripts/leaflet.layers.js
app/assets/javascripts/leaflet.share.js
app/assets/javascripts/leaflet.sidebar-pane.js [new file with mode: 0644]

index 40f546009b0d4e7554d0ee6f0f669a55f4e644f4..5ba36a455db9e3a06ef467a872657844e8f972d9 100644 (file)
@@ -1,5 +1,6 @@
 //= require_self
 //= require leaflet.sidebar
 //= require_self
 //= require leaflet.sidebar
+//= require leaflet.sidebar-pane
 //= require leaflet.locatecontrol/src/L.Control.Locate
 //= require leaflet.layers
 //= require leaflet.key
 //= require leaflet.locatecontrol/src/L.Control.Locate
 //= require leaflet.layers
 //= require leaflet.key
index 367c39c1462067ab74ed7fdad466b0814a5b75fa..46c4661d2b0bd31e027a30a70348e2e798f195e4 100644 (file)
@@ -1,5 +1,5 @@
 L.OSM.key = function (options) {
 L.OSM.key = function (options) {
-  var control = L.control(options);
+  var control = L.OSM.sidebarPane(options);
 
   control.onAdd = function (map) {
     var $container = $("<div>")
 
   control.onAdd = function (map) {
     var $container = $("<div>")
@@ -12,19 +12,7 @@ L.OSM.key = function (options) {
       .on("click", toggle)
       .appendTo($container);
 
       .on("click", toggle)
       .appendTo($container);
 
-    var $ui = $("<div>")
-      .attr("class", "key-ui");
-
-    $("<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("javascripts.key.title")));
+    var $ui = this.makeUI("key-ui", "javascripts.key.title", toggle);
 
     var $section = $("<div>")
       .attr("class", "section")
 
     var $section = $("<div>")
       .attr("class", "section")
index 038205ca4975d16e593b89d4b0278fef61062367..518cdc7f173a96bb1d36bb2e8c993d925ffaf683 100644 (file)
@@ -1,5 +1,5 @@
 L.OSM.layers = function (options) {
 L.OSM.layers = function (options) {
-  var control = L.control(options);
+  var control = L.OSM.sidebarPane(options);
 
   control.onAdd = function (map) {
     var layers = options.layers;
 
   control.onAdd = function (map) {
     var layers = options.layers;
@@ -15,19 +15,7 @@ L.OSM.layers = function (options) {
       .on("click", toggle)
       .appendTo($container);
 
       .on("click", toggle)
       .appendTo($container);
 
-    var $ui = $("<div>")
-      .attr("class", "layers-ui");
-
-    $("<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("javascripts.map.layers.header")));
+    var $ui = this.makeUI("layers-ui", "javascripts.map.layers.header", toggle);
 
     var baseSection = $("<div>")
       .attr("class", "section base-layers")
 
     var baseSection = $("<div>")
       .attr("class", "section base-layers")
index 1817e71ccd03d2b759618cf3dd576e3f08cf69d3..875008cfc7450bab96deb64b0c3d8c20f52de8b2 100644 (file)
@@ -1,5 +1,5 @@
 L.OSM.share = function (options) {
 L.OSM.share = function (options) {
-  var control = L.control(options),
+  var control = L.OSM.sidebarPane(options),
       marker = L.marker([0, 0], { draggable: true }),
       locationFilter = new L.LocationFilter({
         enableButton: false,
       marker = L.marker([0, 0], { draggable: true }),
       locationFilter = new L.LocationFilter({
         enableButton: false,
@@ -18,19 +18,7 @@ L.OSM.share = function (options) {
       .on("click", toggle)
       .appendTo($container);
 
       .on("click", toggle)
       .appendTo($container);
 
-    var $ui = $("<div>")
-      .attr("class", "share-ui");
-
-    $("<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("javascripts.share.title")));
+    var $ui = this.makeUI("share-ui", "javascripts.share.title", toggle);
 
     // Link / Embed
 
 
     // Link / Embed
 
diff --git a/app/assets/javascripts/leaflet.sidebar-pane.js b/app/assets/javascripts/leaflet.sidebar-pane.js
new file mode 100644 (file)
index 0000000..f087cbb
--- /dev/null
@@ -0,0 +1,23 @@
+L.OSM.sidebarPane = function (options) {
+  var control = L.control(options);
+
+  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;
+  };
+
+  return control;
+};