]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.key.js
Replace use of I18n in javascript with OSM.i18n
[rails.git] / app / assets / javascripts / leaflet.key.js
index 6a3400d348831ab48ff53b5f1a2f9e991307f52b..a5d7acb430507b98e4ef7c96608bc69f0f835abf 100644 (file)
@@ -1,9 +1,9 @@
 L.OSM.key = function (options) {
-  var control = L.OSM.sidebarPane(options, "key", null, "javascripts.key.title");
+  const control = L.OSM.sidebarPane(options, "key", null, "javascripts.key.title");
 
   control.onAddPane = function (map, button, $ui) {
-    var $section = $("<div>")
-      .attr("class", "section")
+    const $section = $("<div>")
+      .attr("class", "p-3")
       .appendTo($ui);
 
     $ui
@@ -16,7 +16,10 @@ L.OSM.key = function (options) {
 
     function shown() {
       map.on("zoomend baselayerchange", update);
-      $section.load("/key", update);
+      fetch("/key")
+        .then(r => r.text())
+        .then(html => { $section.html(html); })
+        .then(update);
     }
 
     function hidden() {
@@ -24,26 +27,26 @@ L.OSM.key = function (options) {
     }
 
     function updateButton() {
-      var disabled = ["mapnik", "cyclemap"].indexOf(map.getMapBaseLayerId()) === -1;
+      const disabled = OSM.LAYERS_WITH_MAP_KEY.indexOf(map.getMapBaseLayerId()) === -1;
       button
         .toggleClass("disabled", disabled)
         .attr("data-bs-original-title",
-              I18n.t(disabled ?
+              OSM.i18n.t(disabled ?
                 "javascripts.key.tooltip_disabled" :
                 "javascripts.key.tooltip"));
     }
 
     function update() {
-      var layer = map.getMapBaseLayerId(),
-          zoom = map.getZoom();
+      const layerId = map.getMapBaseLayerId(),
+            zoom = map.getZoom();
 
       $(".mapkey-table-entry").each(function () {
-        var data = $(this).data();
-        if (layer === data.layer && zoom >= data.zoomMin && zoom <= data.zoomMax) {
-          $(this).show();
-        } else {
-          $(this).hide();
-        }
+        const data = $(this).data();
+        $(this).toggle(
+          layerId === data.layer &&
+          (!data.zoomMin || zoom >= data.zoomMin) &&
+          (!data.zoomMax || zoom <= data.zoomMax)
+        );
       });
     }
   };